Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: should not spill toPass between tests (#22473)
Pavel Feldmane7b9c088334e
diff --git a/packages/playwright-test/src/matchers/expect.ts b/packages/playwright-test/src/matchers/expect.tsindex 8bf73728cb..6dba330818 100644--- a/packages/playwright-test/src/matchers/expect.ts+++ b/packages/playwright-test/src/matchers/expect.ts@@ -283,7 +283,12 @@ class ExpectMetaInfoProxyHandler implements ProxyHandler<any> {}async function pollMatcher(matcherName: any, isNot: boolean, pollIntervals: number[] | undefined, timeout: number, generator: () => any, ...args: any[]) {+ const testInfo = currentTestInfo();+const result = await pollAgainstTimeout<Error|undefined>(async () => {+ if (testInfo && currentTestInfo() !== testInfo)+ return { continuePolling: false, result: undefined };+const value = await generator();let expectInstance = expectLibrary(value) as any;if (isNot)diff --git a/packages/playwright-test/src/matchers/matchers.ts b/packages/playwright-test/src/matchers/matchers.tsindex a0380f1bf6..f22d567efd 100644--- a/packages/playwright-test/src/matchers/matchers.ts+++ b/packages/playwright-test/src/matchers/matchers.ts@@ -23,6 +23,7 @@ import { toBeTruthy } from './toBeTruthy';import { toEqual } from './toEqual';import { toExpectedTextValues, toMatchText } from './toMatchText';import { constructURLBasedOnBaseURL, isTextualMimeType, pollAgainstTimeout } from 'playwright-core/lib/utils';+import { currentTestInfo } from '../common/globals';interface LocatorEx extends Locator {_expect(expression: string, options: Omit<FrameExpectOptions, 'expectedValue'> & { expectedValue?: any }): Promise<{ matches: boolean, received?: any, log?: string[], timedOut?: boolean }>;@@ -337,9 +338,12 @@ export async function toPass(timeout?: number,} = {},) {+ const testInfo = currentTestInfo();const timeout = options.timeout !== undefined ? options.timeout : 0;const result = await pollAgainstTimeout<Error|undefined>(async () => {+ if (testInfo && currentTestInfo() !== testInfo)+ return { continuePolling: false, result: undefined };try {await callback();return { continuePolling: this.isNot, result: undefined };diff --git a/tests/playwright-test/expect-to-pass.spec.ts b/tests/playwright-test/expect-to-pass.spec.tsindex 875014cc6d..06e36a4c1c 100644--- a/tests/playwright-test/expect-to-pass.spec.ts+++ b/tests/playwright-test/expect-to-pass.spec.ts@@ -182,3 +182,25 @@ test('should not accept TimeoutError', async ({ runInlineTest }) => {expect(result.exitCode).toBe(1);expect(result.failed).toBe(1);});++test('should not spin forever', async ({ runInlineTest }) => {+ const result = await runInlineTest({+ 'a.spec.ts': `+ import { test, expect } from '@playwright/test';+ let log;+ test('spill toPass', async () => {+ expect(() => {+ log?.push('poll');+ throw new Error('Polling');+ }).toPass().catch();+ });+ test('should not see toPass', async () => {+ log = [];+ await new Promise(f => setTimeout(f, 1000));+ expect(log.length).toBe(0);+ });+ `+ });+ expect(result.exitCode).toBe(0);+ expect(result.passed).toBe(2);+});