Skip to content

Commit f593a7b

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

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

lib/internal/test_runner/runner.js

Lines changed: 1 addition & 0 deletions
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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -608,20 +608,14 @@ 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') {
614-
validateNumber(cliTimeout, 'options.timeout', 0, TIMEOUT_MAX);
615-
this.timeout = cliTimeout;
616-
}
611+
validateNumber(cliTimeout, 'options.timeout', 0, TIMEOUT_MAX);
612+
this.timeout = cliTimeout;
617613
}
618614

619615
// Take timeout from options
620616
if (timeout != null && timeout !== Infinity) {
621-
if (!(this.name === '<root>' && this.parent === null)) {
622-
validateNumber(timeout, 'options.timeout', 0, TIMEOUT_MAX);
623-
this.timeout = timeout;
624-
}
617+
validateNumber(timeout, 'options.timeout', 0, TIMEOUT_MAX);
618+
this.timeout = timeout;
625619
}
626620

627621
if (skip) {
@@ -1408,6 +1402,7 @@ class Suite extends Test {
14081402
reportedType = 'suite';
14091403
constructor(options) {
14101404
super(options);
1405+
this.timeout = null;
14111406

14121407
if (this.config.testNamePatterns !== null &&
14131408
this.config.testSkipPatterns !== null &&
Lines changed: 11 additions & 3 deletions
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)