Skip to content

Commit 034408b

Browse files
committed
timeout vs timedOut
1 parent a6315ec commit 034408b

File tree

10 files changed

+32
-27
lines changed

10 files changed

+32
-27
lines changed

packages/playwright/src/matchers/matcherHint.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type MatcherMessageDetails = {
2929
printedExpected?: string;
3030
printedReceived?: string;
3131
printedDiff?: string;
32+
timedOut?: boolean;
3233
timeout?: number;
3334
errorMessage?: string;
3435
log?: string[];
@@ -59,7 +60,7 @@ export function formatMatcherMessage(state: ExpectMatcherState, details: Matcher
5960
message += details.printedExpected + '\n';
6061
if (details.printedReceived)
6162
message += details.printedReceived + '\n';
62-
if (details.timeout)
63+
if (details.timedOut && details.timeout)
6364
message += `Timeout: ${align ? ' ' : ''}${details.timeout}ms\n`;
6465
if (details.printedDiff)
6566
message += details.printedDiff + '\n';

packages/playwright/src/matchers/toBeTruthy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ export async function toBeTruthy(
6161
matcherName,
6262
expectation: arg,
6363
locator,
64-
timeout: timedOut ? timeout : undefined,
64+
timeout,
65+
timedOut,
6566
printedExpected,
6667
printedReceived,
6768
errorMessage,

packages/playwright/src/matchers/toEqual.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ export async function toEqual<T>(
8989
matcherName,
9090
expectation: 'expected',
9191
locator,
92-
timeout: timedOut ? timeout : undefined,
92+
timeout,
93+
timedOut,
9394
printedExpected,
9495
printedReceived,
9596
printedDiff,

packages/playwright/src/matchers/toHaveURL.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function toHaveURLMessage(
9090
expected: Function,
9191
received: string | undefined,
9292
pass: boolean,
93-
didTimeout: boolean,
93+
timedOut: boolean,
9494
timeout: number,
9595
): string {
9696
const receivedString = received || '';
@@ -115,7 +115,8 @@ function toHaveURLMessage(
115115
return formatMatcherMessage(state, {
116116
matcherName,
117117
expectation: 'expected',
118-
timeout: didTimeout ? timeout : undefined,
118+
timeout,
119+
timedOut,
119120
printedExpected,
120121
printedReceived,
121122
printedDiff,

packages/playwright/src/matchers/toMatchAriaSnapshot.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export async function toMatchAriaSnapshot(
8585
expected = unshift(expected);
8686
const { matches: pass, received, log, timedOut, errorMessage } = await locator._expect('to.match.aria', { expectedValue: expected, isNot: this.isNot, timeout });
8787
const typedReceived = received as MatcherReceived;
88-
const receivedText = typedReceived.raw;
8988

9089
const message = () => {
9190
let printedExpected: string | undefined;
@@ -94,17 +93,18 @@ export async function toMatchAriaSnapshot(
9493
if (errorMessage) {
9594
printedExpected = `Expected: ${this.isNot ? 'not ' : ''}${this.utils.printExpected(expected)}`;
9695
} else if (pass) {
97-
const receivedString = printReceivedStringContainExpectedSubstring(receivedText, receivedText.indexOf(expected), expected.length);
96+
const receivedString = printReceivedStringContainExpectedSubstring(typedReceived.raw, typedReceived.raw.indexOf(expected), expected.length);
9897
printedExpected = `Expected: not ${this.utils.printExpected(expected)}`;
9998
printedReceived = `Received: ${receivedString}`;
10099
} else {
101-
printedDiff = this.utils.printDiffOrStringify(expected, receivedText, 'Expected', 'Received', false);
100+
printedDiff = this.utils.printDiffOrStringify(expected, typedReceived.raw, 'Expected', 'Received', false);
102101
}
103102
return formatMatcherMessage(this, {
104103
matcherName,
105104
expectation: 'expected',
106105
locator,
107-
timeout: timedOut ? timeout : undefined,
106+
timeout,
107+
timedOut,
108108
printedExpected,
109109
printedReceived,
110110
printedDiff,

packages/playwright/src/matchers/toMatchSnapshot.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ export async function toHaveScreenshot(
381381
// We tried re-generating new snapshot but failed.
382382
// This can be due to e.g. spinning animation, so we want to show it as a diff.
383383
if (errorMessage) {
384-
const header = formatMatcherMessage(this, { matcherName: 'toHaveScreenshot', locator, expectation: 'expected', timeout: timedOut ? timeout : undefined });
384+
const header = formatMatcherMessage(this, { matcherName: 'toHaveScreenshot', locator, expectation: 'expected', timeout, timedOut });
385385
return helper.handleDifferent(actual, undefined, previous, diff, header, errorMessage, log, this._stepInfo);
386386
}
387387

@@ -416,12 +416,12 @@ export async function toHaveScreenshot(
416416
if (helper.updateSnapshots === 'changed' || helper.updateSnapshots === 'all') {
417417
if (actual)
418418
return writeFiles(actual);
419-
let header = formatMatcherMessage(this, { matcherName: 'toHaveScreenshot', locator, expectation: 'expected', timeout: timedOut ? timeout : undefined });
419+
let header = formatMatcherMessage(this, { matcherName: 'toHaveScreenshot', locator, expectation: 'expected', timeout, timedOut });
420420
header += ' Failed to re-generate expected.\n';
421421
return helper.handleDifferent(actual, expectScreenshotOptions.expected, previous, diff, header, errorMessage, log, this._stepInfo);
422422
}
423423

424-
const header = formatMatcherMessage(this, { matcherName: 'toHaveScreenshot', locator, expectation: 'expected', timeout: timedOut ? timeout : undefined });
424+
const header = formatMatcherMessage(this, { matcherName: 'toHaveScreenshot', locator, expectation: 'expected', timeout, timedOut });
425425
return helper.handleDifferent(actual, expectScreenshotOptions.expected, previous, diff, header, errorMessage, log, this._stepInfo);
426426
}
427427

packages/playwright/src/matchers/toMatchText.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ export async function toMatchText(
9393
matcherName,
9494
expectation: 'expected',
9595
locator,
96-
timeout: timedOut ? timeout : undefined,
96+
timeout,
97+
timedOut,
9798
printedExpected,
9899
printedReceived,
99100
printedDiff,

tests/playwright-test/expect-configure.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test('should configure message', async ({ runInlineTest }) => {
4949
expect(result.passed).toBe(0);
5050
expect(result.output).toContain('Error: x-foo must be visible');
5151
expect(result.output).toContain('expect(locator).toBeVisible() failed');
52-
expect(result.output).toContain('Timeout: 1ms');
52+
expect(result.output).toContain('Timeout: 1ms');
5353
expect(result.output).toContain('Call log:');
5454
});
5555

@@ -68,7 +68,7 @@ test('should prefer local message', async ({ runInlineTest }) => {
6868

6969
expect(result.output).toContain('Error: overridden');
7070
expect(result.output).toContain(`expect(locator).toBeVisible() failed`);
71-
expect(result.output).toContain('Timeout: 1ms');
71+
expect(result.output).toContain('Timeout: 1ms');
7272
expect(result.output).toContain('Call log:');
7373
});
7474

tests/playwright-test/expect.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ test('should include custom expect message with web-first assertions', async ({
6868

6969
expect(result.output).toContain('Error: x-foo must be visible');
7070
expect(result.output).toContain('expect(locator).toBeVisible() failed');
71-
expect(result.output).toContain('Timeout: 1ms');
71+
expect(result.output).toContain('Timeout: 1ms');
7272
expect(result.output).toContain('Call log:');
7373
});
7474

@@ -533,13 +533,13 @@ test('should support toHaveURL with baseURL from webServer', async ({ runInlineT
533533
}, { workers: 1 });
534534
const output = result.output;
535535
expect(output).toContain('expect(page).toHaveURL');
536-
expect(output).toContain(`Expected string: \"http://localhost:${port}/kek\"`);
536+
expect(output).toContain(`Expected: \"http://localhost:${port}/kek\"`);
537537
expect(result.passed).toBe(1);
538538
expect(result.failed).toBe(1);
539539
expect(result.exitCode).toBe(1);
540540
});
541541

542-
test('should respect expect.timeout', async ({ runInlineTest }) => {
542+
test('should respect expect.timeout in toHaveURL', async ({ runInlineTest }) => {
543543
const result = await runInlineTest({
544544
'playwright.config.js': `module.exports = { expect: { timeout: 1000 } }`,
545545
'a.test.ts': `
@@ -550,7 +550,7 @@ test('should respect expect.timeout', async ({ runInlineTest }) => {
550550
await page.goto('data:text/html,<div>A</div>');
551551
const error = await expect(page).toHaveURL('data:text/html,<div>B</div>').catch(e => e);
552552
expect(stripVTControlCharacters(error.message)).toContain('expect(page).toHaveURL(expected) failed');
553-
expect(stripVTControlCharacters(error.message)).toContain('Timeout: 1000ms');
553+
expect(stripVTControlCharacters(error.message)).toContain('Timeout: 1000ms');
554554
expect(error.message).toContain('data:text/html,<div>');
555555
});
556556
`,
@@ -570,7 +570,7 @@ test('should support toHaveURL predicate', async ({ runInlineTest }) => {
570570
await page.goto('data:text/html,<div>A</div>');
571571
const error = await expect(page).toHaveURL(url => url === 'data:text/html,<div>B</div>').catch(e => e);
572572
expect(stripVTControlCharacters(error.message)).toContain('expect(page).toHaveURL(expected) failed');
573-
expect(stripVTControlCharacters(error.message)).toContain('Timeout: 1000ms');
573+
expect(stripVTControlCharacters(error.message)).toContain('Timeout: 1000ms');
574574
expect(error.message).toContain('data:text/html,<div>');
575575
});
576576
`,
@@ -615,8 +615,8 @@ test('should print expected/received before timeout', async ({ runInlineTest })
615615
expect(result.passed).toBe(0);
616616
expect(result.failed).toBe(1);
617617
expect(result.output).toContain('Test timeout of 2000ms exceeded.');
618-
expect(result.output).toContain('Expected string: "Text 2"');
619-
expect(result.output).toContain('Received string: "Text content"');
618+
expect(result.output).toContain('Expected: "Text 2"');
619+
expect(result.output).toContain('Received: "Text content"');
620620
});
621621

622622
test('should print pending operations for toHaveText', async ({ runInlineTest }) => {
@@ -634,7 +634,7 @@ test('should print pending operations for toHaveText', async ({ runInlineTest })
634634
expect(result.exitCode).toBe(1);
635635
const output = result.output;
636636
expect(output).toContain(`expect(locator).toHaveText(expected)`);
637-
expect(output).toContain('Expected string: "Text"');
637+
expect(output).toContain('Expected: "Text"');
638638
expect(output).toContain('Error: element(s) not found');
639639
expect(output).toContain('waiting for locator(\'no-such-thing\')');
640640
});
@@ -690,8 +690,8 @@ test('should print expected/received on Ctrl+C', async ({ interactWithTestRunner
690690
const result = parseTestRunnerOutput(testProcess.output);
691691
expect(result.passed).toBe(0);
692692
expect(result.interrupted).toBe(1);
693-
expect(result.output).toContain('Expected string: "Text 2"');
694-
expect(result.output).toContain('Received string: "Text content"');
693+
expect(result.output).toContain('Expected: "Text 2"');
694+
expect(result.output).toContain('Received: "Text content"');
695695
});
696696

697697
test('should not print timed out error message when test times out', async ({ runInlineTest }) => {
@@ -1024,7 +1024,7 @@ test('should respect timeout from configured expect when used outside of the tes
10241024
expect(code).toBe(1);
10251025
expect(stdout).toBe('');
10261026
expect(stripAnsi(stderr)).toContain('expect(locator).toBeAttached() failed');
1027-
expect(stripAnsi(stderr)).toContain('Timeout: 10ms');
1027+
expect(stripAnsi(stderr)).toContain('Timeout: 10ms');
10281028
});
10291029

10301030
test('should expose timeout to custom matchers', async ({ runInlineTest, runTSC }) => {

tests/playwright-test/watch.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ test('should run CT on changed deps', async ({ runWatchTest, writeFiles }) => {
721721
await testProcess.waitForOutput(`src${path.sep}button.spec.tsx:4:11 › pass`);
722722
expect(testProcess.output).not.toContain(`src${path.sep}link.spec.tsx`);
723723
await testProcess.waitForOutput(`Error: expect(locator).toHaveText(expected) failed`);
724-
await testProcess.waitForOutput('Timeout: 1000ms');
724+
await testProcess.waitForOutput('Timeout: 1000ms');
725725
await testProcess.waitForOutput('Waiting for file changes.');
726726
});
727727

0 commit comments

Comments
 (0)