Skip to content

Commit b32ff7a

Browse files
committed
fixup! fixup! fixup! fixup! fixup! fixup! fixup! Convert to ESM
1 parent d2cf00e commit b32ff7a

File tree

32 files changed

+108
-76
lines changed

32 files changed

+108
-76
lines changed

lib/cli.js

+1
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ export default async () => { // eslint-disable-line complexity
431431
reportStream: process.stdout,
432432
stdStream: process.stderr
433433
}) : new DefaultReporter({
434+
extensions: globs.extensions,
434435
projectDir,
435436
reportStream: process.stdout,
436437
stdStream: process.stderr,

lib/reporters/default.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ function manageCorking(stream) {
141141

142142
export default class Reporter {
143143
constructor({
144+
extensions,
144145
verbose,
145146
reportStream,
146147
stdStream,
@@ -149,6 +150,7 @@ export default class Reporter {
149150
spinner,
150151
durationThreshold
151152
}) {
153+
this.extensions = extensions;
152154
this.verbose = verbose;
153155
this.reportStream = reportStream;
154156
this.stdStream = stdStream;
@@ -223,7 +225,7 @@ export default class Reporter {
223225
this.emptyParallelRun = plan.status.emptyParallelRun;
224226

225227
if (this.watching || plan.files.length > 1) {
226-
this.prefixTitle = (testFile, title) => prefixTitle(plan.filePathPrefix, testFile, title);
228+
this.prefixTitle = (testFile, title) => prefixTitle(this.extensions, plan.filePathPrefix, testFile, title);
227229
}
228230

229231
this.removePreviousListener = plan.status.on('stateChange', evt => {

lib/reporters/prefix-title.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import {chalk} from '../chalk.js';
66

77
const SEPERATOR = ' ' + chalk.gray.dim(figures.pointerSmall) + ' ';
88

9-
export default (base, file, title) => {
9+
export default (extensions, base, file, title) => {
1010
const prefix = file
1111
// Only replace base if it is found at the start of the path
1212
.replace(base, (match, offset) => offset === 0 ? '' : match)
1313
.replace(/\.spec/, '')
1414
.replace(/\.test/, '')
1515
.replace(/test-/g, '')
16-
.replace(/\.js$/, '')
16+
.replace(new RegExp(`.(${extensions.join('|')})$`), '')
1717
.split(path.sep)
1818
.filter(p => p !== '__tests__')
1919
.join(SEPERATOR);

lib/watcher.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import nodePath from 'path';
22

3-
import chokidar from 'chokidar';
3+
import chokidar_ from 'chokidar';
44
import createDebug from 'debug';
55
import diff from 'lodash/difference.js';
66
import flatten from 'lodash/flatten.js';
@@ -9,7 +9,15 @@ import {chalk} from './chalk.js';
99
import {applyTestFileFilter, classify, getChokidarIgnorePatterns} from './globs.js';
1010
import providerManager from './provider-manager.js';
1111

12-
const debug = createDebug('ava:watcher');
12+
let chokidar = chokidar_;
13+
export function _injectChokidar(injected) {
14+
chokidar = injected;
15+
}
16+
17+
let debug = createDebug('ava:watcher');
18+
export function _injectDebug(injected) {
19+
debug = injected('ava:watcher');
20+
}
1321

1422
function rethrowAsync(error) {
1523
// Don't swallow exceptions. Note that any

test-tap/fixture/_generate-source-map-initial.cjs

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ test('throw an uncaught exception', t => {
2020
})
2121
const run = () => fixture.run();
2222
`.trim(), {
23-
filename: 'source-map-initial-input.js',
23+
filename: 'source-map-initial-input.cjs',
2424
sourceMaps: true,
2525
presets: ['@ava/stage-4']
2626
});
2727

2828
fs.writeFileSync(
29-
path.join(__dirname, 'source-map-initial.js'),
30-
transformed.code + '\n//# sourceMappingURL=./source-map-initial.js.map\n// Generated using node test/fixtures/_generate-source-map-initial.js\n'
29+
path.join(__dirname, 'source-map-initial.cjs'),
30+
transformed.code + '\n//# sourceMappingURL=./source-map-initial.cjs.map\n// Generated using node test/fixtures/_generate-source-map-initial.js\n'
3131
);
3232
fs.writeFileSync(
33-
path.join(__dirname, 'source-map-initial.js.map'),
33+
path.join(__dirname, 'source-map-initial.cjs.map'),
3434
JSON.stringify(transformed.map)
3535
);
3636

37-
console.log('Generated source-map-initial.js');
37+
console.log('Generated source-map-initial.cjs');
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"ava": {
3-
"files": ["*.js"]
3+
"files": [
4+
"*.cjs"
5+
]
46
}
57
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"ava": {
3-
"files": ["*.js"]
3+
"files": [
4+
"*.cjs"
5+
]
46
}
57
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"ava": {
3-
"files": ["*.js"]
3+
"files": [
4+
"*.cjs"
5+
]
46
}
57
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"ava": {
3-
"files": ["tests/test.js"]
3+
"files": [
4+
"tests/test.cjs"
5+
]
46
}
57
}

test-tap/fixture/snapshots/test-dir/test/test.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../../../../entrypoints/main.cjs';
1+
const test = require('../../../../../entrypoints/main.cjs');
22

33
test('test title', t => {
44
t.snapshot({foo: 'bar'});

test-tap/fixture/snapshots/test-snapshot-location/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"ava": {
33
"files": [
4-
"src/**/*test.js"
4+
"src/**/*test.cjs"
55
],
66
"snapshotDir": "snapshot-fixtures"
77
}

test-tap/fixture/snapshots/test-sourcemaps/build/feature/__tests__/test.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ test('feature test title', t => {
66
test('another feature test', t => {
77
t.snapshot(new Map());
88
});
9-
//# sourceMappingURL=test.js.map
9+
//# sourceMappingURL=test.cjs.map
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": 3,
3+
"file": "test.cjs",
4+
"sourceRoot": "",
5+
"sources": [
6+
"../../../src/feature/__tests__/test.ts"
7+
],
8+
"names": [],
9+
"mappings": "AAAA,OAAO,IAAI,MAAM,sBAAsB,CAAA;AAEvC,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAC3B,CAAC,CAAC,QAAQ,CAAC,EAAC,GAAG,EAAE,KAAK,EAAC,CAAC,CAAC;IAEzB,CAAC,CAAC,QAAQ,CAAC,EAAC,MAAM,EAAE,EAAE,EAAC,CAAC,CAAC;AAC1B,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAC7B,CAAC,CAAC,QAAQ,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"
10+
}

test-tap/fixture/snapshots/test-sourcemaps/build/feature/__tests__/test.js.map

-1
This file was deleted.

test-tap/fixture/snapshots/test-sourcemaps/build/test.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ test('top level test title', t => {
66
test('another top level test', t => {
77
t.snapshot(new Map());
88
});
9-
//# sourceMappingURL=test.js.map
9+
//# sourceMappingURL=test.cjs.map

test-tap/fixture/snapshots/test-sourcemaps/build/test.cjs.map

+1
Original file line numberDiff line numberDiff line change

test-tap/fixture/snapshots/test-sourcemaps/build/test.js.map

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import test from '../../../../../../entrypoints/main.cjs';
1+
const test = require('../../../../../../entrypoints/main.cjs');
22
test('test title', t => {
33
t.snapshot({ foo: 'bar' });
44
t.snapshot({ answer: 43 });
55
});
66
test('another test', t => {
77
t.snapshot(new Map());
88
});
9-
//# sourceMappingURL=test.js.map
9+
//# sourceMappingURL=test.cjs.map
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": 3,
3+
"file": "test.cjs",
4+
"sourceRoot": "",
5+
"sources": [
6+
"../../src/test/test.ts"
7+
],
8+
"names": [],
9+
"mappings": "AAAA,OAAO,IAAI,MAAM,mBAAmB,CAAC;AAErC,IAAI,CAAC,YAAY,EAAE,CAAC;IACnB,CAAC,CAAC,QAAQ,CAAC,EAAC,GAAG,EAAE,KAAK,EAAC,CAAC,CAAC;IAEzB,CAAC,CAAC,QAAQ,CAAC,EAAC,MAAM,EAAE,EAAE,EAAC,CAAC,CAAC;AAC1B,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,cAAc,EAAE,CAAC;IACrB,CAAC,CAAC,QAAQ,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"
10+
}

test-tap/fixture/snapshots/test-sourcemaps/build/test/test.js.map

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"ava": {
33
"files": [
4-
"build/**/test.js"
4+
"build/**/test.cjs"
55
]
66
}
77
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"ava": {
3-
"files": ["tests/**/*.js"]
3+
"files": [
4+
"tests/**/*.cjs"
5+
]
46
}
57
}

test-tap/fixture/source-map-initial.cjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ const fixture = (0, _sourceMapFixtures.mapFile)('throws').require();
2121
t.pass();
2222
});
2323
const run = () => fixture.run();
24-
// # sourceMappingURL=./source-map-initial.js.map
25-
// Generated using node test/fixtures/_generate-source-map-initial.js
24+
// # sourceMappingURL=./source-map-initial.cjs.map
25+
// Generated using node test/fixtures/_generate-source-map-initial.cjs

test-tap/fixture/source-map-initial.cjs.map

+1-1
Original file line numberDiff line numberDiff line change

test-tap/helper/report.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import childProcess from 'child_process';
22
import fs from 'fs';
3+
import {createRequire} from 'module';
34
import path from 'path';
45
import {fileURLToPath} from 'url';
56
import workerThreads from 'worker_threads';
67

78
import globby from 'globby';
8-
import proxyquire from 'proxyquire';
99
import replaceString from 'replace-string';
1010

1111
import {normalizeGlobs} from '../../lib/globs.js';
@@ -27,8 +27,10 @@ class Worker extends workerThreads.Worker {
2727
}
2828

2929
let _Api = null;
30-
const createApi = options => {
30+
const createApi = async options => {
3131
if (!_Api) {
32+
const require = createRequire(import.meta.url);
33+
const proxyquire = require('proxyquire');
3234
_Api = proxyquire('../../lib/api', {
3335
'./fork': proxyquire('../../lib/fork', {
3436
worker_threads: { // eslint-disable-line camelcase
@@ -93,13 +95,13 @@ exports.sanitizers = {
9395
const __dirname = fileURLToPath(new URL('.', import.meta.url));
9496
exports.projectDir = type => path.join(__dirname, '../fixture/report', type.toLowerCase());
9597

96-
const run = (type, reporter, {match = [], filter} = {}) => {
98+
const run = async (type, reporter, {match = [], filter} = {}) => {
9799
const projectDir = exports.projectDir(type);
98100

99101
const providers = [{
100102
type: 'babel',
101103
level: 'ava-3',
102-
main: providerManager.babel(projectDir).main({
104+
main: (await providerManager.babel(projectDir)).main({
103105
config: {
104106
testOptions: {
105107
plugins: ['@babel/plugin-proposal-do-expressions']
@@ -128,7 +130,7 @@ const run = (type, reporter, {match = [], filter} = {}) => {
128130

129131
options.globs = normalizeGlobs({extensions: options.extensions, files: ['*'], providers: []});
130132

131-
const api = createApi(options);
133+
const api = await createApi(options);
132134
api.on('run', plan => reporter.startRun(plan));
133135

134136
const files = globby.sync('*.cjs', {

test-tap/integration/assorted.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test('timeout', t => {
3333
test('include anonymous functions in error reports', t => {
3434
execCli('error-in-anonymous-function.cjs', (err, stdout) => {
3535
t.ok(err);
36-
t.match(stdout, /error-in-anonymous-function\.js:4:8/);
36+
t.match(stdout, /error-in-anonymous-function\.cjs:4:8/);
3737
t.end();
3838
});
3939
});
@@ -146,7 +146,7 @@ test('load .mjs test files', t => {
146146
});
147147

148148
test('load .js test files as ESM modules', t => {
149-
execCli('test.cjs', {dirname: 'fixture/pkg-type-module'}, (err, stdout) => {
149+
execCli('test.js', {dirname: 'fixture/pkg-type-module'}, (err, stdout) => {
150150
t.error(err);
151151
t.match(stdout, /1 test passed/);
152152
t.end();

test-tap/integration/snapshots.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ for (const object of [
1717
{type: 'tests', rel: 'tests-dir', dir: 'tests/snapshots'}
1818
]) {
1919
test(`snapshots work (${object.type})`, t => {
20-
const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', object.rel, object.dir, 'test.js.snap');
20+
const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', object.rel, object.dir, 'test.cjs.snap');
2121
try {
2222
fs.unlinkSync(snapPath);
2323
} catch (error) {
@@ -78,7 +78,7 @@ test('two', t => {
7878
});
7979

8080
test('outdated snapshot version is reported to the console', t => {
81-
const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.js.snap');
81+
const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.cjs.snap');
8282
fs.writeFileSync(snapPath, Buffer.from([0x0A, 0x00, 0x00]));
8383

8484
execCli(['test.cjs'], {dirname: 'fixture/snapshots'}, (error, stdout) => {
@@ -92,7 +92,7 @@ test('outdated snapshot version is reported to the console', t => {
9292
});
9393

9494
test('outdated snapshot version can be updated', t => {
95-
const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.js.snap');
95+
const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.cjs.snap');
9696
fs.writeFileSync(snapPath, Buffer.from([0x0A, 0x00, 0x00]));
9797

9898
execCli(['test.cjs', '--update-snapshots'], {dirname: 'fixture/snapshots', env: {AVA_FORCE_CI: 'not-ci'}}, (error, stdout) => {
@@ -103,7 +103,7 @@ test('outdated snapshot version can be updated', t => {
103103
});
104104

105105
test('newer snapshot version is reported to the console', t => {
106-
const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.js.snap');
106+
const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.cjs.snap');
107107
fs.writeFileSync(snapPath, Buffer.from([0x0A, 0xFF, 0xFF]));
108108

109109
execCli(['test.cjs'], {dirname: 'fixture/snapshots'}, (error, stdout) => {
@@ -117,7 +117,7 @@ test('newer snapshot version is reported to the console', t => {
117117
});
118118

119119
test('snapshot corruption is reported to the console', t => {
120-
const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.js.snap');
120+
const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.cjs.snap');
121121
fs.writeFileSync(snapPath, Buffer.from([0x0A, 0x03, 0x00]));
122122

123123
execCli(['test.cjs'], {dirname: 'fixture/snapshots'}, (error, stdout) => {
@@ -131,7 +131,7 @@ test('snapshot corruption is reported to the console', t => {
131131
});
132132

133133
test('legacy snapshot files are reported to the console', t => {
134-
const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.js.snap');
134+
const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.cjs.snap');
135135
fs.writeFileSync(snapPath, Buffer.from('// Jest Snapshot v1, https://goo.gl/fbAQLP\n'));
136136

137137
execCli(['test.cjs'], {dirname: 'fixture/snapshots'}, (error, stdout) => {
@@ -203,8 +203,8 @@ test('snapshots resolved location from "snapshotDir" in AVA config', t => {
203203
.map(snapRelativeDir => {
204204
const snapPath = path.join(__dirname, '..', relativeFixtureDir, snapDir, snapRelativeDir);
205205
return [
206-
path.join(snapPath, 'test.js.md'),
207-
path.join(snapPath, 'test.js.snap')
206+
path.join(snapPath, 'test.cjs.md'),
207+
path.join(snapPath, 'test.cjs.snap')
208208
];
209209
})
210210
.reduce((a, b) => [...a, ...b], []);
@@ -278,8 +278,8 @@ test('snapshots are identical on different platforms', t => {
278278

279279
test('in CI, new snapshots are not recorded', t => {
280280
const fixtureDir = path.join(__dirname, '..', 'fixture', 'snapshots', 'test-content');
281-
const reportPath = path.join(fixtureDir, 'tests', 'snapshots', 'test.js.md');
282-
const snapPath = path.join(fixtureDir, 'tests', 'snapshots', 'test.js.snap');
281+
const reportPath = path.join(fixtureDir, 'tests', 'snapshots', 'test.cjs.md');
282+
const snapPath = path.join(fixtureDir, 'tests', 'snapshots', 'test.cjs.snap');
283283

284284
const removeFile = filePath => {
285285
try {

test-tap/integration/stack-traces.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import {execCli} from '../helper/cli.js';
55
test('`AssertionError` should capture infinity stack trace', t => {
66
execCli('infinity-stack-trace.cjs', (err, stdout) => {
77
t.ok(err);
8-
t.match(stdout, /c \(.*infinity-stack-trace\.js:6:20\)/);
9-
t.match(stdout, /b \(.*infinity-stack-trace\.js:7:18\)/);
10-
t.match(stdout, /a \(.*infinity-stack-trace\.js:8:18\)/);
11-
t.match(stdout, /.+?infinity-stack-trace\.js:10:2/);
8+
t.match(stdout, /c \(.*infinity-stack-trace\.cjs:6:20\)/);
9+
t.match(stdout, /b \(.*infinity-stack-trace\.cjs:7:18\)/);
10+
t.match(stdout, /a \(.*infinity-stack-trace\.cjs:8:18\)/);
11+
t.match(stdout, /.+?infinity-stack-trace\.cjs:10:2/);
1212
t.end();
1313
});
1414
});

0 commit comments

Comments
 (0)