Skip to content

Commit

Permalink
Update dependencies and such
Browse files Browse the repository at this point in the history
* Upgrade XO and reformat

* Update dev dependencies

* Test with TypeScript 4.9

* Update dependencies

* Pin latest node@18 for Volta

* Use npm@9

* Rebuild lockfile

* Select Node.js version from Volta pin in most CI jobs

* Only pin npm when testing for lockfile churn; ensure npm@8 for Node.js 14
  • Loading branch information
novemberborn authored Jan 15, 2023
1 parent ffed948 commit da3d2bc
Show file tree
Hide file tree
Showing 32 changed files with 903 additions and 581 deletions.
25 changes: 10 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: npm
- name: Upgrade npm
run: npm install --global npm@^8.18
- name: Install npm@8 for Node.js 14
if: matrix.node-version == '^14.19'
run: npm install --global npm@^8
- run: npm install --no-audit
- run: npm run cover
- uses: codecov/codecov-action@v2
Expand All @@ -42,15 +43,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ts-version: [~4.7, ~4.8]
ts-version: [~4.7, ~4.8, ~4.9]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ^18
node-version-file: package.json
cache: npm
- name: Upgrade npm
run: npm install --global npm@^8.18
- run: npm install --no-audit
- run: npm i typescript@${TS_VERSION}
env:
Expand All @@ -65,10 +64,10 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ^18
node-version-file: package.json
cache: npm
- name: Upgrade npm
run: if [[ "$(npm -v)" != "8.18.0" ]]; then npm install --global npm@8.18.0; fi
- name: Pin npm
run: npm install --global npm@9.3.0
- run: npm install --no-audit
- name: Test package-lock for unexpected modifications
run: |
Expand All @@ -87,9 +86,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ^18
- name: Upgrade npm
run: npm install --global npm@^8.18
node-version-file: package.json
- run: npm install --no-package-lock --no-audit
- run: npm run cover

Expand All @@ -100,9 +97,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ^18
node-version-file: package.json
cache: npm
- name: Upgrade npm
run: npm install --global npm@^8.18
- run: npm install --no-audit
- run: npx xo
8 changes: 4 additions & 4 deletions entrypoints/eslint-plugin-helper.cjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
const path = require('path');
const url = require('url');
const v8 = require('v8');
const {Worker} = require('worker_threads');
const path = require('node:path');
const url = require('node:url');
const v8 = require('node:v8');
const {Worker} = require('node:worker_threads');

const {
classify,
Expand Down
2 changes: 1 addition & 1 deletion examples/endpoint-testing/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const http = require('http');
const http = require('node:http');

const test = require('ava');
const got = require('got');
Expand Down
9 changes: 6 additions & 3 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class AssertionError extends Error {
// use the values for custom diff views
this.raw = options.raw;

this.savedError = options.savedError ? options.savedError : getErrorWithLongStackTrace();
this.savedError = options.savedError || getErrorWithLongStackTrace();
}
}

Expand Down Expand Up @@ -143,14 +143,17 @@ function validateExpectations(assertion, expectations, numberArgs) { // eslint-d
case 'is':
case 'message':
case 'name':
case 'code':
case 'code': {
continue;
default:
}

default: {
throw new AssertionError({
assertion,
message: `The second argument to \`t.${assertion}()\` contains unexpected properties`,
values: [formatWithLabel('Called with:', expectations)],
});
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/eslint-plugin-helper-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const buildGlobs = ({conf, providers, projectDir, overrideExtensions, overrideFi
cwd: projectDir,
...normalizeGlobs({
extensions,
files: overrideFiles ? overrideFiles : conf.files,
files: overrideFiles || conf.files,
providers,
}),
};
Expand Down Expand Up @@ -69,5 +69,5 @@ const handleMessage = async ({projectDir, overrideExtensions, overrideFiles}) =>
};

parentPort.on('message', handleMessage);
handleMessage(workerData.firstMessage);
handleMessage(workerData.firstMessage); // eslint-disable-line unicorn/prefer-top-level-await
delete workerData.firstMessage;
11 changes: 8 additions & 3 deletions lib/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ export default function loadFork(file, options, execArgv = process.execArgv) {
}

switch (message.ava.type) {
case 'ready-for-options':
case 'ready-for-options': {
send({type: 'options', options});
break;
}

case 'shared-worker-connect': {
const {channelId, filename, initialData, port} = message.ava;
emitter.emit('connectSharedWorker', {
Expand All @@ -125,11 +127,14 @@ export default function loadFork(file, options, execArgv = process.execArgv) {
break;
}

case 'ping':
case 'ping': {
send({type: 'pong'});
break;
default:
}

default: {
emitStateChange(message.ava);
}
}
});

Expand Down
4 changes: 2 additions & 2 deletions lib/glob-helpers.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const path = require('path');
const process = require('process');
const path = require('node:path');
const process = require('node:process');

const ignoreByDefault = require('ignore-by-default');
const picomatch = require('picomatch');
Expand Down
30 changes: 22 additions & 8 deletions lib/module-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@ const requireTrueValue = value => {

const normalize = (extension, type, defaultModuleType) => {
switch (extension) {
case 'cjs':
case 'cjs': {
requireTrueValue(type);
return 'commonjs';
case 'mjs':
}

case 'mjs': {
requireTrueValue(type);
return 'module';
case 'js':
}

case 'js': {
requireTrueValue(type);
return defaultModuleType;
default:
}

default: {
if (type !== 'commonjs' && type !== 'module') {
throw new TypeError(`Module type for ’${extension}’ must be ’commonjs’ or ’module’`);
}

return type;
}
}
};

Expand All @@ -37,17 +44,24 @@ const deriveFromArray = (extensions, defaultModuleType) => {
const moduleTypes = {};
for (const extension of extensions) {
switch (extension) {
case 'cjs':
case 'cjs': {
moduleTypes.cjs = 'commonjs';
break;
case 'mjs':
}

case 'mjs': {
moduleTypes.mjs = 'module';
break;
case 'js':
}

case 'js': {
moduleTypes.js = defaultModuleType;
break;
default:
}

default: {
moduleTypes[extension] = 'commonjs';
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/now-and-timers.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const timers = require('timers');
const timers = require('node:timers');

Object.assign(exports, timers);
exports.now = Date.now;
Expand Down
13 changes: 6 additions & 7 deletions lib/plugin-support/shared-worker-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ let signalAvailable = () => {
};

let fatal;
loadFactory(workerData.filename).then(factory => {
try {
const factory = await loadFactory(workerData.filename);
if (typeof factory !== 'function') {
throw new TypeError(`Missing default factory function export for shared worker plugin at ${workerData.filename}`);
}
Expand Down Expand Up @@ -236,14 +237,12 @@ loadFactory(workerData.filename).then(factory => {
};
},
});
}).catch(error => {
if (fatal === undefined) {
fatal = error;
}
}).finally(() => {
} catch (error) {
fatal = fatal ?? error;
} finally {
if (fatal !== undefined) {
process.nextTick(() => {
throw fatal;
});
}
});
}
67 changes: 50 additions & 17 deletions lib/reporters/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,52 +153,78 @@ export default class TapReporter {
const fileStats = this.stats && evt.testFile ? this.stats.byFile.get(evt.testFile) : null;

switch (evt.type) {
case 'declared-test':
case 'declared-test': {
// Ignore
break;
case 'hook-failed':
}

case 'hook-failed': {
this.writeTest(evt, {passed: false, todo: false, skip: false});
break;
case 'hook-finished':
}

case 'hook-finished': {
this.writeComment(evt, {});
break;
case 'internal-error':
}

case 'internal-error': {
this.writeCrash(evt);
break;
case 'missing-ava-import':
}

case 'missing-ava-import': {
this.filesWithMissingAvaImports.add(evt.testFile);
this.writeCrash(evt, `No tests found in ${this.relativeFile(evt.testFile)}, make sure to import "ava" at the top of your test file`);
break;
case 'process-exit':
}

case 'process-exit': {
this.writeProcessExit(evt);
break;
case 'selected-test':
}

case 'selected-test': {
if (evt.skip) {
this.writeTest(evt, {passed: true, todo: false, skip: true});
} else if (evt.todo) {
this.writeTest(evt, {passed: false, todo: true, skip: false});
}

break;
case 'stats':
}

case 'stats': {
this.stats = evt.stats;
break;
case 'test-failed':
}

case 'test-failed': {
this.writeTest(evt, {passed: false, todo: false, skip: false});
break;
case 'test-passed':
}

case 'test-passed': {
this.writeTest(evt, {passed: true, todo: false, skip: false});
break;
case 'timeout':
}

case 'timeout': {
this.writeTimeout(evt);
break;
case 'uncaught-exception':
}

case 'uncaught-exception': {
this.writeCrash(evt);
break;
case 'unhandled-rejection':
}

case 'unhandled-rejection': {
this.writeCrash(evt);
break;
case 'worker-failed':
}

case 'worker-failed': {
if (!this.filesWithMissingAvaImports.has(evt.testFile)) {
if (evt.nonZeroExitCode) {
this.writeCrash(evt, `${this.relativeFile(evt.testFile)} exited with a non-zero exit code: ${evt.nonZeroExitCode}`);
Expand All @@ -208,7 +234,9 @@ export default class TapReporter {
}

break;
case 'worker-finished':
}

case 'worker-finished': {
if (!evt.forcedExit && !this.filesWithMissingAvaImports.has(evt.testFile)) {
if (fileStats.declaredTests === 0) {
this.writeCrash(evt, `No tests found in ${this.relativeFile(evt.testFile)}`);
Expand All @@ -218,12 +246,17 @@ export default class TapReporter {
}

break;
}

case 'worker-stderr':
case 'worker-stdout':
case 'worker-stdout': {
this.stdStream.write(evt.chunk);
break;
default:
}

default: {
break;
}
}
}
}
Loading

0 comments on commit da3d2bc

Please sign in to comment.