mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
test_runner: fix suite timeout
PR-URL: https://github.com/nodejs/node/pull/59853 Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
This commit is contained in:
parent
535efea962
commit
6dbf7086bb
|
|
@ -1455,7 +1455,9 @@ class Suite extends Test {
|
||||||
reportedType = 'suite';
|
reportedType = 'suite';
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super(options);
|
super(options);
|
||||||
this.timeout = null;
|
if (options.timeout == null) {
|
||||||
|
this.timeout = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.config.testNamePatterns !== null &&
|
if (this.config.testNamePatterns !== null &&
|
||||||
this.config.testSkipPatterns !== null &&
|
this.config.testSkipPatterns !== null &&
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
const { describe, it, after } = require('node:test');
|
const { describe, it, after } = require('node:test');
|
||||||
const { setTimeout } = require('node:timers');
|
const { setTimeout } = require('node:timers');
|
||||||
|
|
||||||
const timeoutRefs = [];
|
describe('--test-timeout is set to 100ms', () => {
|
||||||
|
const timeoutRefs = [];
|
||||||
|
|
||||||
describe('--test-timeout is set to 20ms', () => {
|
it('should timeout after 100ms', async () => {
|
||||||
it('should timeout after 20ms', async () => {
|
|
||||||
const { promise, resolve } = Promise.withResolvers();
|
const { promise, resolve } = Promise.withResolvers();
|
||||||
timeoutRefs.push(setTimeout(() => {
|
timeoutRefs.push(setTimeout(() => {
|
||||||
resolve();
|
resolve();
|
||||||
|
|
@ -37,3 +37,22 @@ describe('--test-timeout is set to 20ms', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('should inherit timeout options to children', { timeout: 1 }, () => {
|
||||||
|
const timeoutRefs = [];
|
||||||
|
|
||||||
|
after(() => {
|
||||||
|
for (const timeoutRef of timeoutRefs) {
|
||||||
|
clearTimeout(timeoutRef);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should timeout after 1ms', async () => {
|
||||||
|
const { promise, resolve } = Promise.withResolvers();
|
||||||
|
timeoutRefs.push(setTimeout(() => {
|
||||||
|
resolve();
|
||||||
|
}, 20000));
|
||||||
|
await promise;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
TAP version 13
|
TAP version 13
|
||||||
# Subtest: --test-timeout is set to 20ms
|
# Subtest: --test-timeout is set to 100ms
|
||||||
# Subtest: should timeout after 20ms
|
# Subtest: should timeout after 100ms
|
||||||
not ok 1 - should timeout after 20ms
|
not ok 1 - should timeout after 100ms
|
||||||
---
|
---
|
||||||
duration_ms: *
|
duration_ms: *
|
||||||
type: 'test'
|
type: 'test'
|
||||||
location: '/test/fixtures/test-runner/output/test-timeout-flag.js:(LINE):3'
|
location: '/test/fixtures/test-runner/output/test-timeout-flag.js:(LINE):3'
|
||||||
failureType: 'testTimeoutFailure'
|
failureType: 'testTimeoutFailure'
|
||||||
error: 'test timed out after 20ms'
|
error: 'test timed out after 100ms'
|
||||||
code: 'ERR_TEST_FAILURE'
|
code: 'ERR_TEST_FAILURE'
|
||||||
stack: |-
|
stack: |-
|
||||||
async Promise.all (index 0)
|
async Promise.all (index 0)
|
||||||
|
|
@ -35,7 +35,7 @@ TAP version 13
|
||||||
type: 'test'
|
type: 'test'
|
||||||
...
|
...
|
||||||
1..4
|
1..4
|
||||||
not ok 1 - --test-timeout is set to 20ms
|
not ok 1 - --test-timeout is set to 100ms
|
||||||
---
|
---
|
||||||
duration_ms: *
|
duration_ms: *
|
||||||
type: 'suite'
|
type: 'suite'
|
||||||
|
|
@ -44,12 +44,33 @@ not ok 1 - --test-timeout is set to 20ms
|
||||||
error: '2 subtests failed'
|
error: '2 subtests failed'
|
||||||
code: 'ERR_TEST_FAILURE'
|
code: 'ERR_TEST_FAILURE'
|
||||||
...
|
...
|
||||||
1..1
|
# Subtest: should inherit timeout options to children
|
||||||
# tests 4
|
# Subtest: should timeout after 1ms
|
||||||
# suites 1
|
not ok 1 - should timeout after 1ms
|
||||||
|
---
|
||||||
|
duration_ms: *
|
||||||
|
type: 'test'
|
||||||
|
location: '/test/fixtures/test-runner/output/test-timeout-flag.js:(LINE):3'
|
||||||
|
failureType: 'cancelledByParent'
|
||||||
|
error: 'test did not finish before its parent and was cancelled'
|
||||||
|
code: 'ERR_TEST_FAILURE'
|
||||||
|
...
|
||||||
|
1..1
|
||||||
|
not ok 2 - should inherit timeout options to children
|
||||||
|
---
|
||||||
|
duration_ms: *
|
||||||
|
type: 'suite'
|
||||||
|
location: '/test/fixtures/test-runner/output/test-timeout-flag.js:(LINE):1'
|
||||||
|
failureType: 'testTimeoutFailure'
|
||||||
|
error: 'test timed out after 1ms'
|
||||||
|
code: 'ERR_TEST_FAILURE'
|
||||||
|
...
|
||||||
|
1..2
|
||||||
|
# tests 5
|
||||||
|
# suites 2
|
||||||
# pass 2
|
# pass 2
|
||||||
# fail 0
|
# fail 0
|
||||||
# cancelled 2
|
# cancelled 3
|
||||||
# skipped 0
|
# skipped 0
|
||||||
# todo 0
|
# todo 0
|
||||||
# duration_ms *
|
# duration_ms *
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ const tests = [
|
||||||
name: 'test-runner/output/test-timeout-flag.js',
|
name: 'test-runner/output/test-timeout-flag.js',
|
||||||
flags: [
|
flags: [
|
||||||
'--test-reporter=tap',
|
'--test-reporter=tap',
|
||||||
'--test-timeout=20',
|
'--test-timeout=100',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
// --test-timeout should work with or without --test flag
|
// --test-timeout should work with or without --test flag
|
||||||
|
|
@ -145,7 +145,7 @@ const tests = [
|
||||||
name: 'test-runner/output/test-timeout-flag.js',
|
name: 'test-runner/output/test-timeout-flag.js',
|
||||||
flags: [
|
flags: [
|
||||||
'--test-reporter=tap',
|
'--test-reporter=tap',
|
||||||
'--test-timeout=20',
|
'--test-timeout=100',
|
||||||
'--test',
|
'--test',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user