From b20c4fcc5f3dab0f1e5a4eb647c9e1e2d08a7ab0 Mon Sep 17 00:00:00 2001 From: Ryan Rosello Date: Sun, 3 Nov 2024 19:53:02 +1000 Subject: [PATCH] feat(test results) Add timestamp to the errors --- packages/playwright-core/src/utils/stackTrace.ts | 1 + tests/playwright-test/expect.spec.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/packages/playwright-core/src/utils/stackTrace.ts b/packages/playwright-core/src/utils/stackTrace.ts index 2e40968ebc..85ab6fa43a 100644 --- a/packages/playwright-core/src/utils/stackTrace.ts +++ b/packages/playwright-core/src/utils/stackTrace.ts @@ -132,6 +132,7 @@ export function formatCallLog(log: string[] | undefined): string { if (!log || !log.some(l => !!l)) return ''; return ` +Timestamp: ${new Date().toISOString()} Call log: ${colors.dim(log.join('\n'))} `; diff --git a/tests/playwright-test/expect.spec.ts b/tests/playwright-test/expect.spec.ts index 08ce16e7ec..efe235dacc 100644 --- a/tests/playwright-test/expect.spec.ts +++ b/tests/playwright-test/expect.spec.ts @@ -71,6 +71,18 @@ test('should include custom expect message with web-first assertions', async ({ expect(result.output).toContain('Call log:'); }); +test('should include a timestamp of when expectation failed', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'expect-test.spec.ts': ` + import { test, expect } from '@playwright/test'; + test('custom expect message', async ({page}) => { + await expect(page.locator('x-foo'), { message: 'x-foo must be visible' }).toBeVisible({timeout: 1}); + }); + ` + }); + expect(result.output).toMatch(/Timestamp: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/); +}); + test('should work with generic matchers', async ({ runTSC }) => { const result = await runTSC({ 'a.spec.ts': `