chore: make web-first matchers work outside of pw tests (#9624)

This commit is contained in:
Pavel Feldman 2021-10-19 13:46:56 -08:00 committed by GitHub
parent a346af4ebf
commit 9d03a85c30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 12 deletions

View File

@ -27,9 +27,6 @@ export async function toBeTruthy(
query: (isNot: boolean, timeout: number) => Promise<{ matches: boolean, log?: string[] }>,
options: { timeout?: number } = {},
) {
const testInfo = currentTestInfo();
if (!testInfo)
throw new Error(`${matcherName} must be called during the test`);
expectType(receiver, receiverType, matcherName);
const matcherOptions = {
@ -37,7 +34,8 @@ export async function toBeTruthy(
promise: this.promise,
};
let defaultExpectTimeout = testInfo.project.expect?.timeout;
const testInfo = currentTestInfo();
let defaultExpectTimeout = testInfo?.project.expect?.timeout;
if (typeof defaultExpectTimeout === 'undefined')
defaultExpectTimeout = 5000;
const timeout = options.timeout === 0 ? 0 : options.timeout || defaultExpectTimeout;

View File

@ -35,9 +35,6 @@ export async function toEqual<T>(
expected: T,
options: { timeout?: number, contains?: boolean } = {},
) {
const testInfo = currentTestInfo();
if (!testInfo)
throw new Error(`${matcherName} must be called during the test`);
expectType(receiver, receiverType, matcherName);
const matcherOptions = {
@ -46,7 +43,8 @@ export async function toEqual<T>(
promise: this.promise,
};
let defaultExpectTimeout = testInfo.project.expect?.timeout;
const testInfo = currentTestInfo();
let defaultExpectTimeout = testInfo?.project.expect?.timeout;
if (typeof defaultExpectTimeout === 'undefined')
defaultExpectTimeout = 5000;
const timeout = options.timeout === 0 ? 0 : options.timeout || defaultExpectTimeout;

View File

@ -35,9 +35,6 @@ export async function toMatchText(
expected: string | RegExp,
options: { timeout?: number, matchSubstring?: boolean } = {},
) {
const testInfo = currentTestInfo();
if (!testInfo)
throw new Error(`${matcherName} must be called during the test`);
expectType(receiver, receiverType, matcherName);
const matcherOptions = {
@ -60,7 +57,8 @@ export async function toMatchText(
);
}
let defaultExpectTimeout = testInfo.project.expect?.timeout;
const testInfo = currentTestInfo();
let defaultExpectTimeout = testInfo?.project.expect?.timeout;
if (typeof defaultExpectTimeout === 'undefined')
defaultExpectTimeout = 5000;
const timeout = options.timeout === 0 ? 0 : options.timeout || defaultExpectTimeout;