From a7559f7b8c1bfd6ecead8301b8d40fa83a6ee991 Mon Sep 17 00:00:00 2001 From: Adam Gastineau Date: Thu, 23 Jan 2025 12:34:40 -0800 Subject: [PATCH] Fix tests --- packages/playwright/src/matchers/toHaveURL.ts | 9 +++++---- tests/playwright-test/expect.spec.ts | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/playwright/src/matchers/toHaveURL.ts b/packages/playwright/src/matchers/toHaveURL.ts index ffdb740971..df09833f84 100644 --- a/packages/playwright/src/matchers/toHaveURL.ts +++ b/packages/playwright/src/matchers/toHaveURL.ts @@ -18,7 +18,7 @@ import type { Page } from 'playwright-core'; import type { ExpectMatcherState } from '../../types/test'; import { EXPECTED_COLOR, printReceived } from '../common/expectBundle'; import { matcherHint, type MatcherResult } from './matcherHint'; -import { urlMatches } from 'playwright-core/lib/utils'; +import { constructURLBasedOnBaseURL, urlMatches } from 'playwright-core/lib/utils'; import { colors } from 'playwright-core/lib/utilsBundle'; import { printReceivedStringContainExpectedResult, printReceivedStringContainExpectedSubstring } from './expect'; @@ -51,13 +51,12 @@ export async function toHaveURL( } const timeout = options?.timeout ?? this.timeout; + const baseURL: string | undefined = (page.context() as any)._options.baseURL; let conditionSucceeded = false; let lastCheckedURLString: string | undefined = undefined; try { await page.mainFrame().waitForURL( url => { - const baseURL: string | undefined = (page.context() as any)._options - .baseURL; lastCheckedURLString = url.toString(); if (options?.ignoreCase) { @@ -96,7 +95,9 @@ export async function toHaveURL( this, matcherName, expression, - expected, + typeof expected === 'string' + ? constructURLBasedOnBaseURL(baseURL, expected) + : expected, lastCheckedURLString, this.isNot, true, diff --git a/tests/playwright-test/expect.spec.ts b/tests/playwright-test/expect.spec.ts index dfe6a6cf02..fdf9ee35c4 100644 --- a/tests/playwright-test/expect.spec.ts +++ b/tests/playwright-test/expect.spec.ts @@ -561,11 +561,12 @@ test('should support toHaveURL predicate', async ({ runInlineTest }) => { 'playwright.config.js': `module.exports = { expect: { timeout: 1000 } }`, 'a.test.ts': ` import { test, expect } from '@playwright/test'; + import { stripVTControlCharacters } from 'node:util'; test('predicate', async ({ page }) => { await page.goto('data:text/html,
A
'); const error = await expect(page).toHaveURL('data:text/html,
B
').catch(e => e); - expect(error.message).toContain('expect.toHaveURL with timeout 1000ms'); + expect(stripVTControlCharacters(error.message)).toContain('Timed out 1000ms waiting for expect(page).toHaveURL(expected)'); expect(error.message).toContain('data:text/html,
'); }); `,