Skip to content

Commit 1f2245c

Browse files
committed
remove deuplicated if checks and move this.timeout into FileTest and Suite, unref timeout
1 parent af2201e commit 1f2245c

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

lib/internal/test_runner/runner.js

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ class FileTest extends Test {
191191
column: 1,
192192
file: resolve(this.name),
193193
};
194+
this.timeout = null;
194195
}
195196

196197
#skipReporting() {

lib/internal/test_runner/test.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -608,20 +608,16 @@ class Test extends AsyncResource {
608608
// Take timeout from cli
609609
const cliTimeout = this.config.timeout;
610610
if (cliTimeout != null && cliTimeout !== Infinity) {
611-
if (!(this.name === '<root>' && this.parent === null) &&
612-
this.constructor.name !== 'FileTest' &&
613-
this.constructor.name !== 'Suite') {
614611
validateNumber(cliTimeout, 'options.timeout', 0, TIMEOUT_MAX);
615612
this.timeout = cliTimeout;
616-
}
613+
// }
617614
}
618615

619616
// Take timeout from options
620617
if (timeout != null && timeout !== Infinity) {
621-
if (!(this.name === '<root>' && this.parent === null)) {
622618
validateNumber(timeout, 'options.timeout', 0, TIMEOUT_MAX);
623619
this.timeout = timeout;
624-
}
620+
// }
625621
}
626622

627623
if (skip) {
@@ -1408,6 +1404,7 @@ class Suite extends Test {
14081404
reportedType = 'suite';
14091405
constructor(options) {
14101406
super(options);
1407+
this.timeout = null;
14111408

14121409
if (this.config.testNamePatterns !== null &&
14131410
this.config.testSkipPatterns !== null &&
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
// Flags: --test-timeout=20
22
'use strict';
3-
const { describe, test } = require('node:test');
3+
const { describe, test, afterEach } = require('node:test');
44
const { setTimeout } = require('node:timers/promises');
55

6+
let timeout;
7+
68
describe('--test-timeout is set to 20ms', () => {
79
test('should timeout after 20ms', async () => {
8-
await setTimeout(2000);
10+
timeout = await setTimeout(2000);
911
});
1012
test('should timeout after 5ms', { timeout: 5 }, async () => {
11-
await setTimeout(2000);
13+
timeout = await setTimeout(2000);
1214
});
1315
test('should not timeout', { timeout: 5000 }, async () => {
1416
await setTimeout(200);
1517
});
1618
test('should pass', async () => {});
19+
20+
afterEach(() => {
21+
if (timeout) {
22+
timeout.unref();
23+
}
24+
})
1725
});

0 commit comments

Comments
 (0)