Skip to content

Commit 250ef6d

Browse files
committed
address PR comments
1 parent 180116b commit 250ef6d

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

lib/internal/test_runner/harness.js

-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ function lazyBootstrapRoot() {
272272
};
273273
const globalOptions = parseCommandLine();
274274
globalOptions.cwd = process.cwd();
275-
globalOptions.timeout = Infinity;
276275
createTestTree(rootTestOptions, globalOptions);
277276
globalRoot.reporter.on('test:summary', (data) => {
278277
if (!data.success) {

lib/internal/test_runner/test.js

+17-14
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,23 @@ class Test extends AsyncResource {
605605
throw new ERR_INVALID_ARG_TYPE('options.concurrency', ['boolean', 'number'], concurrency);
606606
}
607607

608+
// Take timeout from cli
609+
const cliTimeout = this.config.timeout;
610+
if (cliTimeout != null && cliTimeout !== Infinity) {
611+
if (!(this.name === '<root>' && this.parent === null) &&
612+
this.constructor.name !== 'FileTest' &&
613+
this.constructor.name !== 'Suite') {
614+
validateNumber(cliTimeout, 'options.timeout', 0, TIMEOUT_MAX);
615+
this.timeout = cliTimeout;
616+
}
617+
}
618+
619+
// Take timeout from options
608620
if (timeout != null && timeout !== Infinity) {
609-
validateNumber(timeout, 'options.timeout', 0, TIMEOUT_MAX);
610-
this.timeout = timeout;
621+
if (!(this.name === '<root>' && this.parent === null)) {
622+
validateNumber(timeout, 'options.timeout', 0, TIMEOUT_MAX);
623+
this.timeout = timeout;
624+
}
611625
}
612626

613627
if (skip) {
@@ -788,8 +802,6 @@ class Test extends AsyncResource {
788802
}
789803

790804
createSubtest(Factory, name, options, fn, overrides) {
791-
const timeoutPerTest = this.config.timeoutPerTest;
792-
793805
if (typeof name === 'function') {
794806
fn = name;
795807
} else if (name !== null && typeof name === 'object') {
@@ -799,18 +811,9 @@ class Test extends AsyncResource {
799811
fn = options;
800812
}
801813

802-
if (options !== null && typeof options === 'object') {
803-
if (this.childNumber > 0 && options.timeout === undefined && timeoutPerTest !== Infinity) {
804-
options.timeout = timeoutPerTest;
805-
}
806-
}
807814

808815
if (options === null || typeof options !== 'object') {
809-
if (this.childNumber > 0 && timeoutPerTest !== Infinity) {
810-
options = { __proto__: null, timeout: timeoutPerTest };
811-
} else {
812-
options = kEmptyObject;
813-
}
816+
options = kEmptyObject;
814817
}
815818

816819
let parent = this;

lib/internal/test_runner/utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ function parseCommandLine() {
196196
const sourceMaps = getOptionValue('--enable-source-maps');
197197
const updateSnapshots = getOptionValue('--test-update-snapshots');
198198
const watch = getOptionValue('--watch');
199-
const timeoutPerTest = getOptionValue('--test-timeout') || Infinity;
199+
const timeout = getOptionValue('--test-timeout') || Infinity;
200200
const isChildProcess = process.env.NODE_TEST_CONTEXT === 'child';
201201
const isChildProcessV8 = process.env.NODE_TEST_CONTEXT === 'child-v8';
202202
let concurrency;
@@ -332,7 +332,7 @@ function parseCommandLine() {
332332
sourceMaps,
333333
testNamePatterns,
334334
testSkipPatterns,
335-
timeoutPerTest,
335+
timeout,
336336
updateSnapshots,
337337
watch,
338338
};

test/fixtures/test-runner/output/test-timeout-flag.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ const { setTimeout } = require('node:timers/promises');
55

66
describe('--test-timeout is set to 20ms', () => {
77
test('should timeout after 20ms', async () => {
8-
await setTimeout(100);
8+
await setTimeout(2000);
99
});
1010
test('should timeout after 5ms', { timeout: 5 }, async () => {
11-
await setTimeout(100);
11+
await setTimeout(2000);
1212
});
13-
test('should not timeout', { timeout: 50 }, async () => {
14-
await setTimeout(25);
15-
});
16-
test('should pass', async () => {
17-
await setTimeout(10);
13+
test('should not timeout', { timeout: 5000 }, async () => {
14+
await setTimeout(200);
1815
});
16+
test('should pass', async () => {});
1917
});

test/parallel/test-runner-cli-timeout.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ const env = { ...process.env, 'NODE_DEBUG': 'test_runner' };
1010
test('default timeout -- Infinity', async () => {
1111
const args = ['--test'];
1212
const cp = spawnSync(process.execPath, args, { cwd, env });
13-
assert.match(cp.stderr.toString(), /timeoutPerTest: Infinity/);
13+
assert.match(cp.stderr.toString(), /timeout: Infinity/);
1414
});
1515

1616
test('timeout of 10ms', async () => {
1717
const args = ['--test', '--test-timeout', 10];
1818
const cp = spawnSync(process.execPath, args, { cwd, env });
19-
assert.match(cp.stderr.toString(), /timeoutPerTest: 10/);
19+
assert.match(cp.stderr.toString(), /timeout: 10/);
2020
});
2121

2222
test('isolation=none uses the --test-timeout flag', async () => {
2323
const args = [
2424
'--test', '--test-isolation=none', '--test-timeout=10',
2525
];
2626
const cp = spawnSync(process.execPath, args, { cwd, env });
27-
assert.match(cp.stderr.toString(), /timeoutPerTest: 10/);
27+
assert.match(cp.stderr.toString(), /timeout: 10/);
2828
});

0 commit comments

Comments
 (0)