Skip to content

Commit

Permalink
Upgrade xo to v0.57.0
Browse files Browse the repository at this point in the history
* Upgrade xo to v0.57.0 and lint sources, tests, and examples

Disabled `unicorn/prevent-abbreviations` because it introduces too many
opinionated changes.

* Update reporter logs which are sensitive to line numbers changing

---------

Co-authored-by: Mark Wubben <[email protected]>
make-github-pseudonymous-again and novemberborn authored Feb 27, 2024

Partially verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
1 parent 2e0c2b1 commit 1d62caf
Showing 20 changed files with 439 additions and 473 deletions.
1 change: 1 addition & 0 deletions .xo-config.cjs
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ module.exports = {
'import/newline-after-import': 'error',
'unicorn/require-post-message-target-origin': 'off',
'unicorn/prefer-event-target': 'off',
'unicorn/prevent-abbreviations': 'off',
},
overrides: [
{
2 changes: 1 addition & 1 deletion examples/macros/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const test = require('ava');

const {sum} = require('.');
const {sum} = require('./index.js');

function macro(t, a, b, expected) {
t.is(sum(a, b), expected);
2 changes: 1 addition & 1 deletion examples/timeouts/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
const test = require('ava');

const {fetchUsers, fetchPosts, createPost} = require('.');
const {fetchUsers, fetchPosts, createPost} = require('./index.js');

test('retrieve users', async t => {
t.timeout(100);
4 changes: 3 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
@@ -381,7 +381,9 @@ export default async function loadCli() { // eslint-disable-line complexity

let globs;
try {
globs = normalizeGlobs({files: conf.files, ignoredByWatcher: conf.watchMode?.ignoreChanges, extensions, providers});
globs = normalizeGlobs({
files: conf.files, ignoredByWatcher: conf.watchMode?.ignoreChanges, extensions, providers,
});
} catch (error) {
exit(error.message);
}
8 changes: 4 additions & 4 deletions lib/create-chain.js
Original file line number Diff line number Diff line change
@@ -11,9 +11,7 @@ function startChain(name, call, defaults) {
}

function extendChain(previous, name, flag) {
if (!flag) {
flag = name;
}
flag ||= name;

const fn = (...args) => {
callWithFlag(previous, flag, args);
@@ -89,7 +87,9 @@ export default function createChain(fn, defaults, meta) {
// "todo" tests cannot be chained. Allow todo tests to be flagged as needing
// to be serial.
root.todo = startChain('test.todo', fn, {...defaults, type: 'test', todo: true});
root.serial.todo = startChain('test.serial.todo', fn, {...defaults, serial: true, type: 'test', todo: true});
root.serial.todo = startChain('test.serial.todo', fn, {
...defaults, serial: true, type: 'test', todo: true,
});

root.macro = options => {
if (typeof options === 'function') {
4 changes: 3 additions & 1 deletion lib/eslint-plugin-helper-worker.js
Original file line number Diff line number Diff line change
@@ -48,7 +48,9 @@ const resolveGlobs = async (projectDir, overrideExtensions, overrideFiles) => {
}

const {conf, providers} = await configCache.get(projectDir);
return buildGlobs({conf, providers, projectDir, overrideExtensions, overrideFiles});
return buildGlobs({
conf, providers, projectDir, overrideExtensions, overrideFiles,
});
};

const data = new Uint8Array(workerData.dataBuffer);
6 changes: 4 additions & 2 deletions lib/load-config.js
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ const loadConfigFile = async ({projectDir, configFile}) => {

function resolveConfigFile(configFile) {
if (configFile) {
configFile = path.resolve(configFile); // Relative to CWD
return path.resolve(configFile); // Relative to CWD
}

return configFile;
@@ -153,7 +153,9 @@ export async function loadConfig({configFile, resolveFrom = process.cwd(), defau
}
}

const config = {...defaults, nonSemVerExperiments: {}, ...fileConf, ...packageConf, projectDir, configFile};
const config = {
...defaults, nonSemVerExperiments: {}, ...fileConf, ...packageConf, projectDir, configFile,
};

const {nonSemVerExperiments: experiments} = config;
if (!isPlainObject(experiments)) {
2 changes: 1 addition & 1 deletion lib/plugin-support/shared-worker-loader.js
Original file line number Diff line number Diff line change
@@ -238,7 +238,7 @@ try {
},
});
} catch (error) {
fatal = fatal ?? error;
fatal ??= error;
} finally {
if (fatal !== undefined) {
process.nextTick(() => {
20 changes: 8 additions & 12 deletions lib/snapshot-manager.js
Original file line number Diff line number Diff line change
@@ -220,7 +220,9 @@ export function extractCompressedSnapshot(buffer, snapPath) {
const compressedOffset = sha256sumOffset + SHA_256_HASH_LENGTH;
const compressed = buffer.slice(compressedOffset);

return {version, compressed, sha256sumOffset, compressedOffset};
return {
version, compressed, sha256sumOffset, compressedOffset,
};
}

function decodeSnapshots(buffer, snapPath) {
@@ -290,11 +292,7 @@ class Manager {
}

recordSerialized({data, label, belongsTo, index}) {
let block = this.newBlocksByTitle.get(belongsTo);
if (!block) {
block = {snapshots: []};
}

const block = this.newBlocksByTitle.get(belongsTo) ?? {snapshots: []};
const {snapshots} = block;

if (index > snapshots.length) {
@@ -319,7 +317,9 @@ class Manager {

return () => { // Must be called in order!
this.hasChanges = true;
this.recordSerialized({data, label, belongsTo, index});
this.recordSerialized({
data, label, belongsTo, index,
});
};
}

@@ -338,11 +338,7 @@ class Manager {

skipSnapshot({belongsTo, index, deferRecording}) {
const oldBlock = this.oldBlocksByTitle.get(belongsTo);
let snapshot = oldBlock?.snapshots[index];

if (!snapshot) {
snapshot = {};
}
const snapshot = oldBlock?.snapshots[index] ?? {};

// Retain the label from the old snapshot, so as not to assume that the
// snapshot.skip() arguments are well-formed.
8 changes: 6 additions & 2 deletions lib/test.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,9 @@ import concordance from 'concordance';
import isPromise from 'is-promise';
import plur from 'plur';

import {AssertionError, Assertions, checkAssertionMessage, getAssertionStack} from './assert.js';
import {
AssertionError, Assertions, checkAssertionMessage, getAssertionStack,
} from './assert.js';
import concordanceOptions from './concordance-options.js';
import nowAndTimers from './now-and-timers.cjs';
import parseTestArgs from './parse-test-args.js';
@@ -277,7 +279,9 @@ export default class Test {

const {deferredSnapshotRecordings, error, logs, passed, assertCount, snapshotCount} = await attempt.run();
const errors = error ? [error] : [];
return {assertCount, deferredSnapshotRecordings, errors, logs, passed, snapshotCount, startingSnapshotCount};
return {
assertCount, deferredSnapshotRecordings, errors, logs, passed, snapshotCount, startingSnapshotCount,
};
};

this.assertCount = 0;
12 changes: 9 additions & 3 deletions lib/watcher.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,9 @@ import {nodeFileTrace} from '@vercel/nft';
import createDebug from 'debug';

import {chalk} from './chalk.js';
import {applyTestFileFilter, classify, buildIgnoreMatcher, findTests} from './globs.js';
import {
applyTestFileFilter, classify, buildIgnoreMatcher, findTests,
} from './globs.js';
import {levels as providerLevels} from './provider-manager.js';

const debug = createDebug('ava:watcher');
@@ -34,7 +36,9 @@ export function available(projectDir) {

export async function start({api, filter, globs, projectDir, providers, reporter, stdin, signal}) {
providers = providers.filter(({level}) => level >= providerLevels.ava6);
for await (const {files, ...runtimeOptions} of plan({api, filter, globs, projectDir, providers, stdin, abortSignal: signal})) {
for await (const {files, ...runtimeOptions} of plan({
api, filter, globs, projectDir, providers, stdin, abortSignal: signal,
})) {
await api.run({files, filter, runtimeOptions});
reporter.endRun();
reporter.lineWriter.writeLine(END_MESSAGE);
@@ -62,7 +66,9 @@ async function * plan({api, filter, globs, projectDir, providers, stdin, abortSi
const changeFromPath = path => {
const {isTest} = classify(path, cwdAndGlobs);
const stats = fileStats(path);
return {path, isTest, exists: stats !== undefined, isFile: stats?.isFile() ?? false};
return {
path, isTest, exists: stats !== undefined, isFile: stats?.isFile() ?? false,
};
};

// Begin a file trace in the background.
699 changes: 304 additions & 395 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -138,7 +138,7 @@
"tempy": "^3.1.0",
"tsd": "^0.30.4",
"typescript": "~5.3.3",
"xo": "^0.56.0",
"xo": "^0.57.0",
"zen-observable": "^0.10.0"
},
"peerDependencies": {
74 changes: 44 additions & 30 deletions test-tap/api.js
Original file line number Diff line number Diff line change
@@ -12,12 +12,14 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url));
const ROOT_DIR = path.join(__dirname, '..');

async function apiCreator(options = {}) {
options.projectDir = options.projectDir ?? ROOT_DIR;
options.projectDir ??= ROOT_DIR;
options.chalkOptions = {level: 0};
options.concurrency = 2;
options.extensions = options.extensions ?? ['cjs'];
options.extensions ??= ['cjs'];
options.experiments = {};
options.globs = normalizeGlobs({files: options.files, ignoredByWatcher: options.watchMode?.ignoreChanges, extensions: options.extensions, providers: []});
options.globs = normalizeGlobs({
files: options.files, ignoredByWatcher: options.watchMode?.ignoreChanges, extensions: options.extensions, providers: [],
});
const instance = new Api(options);

return instance;
@@ -97,10 +99,12 @@ for (const opt of options) {
});
});

return api.run({files: [
path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.cjs'),
path.join(__dirname, 'fixture/fail-fast/multiple-files/passes.cjs'),
]})
return api.run({
files: [
path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.cjs'),
path.join(__dirname, 'fixture/fail-fast/multiple-files/passes.cjs'),
],
})
.then(runStatus => {
t.ok(api.options.failFast);
t.strictSame(tests, [{
@@ -214,10 +218,12 @@ for (const opt of options) {
});
});

return api.run({files: [
path.join(__dirname, 'fixture/fail-fast/crash/crashes.cjs'),
path.join(__dirname, 'fixture/fail-fast/crash/passes.cjs'),
]})
return api.run({
files: [
path.join(__dirname, 'fixture/fail-fast/crash/crashes.cjs'),
path.join(__dirname, 'fixture/fail-fast/crash/passes.cjs'),
],
})
.then(runStatus => {
t.ok(api.options.failFast);
t.strictSame(tests, []);
@@ -270,11 +276,13 @@ for (const opt of options) {
});
});

return api.run({files: [
path.join(__dirname, 'fixture/fail-fast/timeout/fails.cjs'),
path.join(__dirname, 'fixture/fail-fast/timeout/passes.cjs'),
path.join(__dirname, 'fixture/fail-fast/timeout/passes-slow.cjs'),
]})
return api.run({
files: [
path.join(__dirname, 'fixture/fail-fast/timeout/fails.cjs'),
path.join(__dirname, 'fixture/fail-fast/timeout/passes.cjs'),
path.join(__dirname, 'fixture/fail-fast/timeout/passes-slow.cjs'),
],
})
.then(runStatus => {
t.ok(api.options.failFast);
t.strictSame(tests, []);
@@ -290,10 +298,12 @@ for (const opt of options) {
failFast: true,
});

return api.run({files: [
path.join(__dirname, 'fixture/fail-fast/without-error/a.cjs'),
path.join(__dirname, 'fixture/fail-fast/without-error/b.cjs'),
]})
return api.run({
files: [
path.join(__dirname, 'fixture/fail-fast/without-error/a.cjs'),
path.join(__dirname, 'fixture/fail-fast/without-error/b.cjs'),
],
})
.then(runStatus => {
t.ok(api.options.failFast);
t.equal(runStatus.stats.passedTests, 2);
@@ -423,11 +433,13 @@ for (const opt of options) {

const api = await apiCreator(opt);

return api.run({files: [
path.join(__dirname, 'fixture/test-count.cjs'),
path.join(__dirname, 'fixture/test-count-2.cjs'),
path.join(__dirname, 'fixture/test-count-3.cjs'),
]}).then(runStatus => {
return api.run({
files: [
path.join(__dirname, 'fixture/test-count.cjs'),
path.join(__dirname, 'fixture/test-count-2.cjs'),
path.join(__dirname, 'fixture/test-count-3.cjs'),
],
}).then(runStatus => {
t.equal(runStatus.stats.passedTests, 4, 'pass count');
t.equal(runStatus.stats.failedTests, 3, 'fail count');
t.equal(runStatus.stats.skippedTests, 3, 'skip count');
@@ -452,11 +464,13 @@ for (const opt of options) {
});
});

return api.run({files: [
path.join(__dirname, 'fixture/match-no-match.cjs'),
path.join(__dirname, 'fixture/match-no-match-2.cjs'),
path.join(__dirname, 'fixture/test-count.cjs'),
]}).then(runStatus => {
return api.run({
files: [
path.join(__dirname, 'fixture/match-no-match.cjs'),
path.join(__dirname, 'fixture/match-no-match-2.cjs'),
path.join(__dirname, 'fixture/test-count.cjs'),
],
}).then(runStatus => {
t.equal(runStatus.stats.passedTests, 1);
});
});
24 changes: 19 additions & 5 deletions test-tap/assert.js
Original file line number Diff line number Diff line change
@@ -538,13 +538,21 @@ test('.deepEqual()', t => {
{foo: {z: 100, y: 200, x: 300}},
'bar',
11,
{baz: {d: 4, a: 1, b: 2, c: 3}},
{
baz: {
d: 4, a: 1, b: 2, c: 3,
},
},
],
[
{foo: {x: 300, y: 200, z: 100}},
'bar',
11,
{baz: {c: 3, b: 2, a: 1, d: 4}},
{
baz: {
c: 3, b: 2, a: 1, d: 4,
},
},
],
));

@@ -778,7 +786,9 @@ test('.like()', t => {

passes(t, () => {
const array = ['c1', 'c2'];
return assertions.like({a: 'a', b: 'b', c: ['c1', 'c2'], d: ['c1', 'c2']}, {b: 'b', d: array, c: array});
return assertions.like({
a: 'a', b: 'b', c: ['c1', 'c2'], d: ['c1', 'c2'],
}, {b: 'b', d: array, c: array});
});

failsWith(t, () => {
@@ -1227,7 +1237,9 @@ test('.throws() fails if passed a bad expectation', t => {
formattedDetails: [{label: 'Called with:', formatted: /name: null/}],
});

failsWith(t, () => assertions.throws(() => {}, {is: {}, message: '', name: '', of() {}, foo: null}), {
failsWith(t, () => assertions.throws(() => {}, {
is: {}, message: '', name: '', of() {}, foo: null,
}), {
assertion: 't.throws()',
message: 'The second argument to `t.throws()` contains unexpected properties',
formattedDetails: [{label: 'Called with:', formatted: /foo: null/}],
@@ -1303,7 +1315,9 @@ test('.throwsAsync() fails if passed a bad expectation', async t => {
formattedDetails: [{label: 'Called with:', formatted: /name: null/}],
});

await failsWithAsync(t, () => assertions.throwsAsync(() => {}, {is: {}, message: '', name: '', of() {}, foo: null}), {
await failsWithAsync(t, () => assertions.throwsAsync(() => {}, {
is: {}, message: '', name: '', of() {}, foo: null,
}), {
assertion: 't.throwsAsync()',
message: 'The second argument to `t.throwsAsync()` contains unexpected properties',
formattedDetails: [{label: 'Called with:', formatted: /foo: null/}],
20 changes: 15 additions & 5 deletions test-tap/code-excerpt.js
Original file line number Diff line number Diff line change
@@ -16,7 +16,9 @@ test('read code excerpt', t => {
alert();
}`));

const excerpt = codeExcerpt({file, line: 2, isWithinProject: true, isDependency: false});
const excerpt = codeExcerpt({
file, line: 2, isWithinProject: true, isDependency: false,
});
const expected = [
` ${chalk.grey('1:')} function a() {`,
chalk.bgRed.bold(' 2: alert(); '),
@@ -32,7 +34,9 @@ test('truncate lines', t => {
alert();
}`));

const excerpt = codeExcerpt({file, line: 2, isWithinProject: true, isDependency: false}, {maxWidth: 14});
const excerpt = codeExcerpt({
file, line: 2, isWithinProject: true, isDependency: false,
}, {maxWidth: 14});
const expected = [
` ${chalk.grey('1:')} functio…`,
chalk.bgRed.bold(' 2: alert…'),
@@ -56,7 +60,9 @@ function a() {
alert();
}`));

const excerpt = codeExcerpt({file, line: 10, isWithinProject: true, isDependency: false});
const excerpt = codeExcerpt({
file, line: 10, isWithinProject: true, isDependency: false,
});
const expected = [
` ${chalk.grey(' 9:')} function a() {`,
chalk.bgRed.bold(' 10: alert(); '),
@@ -69,7 +75,9 @@ function a() {

test('noop if file cannot be read', t => {
const file = pathToFileURL(temporaryFile());
const excerpt = codeExcerpt({file, line: 10, isWithinProject: true, isDependency: false});
const excerpt = codeExcerpt({
file, line: 10, isWithinProject: true, isDependency: false,
});
t.equal(excerpt, null);
t.end();
});
@@ -81,7 +89,9 @@ test('noop if file is not within project', t => {
});

test('noop if file is a dependency', t => {
const excerpt = codeExcerpt({isWithinProject: true, isDependency: true, file: import.meta.url, line: 1});
const excerpt = codeExcerpt({
isWithinProject: true, isDependency: true, file: import.meta.url, line: 1,
});
t.equal(excerpt, null);
t.end();
});
4 changes: 2 additions & 2 deletions test-tap/reporters/tap.regular.v18.log
Original file line number Diff line number Diff line change
@@ -113,7 +113,7 @@ not ok 12 - test › no longer failing
message: >-
Test was expected to fail, but succeeded, you should stop marking the test as
failing
at: 'Test.finish (/lib/test.js:629:28)'
at: 'Test.finish (/lib/test.js:633:28)'
...
---tty-stream-chunk-separator
not ok 13 - test › logs
@@ -144,7 +144,7 @@ not ok 15 - test › implementation throws non-error
details:
'Error thrown in test:': 'null'
message: Error thrown in test
at: 'Test.run (/lib/test.js:542:25)'
at: 'Test.run (/lib/test.js:546:25)'
...
---tty-stream-chunk-separator
not ok 16 - traces-in-t-throws › throws
4 changes: 2 additions & 2 deletions test-tap/reporters/tap.regular.v20.log
Original file line number Diff line number Diff line change
@@ -113,7 +113,7 @@ not ok 12 - test › no longer failing
message: >-
Test was expected to fail, but succeeded, you should stop marking the test as
failing
at: 'Test.finish (/lib/test.js:629:28)'
at: 'Test.finish (/lib/test.js:633:28)'
...
---tty-stream-chunk-separator
not ok 13 - test › logs
@@ -144,7 +144,7 @@ not ok 15 - test › implementation throws non-error
details:
'Error thrown in test:': 'null'
message: Error thrown in test
at: 'Test.run (/lib/test.js:542:25)'
at: 'Test.run (/lib/test.js:546:25)'
...
---tty-stream-chunk-separator
not ok 16 - traces-in-t-throws › throws
4 changes: 2 additions & 2 deletions test-tap/reporters/tap.regular.v21.log
Original file line number Diff line number Diff line change
@@ -113,7 +113,7 @@ not ok 12 - test › no longer failing
message: >-
Test was expected to fail, but succeeded, you should stop marking the test as
failing
at: 'Test.finish (/lib/test.js:629:28)'
at: 'Test.finish (/lib/test.js:633:28)'
...
---tty-stream-chunk-separator
not ok 13 - test › logs
@@ -144,7 +144,7 @@ not ok 15 - test › implementation throws non-error
details:
'Error thrown in test:': 'null'
message: Error thrown in test
at: 'Test.run (/lib/test.js:542:25)'
at: 'Test.run (/lib/test.js:546:25)'
...
---tty-stream-chunk-separator
not ok 16 - traces-in-t-throws › throws
12 changes: 9 additions & 3 deletions test/helpers/exec.js
Original file line number Diff line number Diff line change
@@ -65,7 +65,9 @@ const initState = () => {
},
};

return {errors, logs, stats, stdout: '', stderr: ''};
return {
errors, logs, stats, stdout: '', stderr: '',
};
};

const sortStats = stats => {
@@ -121,7 +123,9 @@ export async function * exec(args, options) {
const item = await Promise.race([done, statusEvents.next()]); // eslint-disable-line no-await-in-loop
if (item.execa) {
sortStats(stats);
yield {process: execaProcess, stats, stdout, stderr, runCount};
yield {
process: execaProcess, stats, stdout, stderr, runCount,
};
break;
}

@@ -134,7 +138,9 @@ export async function * exec(args, options) {
case 'end': {
sortStats(stats);
runCount++;
yield {process: execaProcess, stats, stdout, stderr, runCount};
yield {
process: execaProcess, stats, stdout, stderr, runCount,
};
({errors, logs, stats, stdout, stderr} = initState());
break;
}

0 comments on commit 1d62caf

Please sign in to comment.