Skip to content

Commit 7a56fea

Browse files
hi-ogawaclaude
andauthored
fix(browser): skip trace entries after their attempt ended (#11771)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 4f135cc commit 7a56fea

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

‎packages/browser/src/client/tester/trace.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ export async function recordBrowserTraceEntry(
9292
task: Task,
9393
options: Omit<BrowserTraceEntry, 'snapshot' | 'startTime'>,
9494
): Promise<void> {
95-
const attemptInfo = getBrowserState().browserTraceAttempts.get(task.id)!
95+
// An un-awaited action can settle after its attempt ended.
96+
const attemptInfo = getBrowserState().browserTraceAttempts.get(task.id)
97+
if (!attemptInfo) {
98+
return
99+
}
96100
const relativeStartTime = now() - attemptInfo.startTime
97101
const failureOnly = getBrowserState().config.browser.traceView.mode === 'failure-only'
98102
// in 'failure-only', only the end of a failed test is snapshotted and sent,

‎test/browser/specs/trace.test.ts‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { stripVTControlCharacters } from 'node:util'
66
import { relative } from 'pathe'
77
import { expect, test } from 'vitest'
88
import { buildTestProjectTree } from '../../test-utils'
9-
import { instances, provider, runBrowserTests } from './utils'
9+
import { instances, provider, runBrowserTests, runInlineBrowserTests } from './utils'
1010

1111
// update snapshots by
1212
// TEST_BROWSER=chromium pnpm -C test/browser/ test:playwright specs/trace.test.ts -u --run
@@ -1691,3 +1691,39 @@ test('trace view artifacts', async () => {
16911691
}
16921692
}
16931693
})
1694+
1695+
test('action settling after its attempt ended is not recorded', async () => {
1696+
const { stderr, errorTree } = await runInlineBrowserTests(
1697+
{
1698+
'basic.test.ts': /* ts */ `
1699+
import { test } from 'vitest'
1700+
import { page } from 'vitest/browser'
1701+
1702+
test('unawaited', () => {
1703+
document.body.innerHTML = '<button>Click</button>'
1704+
// attaching a handler starts the call without awaiting it
1705+
page.getByRole('button').click().then(() => {})
1706+
})
1707+
1708+
test('wait', async () => {
1709+
await new Promise(resolve => setTimeout(resolve, 500))
1710+
})
1711+
`,
1712+
},
1713+
{
1714+
browser: {
1715+
instances: instances.slice(0, 1),
1716+
traceView: 'on',
1717+
},
1718+
},
1719+
)
1720+
expect(stderr).toBe('')
1721+
expect(errorTree()).toMatchInlineSnapshot(`
1722+
{
1723+
"basic.test.ts": {
1724+
"unawaited": "passed",
1725+
"wait": "passed",
1726+
},
1727+
}
1728+
`)
1729+
})

0 commit comments

Comments
 (0)