Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_runner, cli: add --test-timeout flag #50443

Merged
merged 8 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 fixtures = require('../common/fixtures');
const assert = require('node:assert');
const { spawnSync } = require('node:child_process');
const { test } = require('node:test');
const cwd = fixtures.path('test-runner', 'default-behavior');
const env = { ...process.env, 'NODE_DEBUG': 'test_runner' };

test('default timeout -- Infinity', async () => {
const args = ['--test'];
const cp = spawnSync(process.execPath, args, { cwd, env });
assert.match(cp.stderr.toString(), /timeout: Infinity,/);
});

test('timeout of 10ms', async () => {
const args = ['--test', '--test-timeout', 10];
const cp = spawnSync(process.execPath, args, { cwd, env });
assert.match(cp.stderr.toString(), /timeout: 10,/);
});