From f1c269c3ad405f69e4da7694072bbea830385067 Mon Sep 17 00:00:00 2001 From: Pietro Marchini Date: Fri, 10 Jan 2025 18:35:58 +0100 Subject: [PATCH] test_runner: add bail out --- doc/api/cli.md | 12 +++ doc/api/test.md | 51 +++++++++ lib/internal/test_runner/harness.js | 1 + lib/internal/test_runner/reporter/spec.js | 5 +- lib/internal/test_runner/reporter/tap.js | 4 + lib/internal/test_runner/reporter/utils.js | 4 + lib/internal/test_runner/runner.js | 41 ++++++- lib/internal/test_runner/test.js | 30 +++++- lib/internal/test_runner/tests_stream.js | 9 ++ lib/internal/test_runner/utils.js | 2 + src/node_options.cc | 5 + src/node_options.h | 1 + .../test-runner/bailout/sequential.test.mjs | 12 +++ .../test-runner/bailout/suite.test.mjs | 11 ++ test/fixtures/test-runner/output/bail-spec.js | 18 ++++ .../test-runner/output/bail-spec.snapshot | 32 ++++++ test/fixtures/test-runner/output/bail-tap.js | 18 ++++ .../test-runner/output/bail-tap.snapshot | 38 +++++++ test/parallel/test-runner-bail.js | 84 +++++++++++++++ test/parallel/test-runner-output.mjs | 17 +++ test/parallel/test-runner-run.mjs | 100 ++++++++++++++++++ 21 files changed, 487 insertions(+), 8 deletions(-) create mode 100644 test/fixtures/test-runner/bailout/sequential.test.mjs create mode 100644 test/fixtures/test-runner/bailout/suite.test.mjs create mode 100644 test/fixtures/test-runner/output/bail-spec.js create mode 100644 test/fixtures/test-runner/output/bail-spec.snapshot create mode 100644 test/fixtures/test-runner/output/bail-tap.js create mode 100644 test/fixtures/test-runner/output/bail-tap.snapshot create mode 100644 test/parallel/test-runner-bail.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 46007c5b86b927..59318c7d9302c0 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -2254,6 +2254,17 @@ Starts the Node.js command line test runner. This flag cannot be combined with See the documentation on [running tests from the command line][] for more details. +### `--test-bail` + + + +> Stability: 1 - Experimental + +Instructs the test runner to bail out if a test failure occurs. +See the documentation on [test bailout][] for more details. + ### `--test-concurrency` + +> Stability: 1 - Experimental + +The `--test-bail` flag provides a way to stop test execution +as soon as a test fails. +By enabling this flag, the test runner will exit the test suite early +when it encounters the first failing test, preventing +the execution of subsequent tests. +Already running tests will be canceled, and no further tests will be started. +**Default:** `false`. + ## Test reporters