mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore: should not spill toPass between tests (#22473)
This commit is contained in:
parent
3c495c5590
commit
e7b9c08833
@ -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)
|
||||
|
@ -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 };
|
||||
|
@ -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);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user