From 4dcd96b8a65f9fa8af580ee27f60d2d8004409ae Mon Sep 17 00:00:00 2001 From: Raz Luvaton <16746759+rluvaton@users.noreply.github.com> Date: Wed, 5 Jul 2023 06:57:28 +0300 Subject: [PATCH] test_runner: add shards support PR-URL: https://github.com/nodejs/node/pull/48639 Reviewed-By: Moshe Atlow Reviewed-By: Benjamin Gruenbaum --- doc/api/cli.md | 22 +++ doc/api/test.md | 5 + doc/node.1 | 3 + lib/internal/main/test_runner.js | 37 ++++- lib/internal/test_runner/runner.js | 34 ++++- src/node_options.cc | 4 + src/node_options.h | 1 + test/fixtures/test-runner/shards/a.cjs | 4 + test/fixtures/test-runner/shards/b.cjs | 4 + test/fixtures/test-runner/shards/c.cjs | 4 + test/fixtures/test-runner/shards/d.cjs | 4 + test/fixtures/test-runner/shards/e.cjs | 4 + test/fixtures/test-runner/shards/f.cjs | 4 + test/fixtures/test-runner/shards/g.cjs | 4 + test/fixtures/test-runner/shards/h.cjs | 4 + test/fixtures/test-runner/shards/i.cjs | 4 + test/fixtures/test-runner/shards/j.cjs | 4 + test/parallel/test-runner-cli.js | 133 ++++++++++++++++++ test/parallel/test-runner-run.mjs | 178 +++++++++++++++++++++++++ 19 files changed, 453 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/test-runner/shards/a.cjs create mode 100644 test/fixtures/test-runner/shards/b.cjs create mode 100644 test/fixtures/test-runner/shards/c.cjs create mode 100644 test/fixtures/test-runner/shards/d.cjs create mode 100644 test/fixtures/test-runner/shards/e.cjs create mode 100644 test/fixtures/test-runner/shards/f.cjs create mode 100644 test/fixtures/test-runner/shards/g.cjs create mode 100644 test/fixtures/test-runner/shards/h.cjs create mode 100644 test/fixtures/test-runner/shards/i.cjs create mode 100644 test/fixtures/test-runner/shards/j.cjs diff --git a/doc/api/cli.md b/doc/api/cli.md index 31ed14ce2730e4..f1124ab9cdaddd 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -1289,6 +1289,27 @@ added: v18.0.0 Configures the test runner to only execute top level tests that have the `only` option set. +### `--test-shard` + + + +Test suite shard to execute in a format of `/`, where + +`index` is a positive integer, index of divided parts +`total` is a positive integer, total of divided part +This command will divide all tests files into `total` equal parts, +and will run only those that happen to be in an `index` part. + +For example, to split your tests suite into three parts, use this: + +```bash +node --test --test-shard=1/3 +node --test --test-shard=2/3 +node --test --test-shard=3/3 +``` + ### `--throw-deprecation`