Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ts-version: [~5.9]
ts-version: [~5.9, ~6.0]
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
Expand Down
2 changes: 1 addition & 1 deletion lib/api-event-iterator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export async function * asyncEventIteratorFromApi(api) {
// TODO: support multiple runs (watch mode)
const {value: plan} = await api.events('run').next();
const {value: {data: plan}} = await api.events('run').next();

for await (const stateChange of plan.status.events('stateChange')) {
yield stateChange;
Expand Down
8 changes: 4 additions & 4 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export default class Api extends Emittery {

// The files must be in the same order across all runs, so sort them.
const defaultComparator = (a, b) => a.localeCompare(b, [], {numeric: true});
selectedFiles = selectedFiles.sort(this.options.sortTestFiles ?? defaultComparator);
selectedFiles = selectedFiles.toSorted(this.options.sortTestFiles ?? defaultComparator);
selectedFiles = chunkd(selectedFiles, currentIndex, totalRuns);

const currentFileCount = selectedFiles.length;
Expand All @@ -189,7 +189,7 @@ export default class Api extends Emittery {
} else {
// If a custom sorter was configured, use it.
if (this.options.sortTestFiles) {
selectedFiles = selectedFiles.sort(this.options.sortTestFiles);
selectedFiles = selectedFiles.toSorted(this.options.sortTestFiles);
}

runStatus = new RunStatus(selectedFiles.length, null, selectionInsights);
Expand Down Expand Up @@ -220,7 +220,7 @@ export default class Api extends Emittery {
return runStatus;
}

runStatus.on('stateChange', record => {
runStatus.on('stateChange', ({data: record}) => {
if (record.testFile && !timedOutWorkerFiles.has(record.testFile) && record.type !== 'worker-stderr' && record.type !== 'worker-stdout') {
// Debounce the timer whenever there is test-related activity from workers that haven't already timed out.
timeoutTrigger.debounce();
Expand Down Expand Up @@ -293,7 +293,7 @@ export default class Api extends Emittery {
deregisteredSharedWorkers.push(observeWorkerProcess(worker, runStatus));

pendingWorkers.add(worker);
worker.promise.then(() => { // eslint-disable-line promise/prefer-await-to-then
worker.promise.then(() => {
pendingWorkers.delete(worker);
});
timeoutTrigger.debounce();
Expand Down
7 changes: 4 additions & 3 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function formatWithLabel(label, value) {
}

const noop = () => {};

const notImplemented = () => {
throw new Error('not implemented');
};
Expand Down Expand Up @@ -423,7 +424,7 @@ export class Assertions {
retval = fn();
if (isPromise(retval)) {
// Here isPromise() checks if something is "promise like". Cast to an actual promise.
Promise.resolve(retval).catch(noop); // eslint-disable-line promise/prefer-await-to-then
Promise.resolve(retval).catch(noop);
throw fail(new AssertionError(message, {
assertion: 't.throws()',
formattedDetails: [formatWithLabel('Function returned a promise. Use `t.throwsAsync()` instead:', retval)],
Expand Down Expand Up @@ -490,7 +491,7 @@ export class Assertions {
// Record the stack before it gets lost in the promise chain.
const assertionStack = getAssertionStack();
// Handle "promise like" objects by casting to a real Promise.
const intermediate = Promise.resolve(promise).then(value => { // eslint-disable-line promise/prefer-catch, promise/prefer-await-to-then
const intermediate = Promise.resolve(promise).then(value => {
throw failPending(new AssertionError(message, {
assertion: 't.throwsAsync()',
assertionStack,
Expand Down Expand Up @@ -592,7 +593,7 @@ export class Assertions {
// Create an error object to record the stack before it gets lost in the promise chain.
const assertionStack = getAssertionStack();
// Handle "promise like" objects by casting to a real Promise.
const intermediate = Promise.resolve(promise).then(noop, error => { // eslint-disable-line promise/prefer-catch, promise/prefer-await-to-then
const intermediate = Promise.resolve(promise).then(noop, error => {
throw failPending(new AssertionError(message, {
assertion: 't.notThrowsAsync()',
assertionStack,
Expand Down
10 changes: 5 additions & 5 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,8 @@ export default async function loadCli() { // eslint-disable-line complexity
const {controlFlow} = await import('./ipc-flow-control.cjs');
const bufferedSend = controlFlow(process);

api.on('run', plan => {
plan.status.on('stateChange', evt => {
api.on('run', ({data: plan}) => {
plan.status.on('stateChange', ({data: evt}) => {
bufferedSend(evt);
});
});
Expand All @@ -488,10 +488,10 @@ export default async function loadCli() { // eslint-disable-line complexity
});
}

api.on('run', plan => {
api.on('run', ({data: plan}) => {
reporter.startRun(plan);

plan.status.on('stateChange', evt => {
plan.status.on('stateChange', ({data: evt}) => {
if (evt.type === 'end' || evt.type === 'interrupt') {
// Write out code coverage data when the run ends, lest a process
// interrupt causes it to be lost.
Expand Down Expand Up @@ -537,7 +537,7 @@ export default async function loadCli() { // eslint-disable-line complexity
});
} else {
let debugWithoutSpecificFile = false;
api.on('run', plan => {
api.on('run', ({data: plan}) => {
if (debug !== null && plan.files.length !== 1) {
debugWithoutSpecificFile = true;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ export default function loadFork(file, options, execArgv = process.execArgv) {
},

onConnectSharedWorker(listener) {
return emitter.on('connectSharedWorker', listener);
return emitter.on('connectSharedWorker', ({data}) => listener(data));
},

onStateChange(listener) {
return emitter.on('stateChange', listener);
return emitter.on('stateChange', ({data}) => listener(data));
},
};
}
2 changes: 1 addition & 1 deletion lib/plugin-support/shared-worker-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ try {

// Run possibly asynchronous release functions serially, in reverse
// order. Any error will crash the worker.
for await (const fn of [...teardownFns].reverse()) {
for await (const fn of [...teardownFns].toReversed()) {
await fn();
}

Expand Down
6 changes: 3 additions & 3 deletions lib/plugin-support/shared-workers.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export async function observeWorkerProcess(fork, runStatus) {
}
};

fork.promise.finally(() => { // eslint-disable-line promise/prefer-await-to-then
fork.promise.finally(() => {
removeAllInstances();
});

Expand All @@ -99,7 +99,7 @@ export async function observeWorkerProcess(fork, runStatus) {
}
};

launched.statePromises.error.then(error => { // eslint-disable-line promise/prefer-await-to-then
launched.statePromises.error.then(error => {
launched.worker.off('message', handleWorkerMessage);
removeAllInstances();
runStatus.emitStateChange({type: 'shared-worker-error', err: serializeError(error)});
Expand All @@ -118,7 +118,7 @@ export async function observeWorkerProcess(fork, runStatus) {
port,
}, [port]);

fork.promise.finally(() => { // eslint-disable-line promise/prefer-await-to-then
fork.promise.finally(() => {
launched.worker.postMessage({
type: 'deregister-test-worker',
id: fork.threadId,
Expand Down
2 changes: 1 addition & 1 deletion lib/reporters/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default class Reporter {
this.prefixTitle = (testFile, title) => prefixTitle(this.extensions, plan.filePathPrefix, testFile, title);
}

this.removePreviousListener = plan.status.on('stateChange', evt => {
this.removePreviousListener = plan.status.on('stateChange', ({data: evt}) => {
this.consumeStateChange(evt);
});

Expand Down
6 changes: 3 additions & 3 deletions lib/reporters/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ function dumpError({

export default class TapReporter {
constructor(options) {
this.i = 0;

this.extensions = options.extensions;
this.stdStream = options.stdStream;
this.reportStream = options.reportStream;
Expand All @@ -71,7 +69,7 @@ export default class TapReporter {
this.prefixTitle = (testFile, title) => prefixTitle(this.extensions, plan.filePathPrefix, testFile, title);
}

plan.status.on('stateChange', evt => this.consumeStateChange(evt));
plan.status.on('stateChange', ({data: evt}) => this.consumeStateChange(evt));

this.reportStream.write(supertap.start() + os.EOL);
}
Expand Down Expand Up @@ -265,4 +263,6 @@ export default class TapReporter {
}
}
}

i = 0;
}
8 changes: 4 additions & 4 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export default class Runner extends Emittery {
let waitForSerial = Promise.resolve();
await runnables.reduce((previous, runnable) => { // eslint-disable-line unicorn/no-array-reduce
if (runnable.metadata.serial || this.serial) {
waitForSerial = previous.then(() => // eslint-disable-line promise/prefer-await-to-then
waitForSerial = previous.then(() =>
// Serial runnables run as long as there was no previous failure, unless
// the runnable should always be run.
(allPassed || runnable.metadata.always) && runAndStoreResult(runnable));
Expand All @@ -263,7 +263,7 @@ export default class Runner extends Emittery {

return Promise.all([
previous,
waitForSerial.then(() => // eslint-disable-line promise/prefer-await-to-then
waitForSerial.then(() =>
// Concurrent runnables are kicked off after the previous serial
// runnables have completed, as long as there was no previous failure
// (or if the runnable should always be run). One concurrent runnable's
Expand Down Expand Up @@ -476,7 +476,7 @@ export default class Runner extends Emittery {

// Note that the hooks and tests always begin running asynchronously.
const beforePromise = this.runHooks(this.tasks.before, contextRef);
const serialPromise = beforePromise.then(beforeHooksOk => { // eslint-disable-line promise/prefer-await-to-then
const serialPromise = beforePromise.then(beforeHooksOk => {
// Don't run tests if a `before` hook failed.
if (!beforeHooksOk) {
return false;
Expand All @@ -498,7 +498,7 @@ export default class Runner extends Emittery {
return this.runTest(task, contextRef.copy());
}, true);
});
const concurrentPromise = Promise.all([beforePromise, serialPromise]).then(async ([beforeHooksOk, serialOk]) => { // eslint-disable-line promise/prefer-await-to-then
const concurrentPromise = Promise.all([beforePromise, serialPromise]).then(async ([beforeHooksOk, serialOk]) => {
// Don't run tests if a `before` hook failed, or if `failFast` is enabled
// and a previous serial test failed.
if (!beforeHooksOk || (!serialOk && this.failFast)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const scheduler = {
return selectedFiles;
}

return [...selectedFiles].sort((f, s) => {
return selectedFiles.toSorted((f, s) => {
if (failedTestFiles.includes(f) && failedTestFiles.includes(s)) {
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/snapshot-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class BufferBuilder {
}

function sortBlocks(blocksByTitle, blockIndices) {
return [...blocksByTitle].sort(([aTitle], [bTitle]) => {
return [...blocksByTitle].toSorted(([aTitle], [bTitle]) => {
const a = blockIndices.get(aTitle);
const b = blockIndices.get(bTitle);

Expand Down
6 changes: 3 additions & 3 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export default class Test {
}

async runTeardowns() {
const teardowns = [...this.teardowns].reverse();
const teardowns = this.teardowns.toReversed();

for (const teardown of teardowns) {
try {
Expand Down Expand Up @@ -590,7 +590,7 @@ export default class Test {
};

promise
.catch(error => { // eslint-disable-line promise/prefer-await-to-then
.catch(error => {
if (this.testFailure !== null && error === this.testFailure) {
return;
}
Expand All @@ -607,7 +607,7 @@ export default class Test {
}));
}
})
.then(() => resolve(this.finish())); // eslint-disable-line promise/prefer-await-to-then
.then(() => resolve(this.finish()));
});
}

Expand Down
19 changes: 5 additions & 14 deletions lib/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ async function * plan({
};

// Begin a file trace in the background.
fileTracer.update(findTests(cwdAndGlobs).then(testFiles => testFiles.map(path => ({ // eslint-disable-line promise/prefer-await-to-then
fileTracer.update(findTests(cwdAndGlobs).then(testFiles => testFiles.map(path => ({
path: nodePath.relative(projectDir, path),
isTest: true,
exists: true,
Expand All @@ -231,8 +231,8 @@ async function * plan({
};

// Observe all test runs.
api.on('run', ({status}) => {
status.on('stateChange', evt => {
api.on('run', ({data: {status}}) => {
status.on('stateChange', ({data: evt}) => {
switch (evt.type) {
case 'accessed-snapshots': {
fileTracer.addDependency(nodePath.relative(projectDir, evt.testFile), nodePath.relative(projectDir, evt.filename));
Expand Down Expand Up @@ -425,7 +425,7 @@ async function * plan({
// If the file tracer is still analyzing dependencies, wait for that to
// complete.
if (fileTracer.busy !== null) {
fileTracer.busy.then(() => debounce.refresh()); // eslint-disable-line promise/prefer-await-to-then
fileTracer.busy.then(() => debounce.refresh());
takeCoverageForSelfTests?.();
return;
}
Expand Down Expand Up @@ -707,15 +707,10 @@ class FileTracer {
#base;
#cache = Object.create(null);
#pendingTrace = null;
#updateRunning;
#signalUpdateRunning;
#tree = new Tree();

constructor({base}) {
this.#base = base;
this.#updateRunning = new Promise(resolve => {
this.#signalUpdateRunning = resolve;
});
}

get busy() {
Expand Down Expand Up @@ -761,12 +756,9 @@ class FileTracer {
}

update(changes) {
const current = this.#update(changes).finally(() => { // eslint-disable-line promise/prefer-await-to-then
const current = this.#update(changes).finally(() => {
if (this.#pendingTrace === current) {
this.#pendingTrace = null;
this.#updateRunning = new Promise(resolve => {
this.#signalUpdateRunning = resolve;
});
}
});

Expand All @@ -775,7 +767,6 @@ class FileTracer {

async #update(changes) {
await this.#pendingTrace; // Guard against race conditions.
this.#signalUpdateRunning();

let reuseCache = true;
const knownTestFiles = new Set();
Expand Down
8 changes: 4 additions & 4 deletions lib/worker/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ const run = async options => {

refs.runnerChain = runner.chain;

channel.peerFailed.then(() => { // eslint-disable-line promise/prefer-await-to-then
channel.peerFailed.then(() => {
runner.interrupt();
});

runner.on('accessed-snapshots', filename => channel.send({type: 'accessed-snapshots', filename}));
runner.on('stateChange', state => channel.send(state));
runner.on('accessed-snapshots', ({data: filename}) => channel.send({type: 'accessed-snapshots', filename}));
runner.on('stateChange', ({data: state}) => channel.send(state));

runner.on('error', error => {
runner.on('error', ({data: error}) => {
channel.send({type: 'internal-error', err: serializeError(error)});
forceExit();
});
Expand Down
Loading
Loading