Skip to content

Commit 842dc01

Browse files
shubham9411UlisesGascon
authored andcommitted
test_runner, cli: add --test-timeout flag
PR-URL: #50443 Fixes: #50431 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Raz Luvaton <[email protected]> Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 4349790 commit 842dc01

File tree

6 files changed

+39
-0
lines changed

6 files changed

+39
-0
lines changed

doc/api/cli.md

+9
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,15 @@ node --test --test-shard=2/3
17431743
node --test --test-shard=3/3
17441744
```
17451745

1746+
### `--test-timeout`
1747+
1748+
<!-- YAML
1749+
added: REPLACEME
1750+
-->
1751+
1752+
A number of milliseconds the test execution will fail after. If unspecified,
1753+
subtests inherit this value from their parent. The default value is `Infinity`.
1754+
17461755
### `--throw-deprecation`
17471756

17481757
<!-- YAML

doc/node.1

+3
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ option set.
438438
.
439439
.It Fl -test-shard
440440
Test suite shard to execute in a format of <index>/<total>.
441+
442+
.It Fl -test-timeout
443+
A number of milliseconds the test execution will fail after.
441444
.
442445
.It Fl -throw-deprecation
443446
Throw errors for deprecations.

lib/internal/main/test_runner.js

+3
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,14 @@ if (shardOption) {
6060
};
6161
}
6262

63+
const timeout = getOptionValue('--test-timeout') || Infinity;
64+
6365
const options = {
6466
concurrency,
6567
inspectPort,
6668
watch: getOptionValue('--watch'),
6769
setup: setupTestReporters,
70+
timeout,
6871
shard,
6972
};
7073
debug('test runner configuration:', options);

src/node_options.cc

+3
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,9 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
603603
AddOption("--test-concurrency",
604604
"specify test runner concurrency",
605605
&EnvironmentOptions::test_runner_concurrency);
606+
AddOption("--test-timeout",
607+
"specify test runner timeout",
608+
&EnvironmentOptions::test_runner_timeout);
606609
AddOption("--experimental-test-coverage",
607610
"enable code coverage in the test runner",
608611
&EnvironmentOptions::test_runner_coverage);

src/node_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class EnvironmentOptions : public Options {
161161
bool has_env_file_string = false;
162162
bool test_runner = false;
163163
uint64_t test_runner_concurrency = 0;
164+
uint64_t test_runner_timeout = 0;
164165
bool test_runner_coverage = false;
165166
std::vector<std::string> test_name_pattern;
166167
std::vector<std::string> test_reporter;
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
require('../common');
3+
const fixtures = require('../common/fixtures');
4+
const assert = require('node:assert');
5+
const { spawnSync } = require('node:child_process');
6+
const { test } = require('node:test');
7+
const cwd = fixtures.path('test-runner', 'default-behavior');
8+
const env = { ...process.env, 'NODE_DEBUG': 'test_runner' };
9+
10+
test('default timeout -- Infinity', async () => {
11+
const args = ['--test'];
12+
const cp = spawnSync(process.execPath, args, { cwd, env });
13+
assert.match(cp.stderr.toString(), /timeout: Infinity,/);
14+
});
15+
16+
test('timeout of 10ms', async () => {
17+
const args = ['--test', '--test-timeout', 10];
18+
const cp = spawnSync(process.execPath, args, { cwd, env });
19+
assert.match(cp.stderr.toString(), /timeout: 10,/);
20+
});

0 commit comments

Comments
 (0)