-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add --only-failures flag to bun:test #23312
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
Open
robobun
wants to merge
9
commits into
main
Choose a base branch
from
claude/add-only-failures-flag
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ebecc68
Add --only-failures flag to bun:test
d932169
Update --only-failures help text to not reference --dots
f43bbdd
Merge remote-tracking branch 'origin/main' into claude/add-only-failu…
pfgithub 2fb53fa
fix it
pfgithub 91b7c67
default only_failures to isAIAgent
pfgithub 093feed
bunfig
pfgithub 7940ccf
docs & test
pfgithub 3f0d49d
Merge remote-tracking branch 'origin/main' into claude/add-only-failu…
pfgithub b28d83c
Merge branch 'main' into claude/add-only-failures-flag
pfgithub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { expect, test } from "bun:test"; | ||
|
||
test("passing test 1", () => { | ||
expect(1 + 1).toBe(2); | ||
}); | ||
|
||
test("passing test 2", () => { | ||
expect(2 + 2).toBe(4); | ||
}); | ||
|
||
test("failing test", () => { | ||
expect(1 + 1).toBe(3); | ||
}); | ||
|
||
test("passing test 3", () => { | ||
expect(3 + 3).toBe(6); | ||
}); | ||
|
||
test.skip("skipped test", () => { | ||
expect(true).toBe(false); | ||
}); | ||
|
||
test.todo("todo test"); | ||
|
||
test("another failing test", () => { | ||
throw new Error("This test fails"); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { expect, test } from "bun:test"; | ||
import { bunEnv, bunExe, normalizeBunSnapshot, tempDir } from "harness"; | ||
|
||
test.concurrent("only-failures flag should show only failures", async () => { | ||
const result = await Bun.spawn({ | ||
cmd: [bunExe(), "test", import.meta.dir + "/only-failures.fixture.ts", "--only-failures"], | ||
stdout: "pipe", | ||
stderr: "pipe", | ||
env: bunEnv, | ||
}); | ||
const exitCode = await result.exited; | ||
const stdout = await result.stdout.text(); | ||
const stderr = await result.stderr.text(); | ||
expect({ | ||
exitCode, | ||
stdout: normalizeBunSnapshot(stdout), | ||
stderr: normalizeBunSnapshot(stderr), | ||
}).toMatchInlineSnapshot(` | ||
{ | ||
"exitCode": 1, | ||
"stderr": | ||
"test/js/bun/test/only-failures.fixture.ts: | ||
7 | test("passing test 2", () => { | ||
8 | expect(2 + 2).toBe(4); | ||
9 | }); | ||
10 | | ||
11 | test("failing test", () => { | ||
12 | expect(1 + 1).toBe(3); | ||
^ | ||
error: expect(received).toBe(expected) | ||
|
||
Expected: 3 | ||
Received: 2 | ||
at <anonymous> (file:NN:NN) | ||
(fail) failing test | ||
21 | }); | ||
22 | | ||
23 | test.todo("todo test"); | ||
24 | | ||
25 | test("another failing test", () => { | ||
26 | throw new Error("This test fails"); | ||
^ | ||
error: This test fails | ||
at <anonymous> (file:NN:NN) | ||
(fail) another failing test | ||
|
||
3 pass | ||
1 skip | ||
1 todo | ||
2 fail | ||
4 expect() calls | ||
Ran 7 tests across 1 file." | ||
, | ||
"stdout": "bun test <version> (<revision>)", | ||
} | ||
`); | ||
}); | ||
|
||
test.concurrent("only-failures flag should work with multiple files", async () => { | ||
const result = await Bun.spawn({ | ||
cmd: [ | ||
bunExe(), | ||
"test", | ||
import.meta.dir + "/printing/dots/dots1.fixture.ts", | ||
import.meta.dir + "/only-failures.fixture.ts", | ||
"--only-failures", | ||
], | ||
stdout: "pipe", | ||
stderr: "pipe", | ||
env: bunEnv, | ||
}); | ||
const exitCode = await result.exited; | ||
const stdout = await result.stdout.text(); | ||
const stderr = await result.stderr.text(); | ||
expect(exitCode).toBe(1); | ||
expect(normalizeBunSnapshot(stderr)).toContain("(fail) failing test"); | ||
expect(normalizeBunSnapshot(stderr)).toContain("(fail) another failing test"); | ||
expect(normalizeBunSnapshot(stderr)).not.toContain("(pass)"); | ||
}); | ||
|
||
test.concurrent("only-failures should work via bunfig.toml", async () => { | ||
using dir = tempDir("bunfig-only-failures", { | ||
"bunfig.toml": ` | ||
[test] | ||
onlyFailures = true | ||
`, | ||
"my.test.ts": ` | ||
import { test, expect } from "bun:test"; | ||
|
||
test("passing test", () => { | ||
expect(1 + 1).toBe(2); | ||
}); | ||
|
||
test("failing test", () => { | ||
expect(1 + 1).toBe(3); | ||
}); | ||
|
||
test("another passing test", () => { | ||
expect(true).toBe(true); | ||
}); | ||
`, | ||
}); | ||
|
||
const result = await Bun.spawn({ | ||
cmd: [bunExe(), "test"], | ||
stdout: "pipe", | ||
stderr: "pipe", | ||
env: bunEnv, | ||
cwd: String(dir), | ||
}); | ||
|
||
const exitCode = await result.exited; | ||
const stderr = await result.stderr.text(); | ||
|
||
expect(exitCode).toBe(1); | ||
// Should only show the failing test | ||
expect(normalizeBunSnapshot(stderr, dir)).toContain("(fail) failing test"); | ||
// Should not show passing tests | ||
expect(normalizeBunSnapshot(stderr, dir)).not.toContain("(pass)"); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Document the interaction with dots reporter.
While this documentation is clear, consider adding a note about the behavior when
test.onlyFailures
is used alongsidetest.reporter.dots
. Based on the code in test_command.zig, when both are enabled, dots are printed for passing tests and full output is shown for failures. This interaction should be documented to avoid user confusion.Apply this diff to clarify the interaction:
This is equivalent to using the
--only-failures
flag when runningbun test
.+
+Note: When combined with
test.reporter.dots
, passing tests will display as dots while failures show full output.In docs/runtime/bunfig.md around lines 252 to 261, the docs for
test.onlyFailures lack a note about how it interacts with test.reporter.dots;
add a short sentence after the existing paragraph that states: "Note: When
combined with test.reporter.dots, passing tests will display as dots while
failures show full output." so users understand that dots are still printed for
passes and full failure output is shown.