From 099b5e430c68302baba46627139b5dfd49b6a0bb Mon Sep 17 00:00:00 2001 From: Alistair Smith Date: Tue, 10 Feb 2026 10:58:21 -0800 Subject: [PATCH] feat(test): add --retry flag and emit separate testcase entries for retries in JUnit XML (#26866) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### (Copies commits from #26447) ## Summary - Add a global `--retry ` flag to `bun test` that sets a default retry count for all tests (overridable by per-test `{ retry: N }`). Also configurable via `[test] retry = N` in bunfig.toml. - When a test passes after one or more retries, the JUnit XML reporter emits a separate `` entry for each failed attempt (with ``), followed by the final passing ``. This gives flaky test detection tools per-attempt timing and result data using standard JUnit XML that all CI systems can parse. ## Test plan - `bun bd test test/js/junit-reporter/junit.test.js` — verifies separate `` entries appear in JUnit XML for tests that pass after retry - `bun bd test test/cli/test/retry-flag.test.ts` — verifies the `--retry` CLI flag applies a default retry count to all tests ## Changelog - Added `--retry ` flag to `bun test` to set a default retry count for all tests - Added `[test] retry` option to bunfig.toml - JUnit XML reporter now emits separate `` entries for each retry attempt, providing CI visibility into flaky tests --------- Co-authored-by: Chris Lloyd Co-authored-by: Claude Opus 4.5 --- completions/bun-cli.json | 111 +++------- completions/bun.zsh | 1 + docs/runtime/bunfig.mdx | 11 + docs/snippets/cli/test.mdx | 5 + docs/test/configuration.mdx | 11 + docs/test/index.mdx | 29 +++ src/bun.js/test/Execution.zig | 27 ++- src/bun.js/test/ScopeFunctions.zig | 15 +- src/bunfig.zig | 13 ++ src/cli.zig | 1 + src/cli/Arguments.zig | 13 ++ src/cli/test_command.zig | 3 + test/cli/test/retry-flag.test.ts | 315 +++++++++++++++++++++++++++ test/js/junit-reporter/junit.test.js | 47 ++++ 14 files changed, 516 insertions(+), 86 deletions(-) create mode 100644 test/cli/test/retry-flag.test.ts diff --git a/completions/bun-cli.json b/completions/bun-cli.json index b10180517a..265b1ea2dc 100644 --- a/completions/bun-cli.json +++ b/completions/bun-cli.json @@ -20,12 +20,7 @@ "completionType": "javascript_files" } ], - "examples": [ - "bun run ./index.js", - "bun run ./index.tsx", - "bun run dev", - "bun run lint" - ], + "examples": ["bun run ./index.js", "bun run ./index.tsx", "bun run dev", "bun run lint"], "usage": "Usage: bun run [flags] ", "documentationUrl": "https://bun.com/docs/cli/run", "dynamicCompletions": { @@ -63,6 +58,14 @@ "required": false, "multiple": false }, + { + "name": "retry", + "description": "Default retry count for all tests, overridden by per-test { retry: N }", + "hasValue": true, + "valueType": "val", + "required": false, + "multiple": false + }, { "name": "only", "description": "Only run tests that are marked with \"test.only()\"", @@ -152,11 +155,7 @@ "completionType": "test_files" } ], - "examples": [ - "bun test", - "bun test foo bar", - "bun test --test-name-pattern baz" - ], + "examples": ["bun test", "bun test foo bar", "bun test --test-name-pattern baz"], "usage": "Usage: bun test [flags] []", "documentationUrl": "https://bun.com/docs/cli/test", "dynamicCompletions": { @@ -199,9 +198,7 @@ "examples": [], "usage": "Usage: bunx [flags] <@version> [flags and arguments for the package]", "dynamicCompletions": {}, - "aliases": [ - "bunx" - ] + "aliases": ["bunx"] }, "repl": { "name": "repl", @@ -232,10 +229,7 @@ "completionType": "script" } ], - "examples": [ - "bun exec \"echo hi\"", - "bun exec \"echo \\\"hey friends\\\"!\"" - ], + "examples": ["bun exec \"echo hi\"", "bun exec \"echo \\\"hey friends\\\"!\""], "usage": "Usage: bun exec