Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
test_runner: remove cwd option
  • Loading branch information
pmarchini committed Aug 26, 2024
commit 67f8998f508ef584e0f88694e10dbc4bba36715b
6 changes: 0 additions & 6 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -1247,9 +1247,6 @@ added:
- v18.9.0
- v16.19.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/54225
description: Added the `cwd` option.
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/53927
description: Added the `isolation` option.
Expand Down Expand Up @@ -1277,9 +1274,6 @@ changes:
parallel.
If `false`, it would only run one test file at a time.
**Default:** `false`.
* `cwd`: {string} Specifies the current working directory to be used by the test runner.
The cwd serves as the base path for resolving files according to the [test runner execution model][].
**Default:** `process.cwd()`.
* `files`: {Array} An array containing the list of files to run.
**Default** matching files from [test runner execution model][].
* `forceExit`: {boolean} Configures the test runner to exit the process once
Expand Down
7 changes: 3 additions & 4 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const {
validateObject,
validateOneOf,
validateInteger,
validateString,
} = require('internal/validators');
const { getInspectPort, isUsingInspector, isInspectorMessage } = require('internal/util/inspector');
const { isRegExp } = require('internal/util/types');
Expand Down Expand Up @@ -537,7 +536,6 @@ function run(options = kEmptyObject) {
setup,
only,
globPatterns,
cwd = process.cwd(),
} = options;

if (files != null) {
Expand All @@ -562,8 +560,6 @@ function run(options = kEmptyObject) {
validateArray(globPatterns, 'options.globPatterns');
}

validateString(cwd, 'options.cwd');

if (globPatterns?.length > 0 && files?.length > 0) {
throw new ERR_INVALID_ARG_VALUE(
'options.globPatterns', globPatterns, 'is not supported when specifying \'options.files\'',
Expand Down Expand Up @@ -629,6 +625,9 @@ function run(options = kEmptyObject) {
};
const root = createTestTree(rootTestOptions, globalOptions);

// This const should be replaced by a run option in the future.
const cwd = process.cwd();

let testFiles = files ?? createTestFileList(globPatterns, cwd);

if (shard) {
Expand Down
34 changes: 0 additions & 34 deletions test/parallel/test-runner-run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,6 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
});
});

it('should only allow a string in options.cwd', async () => {
[Symbol(), {}, [], () => {}, 0, 1, 0n, 1n, true, false]
.forEach((cwd) => assert.throws(() => run({ cwd }), {
code: 'ERR_INVALID_ARG_TYPE'
}));
});

it('should only allow object as options', () => {
[Symbol(), [], () => {}, 0, 1, 0n, 1n, '', '1', true, false]
.forEach((options) => assert.throws(() => run(options), {
Expand Down Expand Up @@ -520,33 +513,6 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
for await (const _ of stream);
assert.match(stderr, /Warning: node:test run\(\) is being called recursively/);
});

it('should run with different cwd', async () => {
const stream = run({
cwd: fixtures.path('test-runner', 'cwd')
});
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);
});

it('should run with different cwd while in watch mode', async () => {
const controller = new AbortController();
const stream = run({
cwd: fixtures.path('test-runner', 'cwd'),
watch: true,
signal: controller.signal,
}).on('data', function({ type }) {
if (type === 'test:watch:drained') {
controller.abort();
}
});

stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustCall(1));
});
});

describe('forceExit', () => {
Expand Down