Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const {
ArrayPrototypePush,
ArrayPrototypePushApply,
ArrayPrototypeShift,
ArrayPrototypeSlice,
ArrayPrototypeSome,
ArrayPrototypeSort,
MathMax,
Expand Down Expand Up @@ -185,6 +184,9 @@ function getRunArgs(path, { forceExit,
testSkipPatterns,
testTagFilterExpressions,
only,
hasFiles,
testFiles,
globPatterns,
argv: suppliedArgs,
execArgv,
rerunFailuresFilePath,
Expand Down Expand Up @@ -245,7 +247,8 @@ function getRunArgs(path, { forceExit,

if (path === kIsolatedProcessName) {
ArrayPrototypePush(runArgs, '--test');
ArrayPrototypePushApply(runArgs, ArrayPrototypeSlice(process.argv, 1));
ArrayPrototypePush(runArgs, '--test-isolation=none');
ArrayPrototypePushApply(runArgs, hasFiles ? testFiles : globPatterns ?? []);
} else {
ArrayPrototypePush(runArgs, path);
}
Expand Down Expand Up @@ -986,6 +989,7 @@ function run(options = kEmptyObject) {
workerIdPool: isolation === 'process' ? workerIdPool : null,
randomize,
randomSeed,
testFiles,
};

if (isolation === 'process') {
Expand Down
43 changes: 43 additions & 0 deletions test/test-runner/test-run-watch-cwd-isolation-none-argv.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Test run({ watch: true, cwd, isolation: 'none' }) does not reuse the
// parent process argv when spawning the watch child.
import * as common from '../common/index.mjs';
import assert from 'node:assert';
import { readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { run } from 'node:test';
import tmpdir from '../common/tmpdir.js';
import { skipIfNoWatch } from '../common/watch.js';

skipIfNoWatch();
tmpdir.refresh();

const marker = join(tmpdir.path, 'marker');
writeFileSync(join(tmpdir.path, 'test.js'), `
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this test program live as a fixture under test/fixtures/test-runner-watch/ for consistency with the other watch/cwd tests, instead of the inline template string?

const test = require('node:test');
const { writeFileSync } = require('node:fs');

test('test ran from cwd', () => {
writeFileSync(${JSON.stringify(marker)}, 'ran');
});
`);

const controller = new AbortController();
const stream = run({
cwd: tmpdir.path,
watch: true,
signal: controller.signal,
isolation: 'none',
}).on('data', function({ type }) {
if (type === 'test:watch:drained') {
stream.removeAllListeners('test:fail');
stream.removeAllListeners('test:pass');
controller.abort();
}
});

stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustCall(1));
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);

assert.strictEqual(readFileSync(marker, 'utf8'), 'ran');
Loading