Skip to content

Commit

Permalink
fix: restore timeout error name (#28408)
Browse files Browse the repository at this point in the history
Fixes #28404
  • Loading branch information
pavelfeldman authored Nov 30, 2023
1 parent 35c2633 commit 92a0d24
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/playwright-core/src/client/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ import type { SerializedError } from '@protocol/channels';
import { isError } from '../utils';
import { parseSerializedValue, serializeValue } from '../protocol/serializers';

export class TimeoutError extends Error {}
export class TimeoutError extends Error {
constructor(message: string) {
super(message);
this.name = 'TimeoutError';
}
}

export class TargetClosedError extends Error {
constructor(cause?: string) {
super(cause || 'Target page, context or browser has been closed');
this.name = 'TargetClosedError';
}
}

Expand Down
5 changes: 5 additions & 0 deletions tests/page/expect-timeout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ test('should not print timed out error message when page closes', async ({ page
expect(stripAnsi(error.message)).toContain('expect.toHaveText with timeout 100000ms');
expect(stripAnsi(error.message)).not.toContain('Timed out');
});

test('should have timeout error name', async ({ page }) => {
const error = await page.waitForSelector('#not-found', { timeout: 1 }).catch(e => e);
expect(error.name).toBe('TimeoutError');
});
2 changes: 1 addition & 1 deletion tests/playwright-test/reporter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ for (const useIntermediateMergeReport of [false, true] as const) {
`begin {\"title\":\"page.setContent\",\"category\":\"pw:api\"}`,
`end {\"title\":\"page.setContent\",\"category\":\"pw:api\"}`,
`begin {\"title\":\"page.click(input)\",\"category\":\"pw:api\"}`,
`end {\"title\":\"page.click(input)\",\"category\":\"pw:api\",\"error\":{\"message\":\"Error: page.click: Timeout 1ms exceeded.\\nCall log:\\n \\u001b[2m- waiting for locator('input')\\u001b[22m\\n\",\"stack\":\"<stack>\",\"location\":\"<location>\",\"snippet\":\"<snippet>\"}}`,
`end {\"title\":\"page.click(input)\",\"category\":\"pw:api\",\"error\":{\"message\":\"TimeoutError: page.click: Timeout 1ms exceeded.\\nCall log:\\n \\u001b[2m- waiting for locator('input')\\u001b[22m\\n\",\"stack\":\"<stack>\",\"location\":\"<location>\",\"snippet\":\"<snippet>\"}}`,
`begin {\"title\":\"After Hooks\",\"category\":\"hook\"}`,
`begin {\"title\":\"fixture: page\",\"category\":\"fixture\"}`,
`end {\"title\":\"fixture: page\",\"category\":\"fixture\"}`,
Expand Down

0 comments on commit 92a0d24

Please sign in to comment.