Skip to content

Commit cc4e622

Browse files
committed
Assume test files import the correct AVA installation
These workarounds are too tricky to support with ESM entrypoints.
1 parent 1ee1e82 commit cc4e622

File tree

33 files changed

+34
-68
lines changed

33 files changed

+34
-68
lines changed

index.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
11
'use strict';
2-
3-
// Ensure the same AVA install is loaded by the test file as by the test worker
4-
if (process.env.AVA_PATH && process.env.AVA_PATH !== __dirname) {
5-
module.exports = require(process.env.AVA_PATH);
6-
} else {
7-
module.exports = require('./lib/worker/main');
8-
}
2+
module.exports = require('./lib/worker/main');

lib/fork.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22
const {Worker} = require('worker_threads');
33
const childProcess = require('child_process');
4-
const path = require('path');
54
const fs = require('fs');
65
const Emittery = require('emittery');
76
const {controlFlow} = require('./ipc-flow-control');
@@ -10,9 +9,6 @@ if (fs.realpathSync(__filename) !== __filename) {
109
console.warn('WARNING: `npm link ava` and the `--preserve-symlink` flag are incompatible. We have detected that AVA is linked via `npm link`, and that you are using either an early version of Node 6, or the `--preserve-symlink` flag. This breaks AVA. You should upgrade to Node 6.2.0+, avoid the `--preserve-symlink` flag, or avoid using `npm link ava`.');
1110
}
1211

13-
// In case the test file imports a different AVA install,
14-
// the presence of this variable allows it to require this one instead
15-
const AVA_PATH = path.resolve(__dirname, '..');
1612
const WORKER_PATH = require.resolve('./worker/base.js');
1713

1814
class SharedWorkerChannel extends Emittery {
@@ -67,7 +63,7 @@ const createWorker = (options, execArgv) => {
6763
if (options.workerThreads) {
6864
worker = new Worker(WORKER_PATH, {
6965
argv: options.workerArgv,
70-
env: {NODE_ENV: 'test', ...process.env, ...options.environmentVariables, AVA_PATH},
66+
env: {NODE_ENV: 'test', ...process.env, ...options.environmentVariables},
7167
execArgv,
7268
workerData: {
7369
options
@@ -89,7 +85,7 @@ const createWorker = (options, execArgv) => {
8985
worker = childProcess.fork(WORKER_PATH, options.workerArgv, {
9086
cwd: options.projectDir,
9187
silent: true,
92-
env: {NODE_ENV: 'test', ...process.env, ...options.environmentVariables, AVA_PATH},
88+
env: {NODE_ENV: 'test', ...process.env, ...options.environmentVariables},
9389
execArgv
9490
});
9591
postMessage = controlFlow(worker);

plugin.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
11
'use strict';
2-
const path = require('path');
3-
4-
// Ensure the same AVA install is loaded by the test file as by the test worker
5-
if (process.env.AVA_PATH && process.env.AVA_PATH !== __dirname) {
6-
module.exports = require(path.join(process.env.AVA_PATH, 'plugin'));
7-
} else {
8-
module.exports = require('./lib/worker/plugin');
9-
}
2+
module.exports = require('./lib/worker/plugin');

test-tap/integration/assorted.js

-18
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,6 @@ test('should warn ava is required without the cli', t => {
6666
});
6767
});
6868

69-
test('workers ensure test files load the same version of ava', t => {
70-
const target = path.join(__dirname, '..', 'fixture', 'ava-paths', 'target');
71-
72-
// Copy the index.js so the testFile imports it. It should then load the correct AVA install.
73-
const targetInstall = path.join(target, 'node_modules/ava');
74-
fs.mkdirSync(targetInstall, {recursive: true});
75-
fs.writeFileSync(
76-
path.join(targetInstall, 'index.js'),
77-
fs.readFileSync(path.join(__dirname, '../../index.js'))
78-
);
79-
80-
const testFile = path.join(target, 'test.js');
81-
execCli([testFile], {dirname: path.join('fixture', 'ava-paths', 'cwd')}, err => {
82-
t.ifError(err);
83-
t.end();
84-
});
85-
});
86-
8769
test('tests without assertions do not fail if failWithoutAssertions option is set to false', t => {
8870
execCli([], {dirname: 'fixture/pkg-conf/fail-without-assertions'}, err => {
8971
t.ifError(err);

test/helpers/exec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ exports.fixture = async (args, options = {}) => {
4444
const cwd = options.cwd || exports.cwd();
4545
const running = execa.node(cliPath, args, defaultsDeep({
4646
env: {
47-
AVA_EMIT_RUN_STATUS_OVER_IPC: 'I\'ll find a payphone baby / Take some time to talk to you'
47+
AVA_EMIT_RUN_STATUS_OVER_IPC: 'I\'ll find a payphone baby / Take some time to talk to you',
48+
TEST_AVA_IMPORT_FROM: process.cwd()
4849
},
4950
cwd,
5051
serialization: 'advanced',

test/snapshot-removal/fixtures/fixed-snapshot-dir/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
if (process.env.TEMPLATE) {
44
test('some snapshots', t => {

test/snapshot-removal/fixtures/no-snapshots/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
test('without snapshots', t => {
44
t.pass();

test/snapshot-removal/fixtures/only-test/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
if (process.env.TEMPLATE) {
44
test('some snapshots', t => {

test/snapshot-removal/fixtures/removal/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
if (process.env.TEMPLATE) {
44
test('some snapshots', t => {

test/snapshot-removal/fixtures/skipped-snapshots-in-try/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
if (process.env.TEMPLATE) {
44
test('skipped snapshots in try', async t => {

test/snapshot-removal/fixtures/skipped-snapshots/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
if (process.env.TEMPLATE) {
44
test('some snapshots', t => {

test/snapshot-removal/fixtures/skipped-tests/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
if (process.env.TEMPLATE) {
44
test('some snapshots', t => {

test/snapshot-removal/fixtures/snapshot-dir/test/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
if (process.env.TEMPLATE) {
44
test('some snapshots', t => {

test/snapshot-removal/fixtures/try/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
if (process.env.TEMPLATE) {
44
test('snapshots in try', async t => {

test/snapshot-workflow/fixtures/adding-skipped-snapshots/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

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

test/snapshot-workflow/fixtures/adding-snapshots/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

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

test/snapshot-workflow/fixtures/adding-test/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

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

test/snapshot-workflow/fixtures/changing-label/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
test('foo', t => {
44
t.snapshot({foo: 'one'}, process.env.TEMPLATE ? undefined : 'a new message');

test/snapshot-workflow/fixtures/changing-title/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
test(`a ${process.env.TEMPLATE ? '' : 'new '}title`, t => {
44
t.snapshot({foo: 'one'});

test/snapshot-workflow/fixtures/commit-skip/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
test('commit a skipped snapshot', async t => {
44
t.snapshot(1);

test/snapshot-workflow/fixtures/discard-skip/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
test('discard a skipped snapshot', async t => {
44
t.snapshot(1);

test/snapshot-workflow/fixtures/filling-in-blanks/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

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

test/snapshot-workflow/fixtures/first-run/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

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

test/snapshot-workflow/fixtures/invalid-snapfile/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

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

test/snapshot-workflow/fixtures/removing-all-snapshots/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
test('foo', t => {
44
if (process.env.TEMPLATE) {

test/snapshot-workflow/fixtures/removing-snapshots/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

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

test/snapshot-workflow/fixtures/removing-test/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

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

test/snapshot-workflow/fixtures/reorder/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
if (process.env.TEMPLATE) {
44
test('first test', t => {

test/snapshot-workflow/fixtures/select-test-update/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
test('foo', t => {
44
t.snapshot(process.env.TEMPLATE ? {foo: 'one'} : {foo: 'new'});

test/snapshot-workflow/fixtures/skipping-snapshot-update/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
test('foo', t => {
44
if (process.env.TEMPLATE) {

test/snapshot-workflow/fixtures/skipping-snapshot/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
test('foo', t => {
44
(process.env.TEMPLATE ? t.snapshot : t.snapshot.skip)({foo: 'one'});

test/snapshot-workflow/fixtures/skipping-test-update/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
(process.env.TEMPLATE ? test : test.skip)('foo', t => {
44
t.snapshot(process.env.TEMPLATE ? {foo: 'one'} : ['something new']);

test/snapshot-workflow/fixtures/skipping-test/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require(process.env.AVA_PATH); // This fixture is copied to a temporary directory, so require AVA through its configured path.
1+
const test = require(process.env.TEST_AVA_IMPORT_FROM); // This fixture is copied to a temporary directory, so require AVA through its configured path.
22

33
(process.env.TEMPLATE ? test : test.skip)('foo', t => {
44
t.snapshot({foo: 'one'});

0 commit comments

Comments
 (0)