address comments
This commit is contained in:
parent
62054a3b36
commit
7994315d0b
|
|
@ -33,24 +33,6 @@ export function currentlyLoadingFileSuite() {
|
||||||
return currentFileSuite;
|
return currentFileSuite;
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentExpectConfigureTimeout: number | undefined;
|
|
||||||
|
|
||||||
export function setCurrentExpectConfigureTimeout(timeout: number | undefined) {
|
|
||||||
currentExpectConfigureTimeout = timeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function currentExpectTimeout(options: { timeout?: number }) {
|
|
||||||
const testInfo = currentTestInfo();
|
|
||||||
if (options.timeout !== undefined)
|
|
||||||
return options.timeout;
|
|
||||||
if (currentExpectConfigureTimeout !== undefined)
|
|
||||||
return currentExpectConfigureTimeout;
|
|
||||||
let defaultExpectTimeout = testInfo?._projectInternal?.expect?.timeout;
|
|
||||||
if (typeof defaultExpectTimeout === 'undefined')
|
|
||||||
defaultExpectTimeout = 5000;
|
|
||||||
return defaultExpectTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
let _isWorkerProcess = false;
|
let _isWorkerProcess = false;
|
||||||
|
|
||||||
export function setIsWorkerProcess() {
|
export function setIsWorkerProcess() {
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ import {
|
||||||
} from './matchers';
|
} from './matchers';
|
||||||
import { toMatchSnapshot, toHaveScreenshot, toHaveScreenshotStepTitle } from './toMatchSnapshot';
|
import { toMatchSnapshot, toHaveScreenshot, toHaveScreenshotStepTitle } from './toMatchSnapshot';
|
||||||
import type { Expect, ExpectMatcherState } from '../../types/test';
|
import type { Expect, ExpectMatcherState } from '../../types/test';
|
||||||
import { currentTestInfo, currentExpectTimeout, setCurrentExpectConfigureTimeout } from '../common/globals';
|
import { currentTestInfo } from '../common/globals';
|
||||||
import { filteredStackTrace, trimLongString } from '../util';
|
import { filteredStackTrace, trimLongString } from '../util';
|
||||||
import {
|
import {
|
||||||
expect as expectLibrary,
|
expect as expectLibrary,
|
||||||
|
|
@ -129,18 +129,18 @@ function createExpect(info: ExpectMetaInfo) {
|
||||||
if (property === 'extend') {
|
if (property === 'extend') {
|
||||||
return (matchers: any) => {
|
return (matchers: any) => {
|
||||||
const wrappedMatchers: any = {};
|
const wrappedMatchers: any = {};
|
||||||
Object.entries(matchers).forEach(([name, matcher]) => {
|
for (const [name, matcher] of Object.entries(matchers)) {
|
||||||
wrappedMatchers[name] = function(...args: any[]) {
|
wrappedMatchers[name] = function(...args: any[]) {
|
||||||
const { isNot, promise, utils } = this;
|
const { isNot, promise, utils } = this;
|
||||||
const newThis: ExpectMatcherState = {
|
const newThis: ExpectMatcherState = {
|
||||||
isNot,
|
isNot,
|
||||||
promise,
|
promise,
|
||||||
utils,
|
utils,
|
||||||
timeout: currentExpectTimeout({})
|
timeout: currentExpectTimeout()
|
||||||
};
|
};
|
||||||
return (matcher as any).call(newThis, ...args);
|
return (matcher as any).call(newThis, ...args);
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
expectLibrary.extend(wrappedMatchers);
|
expectLibrary.extend(wrappedMatchers);
|
||||||
return expectInstance;
|
return expectInstance;
|
||||||
};
|
};
|
||||||
|
|
@ -255,7 +255,7 @@ class ExpectMetaInfoProxyHandler implements ProxyHandler<any> {
|
||||||
if (this._info.isPoll) {
|
if (this._info.isPoll) {
|
||||||
if ((customAsyncMatchers as any)[matcherName] || matcherName === 'resolves' || matcherName === 'rejects')
|
if ((customAsyncMatchers as any)[matcherName] || matcherName === 'resolves' || matcherName === 'rejects')
|
||||||
throw new Error(`\`expect.poll()\` does not support "${matcherName}" matcher.`);
|
throw new Error(`\`expect.poll()\` does not support "${matcherName}" matcher.`);
|
||||||
matcher = (...args: any[]) => pollMatcher(matcherName, !!this._info.isNot, this._info.pollIntervals, currentExpectTimeout({ timeout: this._info.pollTimeout }), this._info.generator!, ...args);
|
matcher = (...args: any[]) => pollMatcher(matcherName, !!this._info.isNot, this._info.pollIntervals, this._info.pollTimeout ?? currentExpectTimeout(), this._info.generator!, ...args);
|
||||||
}
|
}
|
||||||
return (...args: any[]) => {
|
return (...args: any[]) => {
|
||||||
const testInfo = currentTestInfo();
|
const testInfo = currentTestInfo();
|
||||||
|
|
@ -347,6 +347,22 @@ async function pollMatcher(matcherName: any, isNot: boolean, pollIntervals: numb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let currentExpectConfigureTimeout: number | undefined;
|
||||||
|
|
||||||
|
function setCurrentExpectConfigureTimeout(timeout: number | undefined) {
|
||||||
|
currentExpectConfigureTimeout = timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
function currentExpectTimeout() {
|
||||||
|
if (currentExpectConfigureTimeout !== undefined)
|
||||||
|
return currentExpectConfigureTimeout;
|
||||||
|
const testInfo = currentTestInfo();
|
||||||
|
let defaultExpectTimeout = testInfo?._projectInternal?.expect?.timeout;
|
||||||
|
if (typeof defaultExpectTimeout === 'undefined')
|
||||||
|
defaultExpectTimeout = 5000;
|
||||||
|
return defaultExpectTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
function computeArgsSuffix(matcherName: string, args: any[]) {
|
function computeArgsSuffix(matcherName: string, args: any[]) {
|
||||||
let value = '';
|
let value = '';
|
||||||
if (matcherName === 'toHaveScreenshot')
|
if (matcherName === 'toHaveScreenshot')
|
||||||
|
|
|
||||||
2
packages/playwright/types/test.d.ts
vendored
2
packages/playwright/types/test.d.ts
vendored
|
|
@ -6511,7 +6511,7 @@ export interface ExpectMatcherUtils {
|
||||||
|
|
||||||
export type ExpectMatcherState = {
|
export type ExpectMatcherState = {
|
||||||
/**
|
/**
|
||||||
* Wehther this matcher was called with the negated .not modifier.
|
* Whether this matcher was called with the negated .not modifier.
|
||||||
*/
|
*/
|
||||||
isNot: boolean;
|
isNot: boolean;
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
2
utils/generate_types/overrides-test.d.ts
vendored
2
utils/generate_types/overrides-test.d.ts
vendored
|
|
@ -359,7 +359,7 @@ export interface ExpectMatcherUtils {
|
||||||
|
|
||||||
export type ExpectMatcherState = {
|
export type ExpectMatcherState = {
|
||||||
/**
|
/**
|
||||||
* Wehther this matcher was called with the negated .not modifier.
|
* Whether this matcher was called with the negated .not modifier.
|
||||||
*/
|
*/
|
||||||
isNot: boolean;
|
isNot: boolean;
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue