Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/runtime/test_runner/bun_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,7 @@ pub struct BaseScope {
pub(crate) has_callback: bool,
/// this value is 0 unless the debugger is active and the scope has a debugger id
pub(crate) test_id_for_debugger: i32,
/// only available if using junit reporter, otherwise 0
/// only captured when the junit reporter or the inspector is enabled, otherwise 0
pub(crate) line_no: u32,
}
impl BaseScope {
Expand Down
5 changes: 4 additions & 1 deletion src/runtime/test_runner/jest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,10 @@ pub(crate) fn format_label(

pub(crate) fn capture_test_line_number(callframe: &CallFrame, global_this: &JSGlobalObject) -> u32 {
if let Some(runner) = Jest::runner() {
if runner.test_options.reporters.junit {
// The stored line is consumed by the JUnit reporter and by the
// inspector's retroactive `TestReporter.found` walk (which runs after
// the call frame is gone). Skip the stack walk when neither needs it.
Comment thread
robobun marked this conversation as resolved.
Resolved
if runner.test_options.reporters.junit || global_this.bun_vm().is_inspector_enabled() {
unsafe extern "C" {
fn Bun__CallFrame__getLineNumber(
callframe: *const CallFrame,
Expand Down
14 changes: 14 additions & 0 deletions test/cli/inspect/test-reporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,20 @@ afterAll(async () => {
const describeNames = describes.map(d => d.name).sort();
expect(describeNames).toEqual(["suite A", "suite B"]);

// Retroactively reported tests must carry real source locations, the same
// as tests reported live during collection. The retroactive path reads the
// stored line number, which previously was only captured for the JUnit
// reporter and otherwise left at 0.
for (const t of testsArray) {
expect(t.url).toEndWith("delayed.test.ts");
expect(t.line).toBeGreaterThan(0);
}
// Spot-check an exact line to catch off-by-one regressions. "test A1" is on
// line 6 of delayed.test.ts (leading newline in the template literal makes
// the import on line 2).
const testA1 = tests.find(t => t.name === "test A1");
expect(testA1?.line).toBe(6);

// Receiving the retroactive `found` events proves TestReporter.enable has been
// processed on the JS thread. Release A1 so its `end` event fires with the agent
// enabled, then wait for all three tests to report completion.
Expand Down
Loading