Skip to content

Commit

Permalink
Update all the things
Browse files Browse the repository at this point in the history
* Test lockfile using npm 7.23

* Workflow updates

* Update codecov action
* Cache npm dependencies
* Simplify checkout

* Bump minimal Node.js versions

These should allow us to add features over AVA 4's lifetime using newly
available Node.js APIs.

* Update dev dependencies

* Update to TypeScript 4.4 and latest tsd

* Upgrade XO and reformat

* Update dependencies

* Rebuild lockfile

* Run XO with Node.js 16

It fails on older Node.js versions.
  • Loading branch information
novemberborn committed Sep 12, 2021
1 parent e96b82d commit e8a4976
Show file tree
Hide file tree
Showing 210 changed files with 8,852 additions and 11,486 deletions.
34 changes: 14 additions & 20 deletions .github/workflows/ci.yml
Expand Up @@ -15,12 +15,10 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [^12.22, ^14.15, ^16]
node-version: [^12.22, ^14.17, ^16.4]
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Enable symlinks
if: matrix.os == 'windows-latest'
run: |
Expand All @@ -29,31 +27,31 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: npm
- name: Upgrade npm
run: npm install --global npm@7
- run: npm ci --no-audit
- run: npm install --no-audit
- run: npm run cover
- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v2
with:
file: coverage/lcov.info
files: coverage/lcov.info
name: ${{ matrix.os }}/${{ matrix.node-version }}

typescript:
name: TypeScript compatibility
runs-on: ubuntu-latest
strategy:
matrix:
ts-version: [~4.2]
ts-version: [~4.4]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- uses: actions/setup-node@v2
with:
node-version: ^12.22
cache: npm
- name: Upgrade npm
run: npm install --global npm@7
- run: npm ci --no-audit
- run: npm install --no-audit
- run: npm i typescript@${TS_VERSION}
env:
TS_VERSION: ${{ matrix.ts-version }}
Expand All @@ -65,14 +63,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- uses: actions/setup-node@v2
with:
node-version: ^12.22
cache: npm
- name: Upgrade npm
run: if [[ "$(npm -v)" != "7.11" ]]; then npm install --global npm@7.11; fi
- run: npm ci --no-audit
run: if [[ "$(npm -v)" != "7.23" ]]; then npm install --global npm@7.23; fi
- run: npm install --no-audit
- name: Test package-lock for unexpected modifications
run: |
npm -v
Expand All @@ -88,8 +85,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- uses: actions/setup-node@v2
with:
node-version: ^12.22
Expand All @@ -103,12 +98,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- uses: actions/setup-node@v2
with:
node-version: ^12.22
node-version: ^16.4
cache: npm
- name: Upgrade npm
run: npm install --global npm@7
- run: npm ci
- run: npm install --no-audit
- run: npx xo
38 changes: 20 additions & 18 deletions .xo-config.json
Expand Up @@ -7,8 +7,6 @@
"examples/typescript-*/**/*.ts"
],
"rules": {
"import/no-anonymous-default-export": "off",
"import/no-mutable-exports": "off",
"import/order": [
"error",
{
Expand All @@ -19,8 +17,7 @@
}
],
"import/newline-after-import": "error",
"node/no-unsupported-features/es-syntax": "off",
"no-use-extend-native/no-use-extend-native": "off"
"unicorn/require-post-message-target-origin": "off"
},
"overrides": [
{
Expand All @@ -39,21 +36,28 @@
}
},
{
"files": "test-{d,tap}/**/*.ts",
"files": "{test,test-{d,tap}}/**/*.ts",
"rules": {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/prefer-readonly-parameter-types": "off",
"import/extensions": "off",
"no-unused-vars": "off"
"@typescript-eslint/prefer-readonly-parameter-types": "off"
}
},
{
"files": "test-tap/**/*.js",
"files": "{test,test-{d,tap}}/**",
"rules": {
"import/no-anonymous-default-export": "off",
"node/prefer-global/buffer": "off",
"node/prefer-global/process": "off"
}
},
{
"files": "test-tap/**",
"rules": {
"promise/prefer-await-to-then": "off",
"unicorn/error-message": "off",
Expand All @@ -62,20 +66,18 @@
}
},
{
"files": [
"test-tap/fixture/**",
"test/**/fixtures/**"
],
"files": "test/macros/fixtures/macros.js",
"rules": {
"ava/no-todo-test": "off",
"import/no-extraneous-dependencies": "off",
"import/no-unresolved": "off"
"ava/no-identical-title": "off"
}
},
{
"files": "test/macros/fixtures/macros.js",
"files": [
"examples/**",
"test/snapshot-*/fixtures/**"
],
"rules": {
"ava/no-identical-title": "off"
"unicorn/prefer-module": "off"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion ava.config.cjs
Expand Up @@ -3,5 +3,5 @@
// installed "test-ava" version.
module.exports = {
files: ['test/**', '!test/**/{fixtures,helpers}/**'],
ignoredByWatcher: ['{coverage,docs,media,test-d,test-tap}/**']
ignoredByWatcher: ['{coverage,docs,media,test-d,test-tap}/**'],
};
2 changes: 1 addition & 1 deletion docs/recipes/typescript.md
Expand Up @@ -4,7 +4,7 @@ Translations: [Espa帽ol](https://github.com/avajs/ava-docs/blob/master/es_ES/doc

AVA comes bundled with a TypeScript definition file. This allows developers to leverage TypeScript for writing tests.

This guide assumes you've already set up TypeScript for your project. Note that AVA 3's definition expects at least version 3.7.5. AVA 4 will require at least version 4.2.
This guide assumes you've already set up TypeScript for your project. Note that AVA 3's definition expects at least version 3.7.5. AVA 4 will require at least version 4.4.

## Enabling AVA's support for TypeScript test files

Expand Down
10 changes: 5 additions & 5 deletions entrypoints/eslint-plugin-helper.cjs
Expand Up @@ -10,7 +10,7 @@ const {
isHelperish,
matches,
normalizeFileForMatching,
normalizePatterns
normalizePatterns,
} = require('../lib/glob-helpers.cjs');

const MAX_DATA_LENGTH_EXCLUSIVE = 100 * 1024; // Allocate 100 KiB to exchange globs.
Expand All @@ -32,15 +32,15 @@ const resolveGlobsSync = (projectDir, overrideExtensions, overrideFiles) => {
workerData: {
dataBuffer,
syncBuffer,
firstMessage: {projectDir, overrideExtensions, overrideFiles}
}
firstMessage: {projectDir, overrideExtensions, overrideFiles},
},
});
worker.unref();
} else {
worker.postMessage({projectDir, overrideExtensions, overrideFiles});
}

const synchronize = Atomics.wait(sync, 0, 0, 10000);
const synchronize = Atomics.wait(sync, 0, 0, 10_000);
if (synchronize === 'timed-out') {
throw new Error('Timed out resolving AVA configuration');
}
Expand Down Expand Up @@ -100,7 +100,7 @@ function load(projectDir, overrides) {
// Add the first extension. If multiple extensions are available, assume
// patterns are not biased to any particular extension.
return classifyForESLint(`${importPath}.${globs.extensions[0]}`);
}
},
});
helperCache.set(cacheKey, helper);
return helper;
Expand Down
2 changes: 1 addition & 1 deletion examples/endpoint-testing/test.js
Expand Up @@ -5,7 +5,7 @@ const test = require('ava');
const got = require('got');
const listen = require('test-listen');

const app = require('./app');
const app = require('./app.js');

test.before(async t => {
t.context.server = http.createServer(app);
Expand Down
1 change: 0 additions & 1 deletion examples/macros/test.js
@@ -1,4 +1,3 @@
'use strict';
const test = require('ava');

const {sum} = require('.');
Expand Down
18 changes: 8 additions & 10 deletions examples/timeouts/index.js
@@ -1,10 +1,8 @@
'use strict';

const delay = ms => {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
};
const delay = ms => new Promise(resolve => {
setTimeout(resolve, ms);
});

exports.fetchUsers = async () => {
await delay(50);
Expand All @@ -14,8 +12,8 @@ exports.fetchUsers = async () => {
id: 1,
firstName: 'Ava',
name: 'Rocks',
email: 'ava@rocks.com'
}
email: 'ava@rocks.com',
},
];
};

Expand All @@ -26,8 +24,8 @@ exports.fetchPosts = async userId => {
{
id: 1,
userId,
message: 'AVA Rocks 馃殌'
}
message: 'AVA Rocks 馃殌',
},
];
};

Expand All @@ -37,6 +35,6 @@ exports.createPost = async message => {
return {
id: 2,
userId: 1,
message
message,
};
};
10 changes: 5 additions & 5 deletions examples/timeouts/test.js
Expand Up @@ -13,8 +13,8 @@ test('retrieve users', async t => {
id: 1,
firstName: 'Ava',
name: 'Rocks',
email: 'ava@rocks.com'
}
email: 'ava@rocks.com',
},
]);
});

Expand All @@ -27,8 +27,8 @@ test('retrieve posts', async t => {
{
id: 1,
userId: 1,
message: 'AVA Rocks 馃殌'
}
message: 'AVA Rocks 馃殌',
},
]);
});

Expand All @@ -38,6 +38,6 @@ test('create post', async t => {
t.deepEqual(post, {
id: 2,
userId: 1,
message: 'I love 馃 and 馃寛'
message: 'I love 馃 and 馃寛',
});
});
19 changes: 10 additions & 9 deletions lib/api.js
@@ -1,6 +1,7 @@
import fs from 'fs';
import os from 'os';
import path from 'path';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import process from 'node:process';

import arrify from 'arrify';
import chunkd from 'chunkd';
Expand Down Expand Up @@ -126,7 +127,7 @@ export default class Api extends Emittery {
selectedFiles = filter.length === 0 ? testFiles : globs.applyTestFileFilter({
cwd: this.options.projectDir,
filter: filter.map(({pattern}) => pattern),
testFiles
testFiles,
});
}
} catch (error) {
Expand Down Expand Up @@ -165,7 +166,7 @@ export default class Api extends Emittery {
previousFailures: runtimeOptions.previousFailures || 0,
runOnlyExclusive: runtimeOptions.runOnlyExclusive === true,
runVector: runtimeOptions.runVector || 0,
status: runStatus
status: runStatus,
});

if (setupOrGlobError) {
Expand Down Expand Up @@ -230,7 +231,7 @@ export default class Api extends Emittery {
lineNumbers,
recordNewSnapshots: !isCi,
// If we're looking for matches, run every single test process in exclusive-only mode
runOnlyExclusive: apiOptions.match.length > 0 || runtimeOptions.runOnlyExclusive === true
runOnlyExclusive: apiOptions.match.length > 0 || runtimeOptions.runOnlyExclusive === true,
};

if (runtimeOptions.updateSnapshots) {
Expand Down Expand Up @@ -282,9 +283,9 @@ export default class Api extends Emittery {
return this._cacheDir;
}

const cacheDir = this.options.cacheEnabled === false ?
fs.mkdtempSync(`${tempDir}${path.sep}`) :
this._getLocalCacheDir();
const cacheDir = this.options.cacheEnabled === false
? fs.mkdtempSync(`${tempDir}${path.sep}`)
: this._getLocalCacheDir();

// Ensure cacheDir exists
fs.mkdirSync(cacheDir, {recursive: true});
Expand Down

0 comments on commit e8a4976

Please sign in to comment.