Skip to content

Commit f554872

Browse files
committed
fixup! address more comments
1 parent 24a1936 commit f554872

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

lib/internal/test_runner/test.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -605,17 +605,15 @@ 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-
validateNumber(cliTimeout, 'options.timeout', 0, TIMEOUT_MAX);
612-
this.timeout = cliTimeout;
613-
}
614-
615-
// Take timeout from options
616608
if (timeout != null && timeout !== Infinity) {
617609
validateNumber(timeout, 'options.timeout', 0, TIMEOUT_MAX);
618610
this.timeout = timeout;
611+
} else {
612+
const cliTimeout = this.config.timeout;
613+
if (cliTimeout != null && cliTimeout !== Infinity) {
614+
validateNumber(cliTimeout, 'options.timeout', 0, TIMEOUT_MAX);
615+
this.timeout = cliTimeout;
616+
}
619617
}
620618

621619
if (skip) {
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
// Flags: --test-timeout=20
22
'use strict';
3-
const { describe, test, afterEach } = require('node:test');
4-
const { setTimeout } = require('node:timers/promises');
5-
6-
let timeout;
3+
const { describe, test } = require('node:test');
74

85
describe('--test-timeout is set to 20ms', () => {
96
test('should timeout after 20ms', async () => {
10-
timeout = await setTimeout(2000);
7+
await new Promise(resolve => {
8+
const timeout = setTimeout(resolve, 200000);
9+
timeout.unref();
10+
});
1111
});
1212
test('should timeout after 5ms', { timeout: 5 }, async () => {
13-
timeout = await setTimeout(2000);
14-
});
15-
test('should not timeout', { timeout: 5000 }, async () => {
16-
await setTimeout(200);
13+
await new Promise(resolve => {
14+
const timeout = setTimeout(resolve, 200000);
15+
timeout.unref();
16+
});
1717
});
18-
test('should pass', async () => {});
19-
20-
afterEach(() => {
21-
if (timeout) {
18+
test('should not timeout', { timeout: 50000 }, async () => {
19+
await new Promise(resolve => {
20+
const timeout = setTimeout(resolve, 200);
2221
timeout.unref();
23-
}
22+
});
2423
});
24+
test('should pass', async () => {});
2525
});

0 commit comments

Comments
 (0)