Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,15 @@ node --test --test-shard=2/3
node --test --test-shard=3/3
```

### `--test-timeout`

<!-- YAML
added: REPLACEME
-->

A number of milliseconds the test execution will fail after. If unspecified,
subtests inherit this value from their parent. The default value is `Infinity`.

### `--throw-deprecation`

<!-- YAML
Expand Down
3 changes: 3 additions & 0 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ option set.
.
.It Fl -test-shard
Test suite shard to execute in a format of <index>/<total>.

.It Fl -test-timeout
A number of milliseconds the test execution will fail after.
.
.It Fl -throw-deprecation
Throw errors for deprecations.
Expand Down
3 changes: 3 additions & 0 deletions lib/internal/main/test_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ if (shardOption) {
};
}

const timeout = getOptionValue('--test-timeout') || Infinity;

const options = {
concurrency,
inspectPort,
watch: getOptionValue('--watch'),
setup: setupTestReporters,
timeout,
shard,
};
debug('test runner configuration:', options);
Expand Down
3 changes: 3 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,9 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
AddOption("--test-concurrency",
"specify test runner concurrency",
&EnvironmentOptions::test_runner_concurrency);
AddOption("--test-timeout",
"specify test runner timeout",
&EnvironmentOptions::test_runner_timeout);
AddOption("--experimental-test-coverage",
"enable code coverage in the test runner",
&EnvironmentOptions::test_runner_coverage);
Expand Down
1 change: 1 addition & 0 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class EnvironmentOptions : public Options {
bool has_env_file_string = false;
bool test_runner = false;
uint64_t test_runner_concurrency = 0;
uint64_t test_runner_timeout = 0;
bool test_runner_coverage = false;
std::vector<std::string> test_name_pattern;
std::vector<std::string> test_reporter;
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-runner-cli-timeout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
require('../common');
const assert = require('node:assert');
const { spawnSync } = require('node:child_process');
const { test } = require('node:test');

test('test-timeout flag', () => {
const args = ['--test', '--test-timeout', 10, 'test/fixtures/test-runner/never_ending_sync.js'];
const child = spawnSync(process.execPath, args, { timeout: 500 });

assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
assert.strictEqual(child.stderr.toString(), '');
const stdout = child.stdout.toString();
assert.match(stdout, /not ok 1 - test/);
assert.match(stdout, / {2}---/);
assert.match(stdout, / {2}duration_ms: .*/);
assert.match(stdout, /failureType: 'testTimeoutFailure/);
assert.match(stdout, /error: 'test timed out after 10ms'/);
});