Skip to content

Commit

Permalink
Update dependencies & other general maintenance
Browse files Browse the repository at this point in the history
* Upgrade XO
* Update TypeScript-related dependencies — Don't upgrade @sindresorhus/tsconfig to v6 since it requires TS 5.5 and we test with 5.2.
* Update dev dependencies
* Update dependencies
* Rebuild lockfile
* Upgrade CodeCov action
* Update reporter log instructions and remove deprecation warnings
* Make Node.js 22.6 the recommended development version
* Remove Node.js 21 from the engines list: It's no longer maintained by Node.js itself, see also <https://github.com/avajs/ava/blob/main/docs/support-statement.md>.
  • Loading branch information
novemberborn authored Aug 20, 2024
1 parent f8bf00c commit b15df53
Show file tree
Hide file tree
Showing 54 changed files with 2,464 additions and 3,602 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [^18.18, ^20.8, ^21, ^22]
node-version: [^18.18, ^20.8, ^22]
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
Expand All @@ -31,17 +31,18 @@ jobs:
- run: npm install --no-audit
- run: ./scripts/ci.sh
shell: bash
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
files: coverage/lcov.info
name: ${{ matrix.os }}/${{ matrix.node-version }}
token: ${{ secrets.CODECOV_TOKEN }}

typescript:
name: TypeScript compatibility
runs-on: ubuntu-latest
strategy:
matrix:
ts-version: [~5.2, ~5.3]
ts-version: [~5.2, ~5.3, ~5.4, ~5.5]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand Down
2 changes: 2 additions & 0 deletions .xo-config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = {
files: '**/*.d.*(c|m)ts',
rules: {
'import/extensions': 'off',
'n/file-extension-in-import': 'off',
},
},
{
Expand Down Expand Up @@ -91,6 +92,7 @@ module.exports = {
rules: {
'import/no-anonymous-default-export': 'off',
'n/prefer-global/process': 'off',
'promise/prefer-await-to-then': 'off',
'unicorn/error-message': 'off',
},
},
Expand Down
2 changes: 1 addition & 1 deletion docs/support-statement.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ AVA supports the latest release of any major version that [is supported by Node.

When we drop support for an LTS-covered major version we will bump AVA's major version number.

We will drop support for odd-numbered Node.js versions (e.g. `11` or `13`) *without* bumping AVA's major version number.
We will drop support for odd-numbered Node.js versions (e.g. `21` or `23`) *without* bumping AVA's major version number.

We try to avoid *accidentally* dropping support for non-latest Node.js releases. If such breakage does occur we'll accept pull requests to restore functionality. We might decide to deprecate the offending AVA release and bump AVA's major version number instead.

Expand Down
4 changes: 3 additions & 1 deletion examples/endpoint-testing/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

module.exports = (request, response) => {
const app = (request, response) => {
if (request.url === '/user') {
response.setHeader('Content-Type', 'application/json');
response.end(JSON.stringify({email: 'ava@rocks.com'}));
Expand All @@ -9,3 +9,5 @@ module.exports = (request, response) => {
response.end();
}
};

module.exports = app;
21 changes: 15 additions & 6 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,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);
Promise.resolve(retval).catch(noop); // eslint-disable-line promise/prefer-await-to-then
throw fail(new AssertionError(message, {
assertion: 't.throws()',
formattedDetails: [formatWithLabel('Function returned a promise. Use `t.throwsAsync()` instead:', retval)],
Expand Down Expand Up @@ -462,7 +462,10 @@ export class Assertions {
try {
assertMessage(message, 't.throwsAsync()');
} catch (error) {
Promise.resolve(thrower).catch(noop);
try {
await thrower;
} catch {}

throw error;
}

Expand All @@ -476,15 +479,18 @@ export class Assertions {
try {
expectations = validateExpectations('t.throwsAsync()', expectations, args.length, experiments);
} catch (error) {
Promise.resolve(thrower).catch(noop);
try {
await thrower;
} catch {}

throw fail(error);
}

const handlePromise = async (promise, wasReturned) => {
// 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 => {
const intermediate = Promise.resolve(promise).then(value => { // eslint-disable-line promise/prefer-await-to-then
throw failPending(new AssertionError(message, {
assertion: 't.throwsAsync()',
assertionStack,
Expand Down Expand Up @@ -568,7 +574,10 @@ export class Assertions {
try {
assertMessage(message, 't.notThrowsAsync()');
} catch (error) {
Promise.resolve(nonThrower).catch(noop);
try {
await nonThrower;
} catch {}

throw error;
}

Expand All @@ -583,7 +592,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 => {
const intermediate = Promise.resolve(promise).then(noop, error => { // eslint-disable-line promise/prefer-await-to-then
throw failPending(new AssertionError(message, {
assertion: 't.notThrowsAsync()',
assertionStack,
Expand Down
7 changes: 3 additions & 4 deletions lib/eslint-plugin-helper-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ const buildGlobs = ({conf, providers, projectDir, overrideExtensions, overrideFi

const resolveGlobs = async (projectDir, overrideExtensions, overrideFiles) => {
if (!configCache.has(projectDir)) {
configCache.set(projectDir, loadConfig({resolveFrom: projectDir}).then(async ({config: conf}) => {
const providers = await collectProviders({conf, projectDir});
return {conf, providers};
}));
const {config: conf} = await loadConfig({resolveFrom: projectDir});
const providers = await collectProviders({conf, projectDir});
configCache.set(projectDir, {conf, providers});
}

const {conf, providers} = await configCache.get(projectDir);
Expand Down
13 changes: 9 additions & 4 deletions lib/plugin-support/shared-workers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const waitForAvailable = async worker => {
}
};

const waitForError = async worker => {
const [error] = await events.once(worker, 'error');
return tagWorkerError(error);
};

function launchWorker(filename, initialData) {
if (launchedWorkers.has(filename)) {
return launchedWorkers.get(filename);
Expand All @@ -34,7 +39,7 @@ function launchWorker(filename, initialData) {
const launched = {
statePromises: {
available: waitForAvailable(worker),
error: events.once(worker, 'error').then(([error]) => tagWorkerError(error)),
error: waitForError(worker),
},
exited: false,
worker,
Expand Down Expand Up @@ -79,7 +84,7 @@ export async function observeWorkerProcess(fork, runStatus) {
}
};

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

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

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

fork.promise.finally(() => {
fork.promise.finally(() => { // eslint-disable-line promise/prefer-await-to-then
launched.worker.postMessage({
type: 'deregister-test-worker',
id: fork.threadId,
Expand Down
4 changes: 2 additions & 2 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,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 => {
const serialPromise = beforePromise.then(beforeHooksOk => { // eslint-disable-line promise/prefer-await-to-then
// Don't run tests if a `before` hook failed.
if (!beforeHooksOk) {
return false;
Expand All @@ -511,7 +511,7 @@ export default class Runner extends Emittery {
return this.runTest(task, contextRef.copy());
}, true);
});
const concurrentPromise = Promise.all([beforePromise, serialPromise]).then(async ([beforeHooksOk, serialOk]) => {
const concurrentPromise = Promise.all([beforePromise, serialPromise]).then(async ([beforeHooksOk, serialOk]) => { // eslint-disable-line promise/prefer-await-to-then
// 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
4 changes: 2 additions & 2 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ export default class Test {
};

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

Expand Down
6 changes: 3 additions & 3 deletions lib/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function * plan({api, filter, globs, projectDir, providers, stdin, abortSi
};

// Begin a file trace in the background.
fileTracer.update(findTests(cwdAndGlobs).then(testFiles => testFiles.map(path => ({
fileTracer.update(findTests(cwdAndGlobs).then(testFiles => testFiles.map(path => ({ // eslint-disable-line promise/prefer-await-to-then
path: nodePath.relative(projectDir, path),
isTest: true,
exists: true,
Expand Down Expand Up @@ -187,7 +187,7 @@ async function * plan({api, filter, globs, projectDir, providers, stdin, abortSi
// If the file tracer is still analyzing dependencies, wait for that to
// complete.
if (fileTracer.busy !== null) {
fileTracer.busy.then(() => debounce.refresh());
fileTracer.busy.then(() => debounce.refresh()); // eslint-disable-line promise/prefer-await-to-then
takeCoverageForSelfTests?.();
return;
}
Expand Down Expand Up @@ -526,7 +526,7 @@ class FileTracer {
}

update(changes) {
const current = this.#update(changes).finally(() => {
const current = this.#update(changes).finally(() => { // eslint-disable-line promise/prefer-await-to-then
if (this.#pendingTrace === current) {
this.#pendingTrace = null;
this.#updateRunning = new Promise(resolve => {
Expand Down
10 changes: 5 additions & 5 deletions lib/worker/base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {mkdir} from 'node:fs/promises';
import {createRequire} from 'node:module';
import {join as joinPath, resolve as resolvePath} from 'node:path';
import path from 'node:path';
import process from 'node:process';
import {pathToFileURL} from 'node:url';
import {workerData} from 'node:worker_threads';
Expand Down Expand Up @@ -89,7 +89,7 @@ const run = async options => {

refs.runnerChain = runner.chain;

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

Expand Down Expand Up @@ -187,7 +187,7 @@ const run = async options => {

// Try to load the module as a file, relative to the project directory.
// Match load() behavior.
const fullPath = resolvePath(projectDir, ref);
const fullPath = path.resolve(projectDir, ref);
try {
for (const extension of extensionsToLoadAsModules) {
if (fullPath.endsWith(`.${extension}`)) {
Expand All @@ -208,9 +208,9 @@ const run = async options => {

let importFromProject = async ref => {
// Do not use the cacheDir since it's not guaranteed to be inside node_modules.
const avaCacheDir = joinPath(projectDir, 'node_modules', '.cache', 'ava');
const avaCacheDir = path.join(projectDir, 'node_modules', '.cache', 'ava');
await mkdir(avaCacheDir, {recursive: true});
const stubPath = joinPath(avaCacheDir, 'import-from-project.mjs');
const stubPath = path.join(avaCacheDir, 'import-from-project.mjs');
await writeFileAtomic(stubPath, 'export const importFromProject = ref => import(ref);\n');
({importFromProject} = await import(pathToFileURL(stubPath)));
return importFromProject(ref);
Expand Down
6 changes: 3 additions & 3 deletions lib/worker/channel.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ function registerSharedWorker(filename, initialData) {
// The attaching of message listeners will cause the port to be referenced by
// Node.js. In order to keep track, explicitly reference before attaching.
sharedWorkerHandle.ref();
const ready = selectAvaMessage(ourPort, 'ready').then(() => {
const ready = selectAvaMessage(ourPort, 'ready').then(() => { // eslint-disable-line promise/prefer-await-to-then
currentlyAvailable = error === null;
}).finally(() => {
}).finally(() => { // eslint-disable-line promise/prefer-await-to-then
// Once ready, it's up to user code to subscribe to messages, which (see
// below) causes us to reference the port.
sharedWorkerHandle.unref();
Expand All @@ -170,7 +170,7 @@ function registerSharedWorker(filename, initialData) {

// Errors are received over the test worker channel, not the message port
// dedicated to the shared worker.
events.once(channelEmitter, 'shared-worker-error').then(() => {
events.once(channelEmitter, 'shared-worker-error').then(() => { // eslint-disable-line promise/prefer-await-to-then
unsubscribe();
sharedWorkerHandle.forceUnref();
error = new Error('The shared worker is no longer available');
Expand Down
Loading

0 comments on commit b15df53

Please sign in to comment.