Skip to content

Commit 5b86421

Browse files
authored
fix(browser): always derive a positive locator action timeout (#10626)
1 parent 833f093 commit 5b86421

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

packages/browser/src/client/tester/tester-utils.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,10 @@ export function processTimeoutOptions<T extends { timeout?: number }>(options_:
245245
const currentTime = now()
246246
const endTime = startTime + timeout
247247
const remainingTime = Math.floor(endTime - currentTime)
248-
if (remainingTime <= 0) {
249-
return options_
250-
}
251-
// give us some time to process the timeout
252-
options_.timeout = remainingTime - 100
248+
// keep some buffer to process the timeout, but always hand the provider a
249+
// positive value so it surfaces a descriptive, source-mapped locator error
250+
// instead of letting the task timer win the race with a generic timeout
251+
options_.timeout = Math.max(remainingTime - 100, 1)
253252
return options_
254253
}
255254

test/browser/fixtures/timeout-hooks/hooks-timeout.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,40 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, onTes
44
describe.runIf(server.provider === 'playwright')('timeouts are failing correctly', () => {
55
it('click on non-existing element fails', async () => {
66
await page.getByRole('code').click()
7-
}, 150)
7+
}, 500)
88

99
it('expect.element on non-existing element fails', async () => {
1010
await expect.element(page.getByRole('code')).toBeVisible()
11-
}, 150)
11+
}, 1000)
1212

1313
describe('beforeEach', () => {
1414
beforeEach(async () => {
1515
await page.getByTestId('non-existing').click()
16-
}, 150)
16+
}, 500)
1717

1818
it('skipped', () => {})
1919
})
2020

2121
describe('afterEach', () => {
2222
afterEach(async () => {
2323
await page.getByTestId('non-existing').click()
24-
}, 150)
24+
}, 500)
2525

2626
it('skipped', () => {})
2727
})
2828

2929
describe('beforeAll', () => {
3030
beforeAll(async () => {
3131
await page.getByTestId('non-existing').click()
32-
}, 150)
32+
}, 500)
3333

3434
it('skipped', () => {})
3535
})
3636

3737
describe('afterAll', () => {
3838
afterAll(async () => {
3939
await page.getByTestId('non-existing').click()
40-
}, 150)
40+
}, 500)
4141

4242
it('skipped', () => {})
4343
})
@@ -46,29 +46,29 @@ describe.runIf(server.provider === 'playwright')('timeouts are failing correctly
4646
it('fails', ({ onTestFinished }) => {
4747
onTestFinished(async () => {
4848
await page.getByTestId('non-existing').click()
49-
}, 150)
49+
}, 500)
5050
})
5151

5252
it('fails global', () => {
5353
onTestFinished(async () => {
5454
await page.getByTestId('non-existing').click()
55-
}, 150)
55+
}, 500)
5656
})
5757
})
5858

5959
describe('onTestFailed', () => {
6060
it('fails', ({ onTestFailed }) => {
6161
onTestFailed(async () => {
6262
await page.getByTestId('non-existing').click()
63-
}, 150)
63+
}, 500)
6464

6565
expect.unreachable()
6666
})
6767

6868
it('fails global', () => {
6969
onTestFailed(async () => {
7070
await page.getByTestId('non-existing').click()
71-
}, 150)
71+
}, 500)
7272

7373
expect.unreachable()
7474
})

0 commit comments

Comments
 (0)