From 28c4e699663484430ba16c639d9760c6c2679795 Mon Sep 17 00:00:00 2001 From: Pietro Marchini Date: Sat, 18 Jan 2025 14:30:27 +0100 Subject: [PATCH 01/17] 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 da2506326fc5bd..b4e34a36f0478c 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -2275,6 +2275,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