chore: fix soft after poll (#22642)
This commit is contained in:
parent
44e56d2404
commit
7fdd7a20fb
|
|
@ -115,7 +115,7 @@ function createMatchers(actual: unknown, info: ExpectMetaInfo): any {
|
||||||
}
|
}
|
||||||
|
|
||||||
function createExpect(info: ExpectMetaInfo) {
|
function createExpect(info: ExpectMetaInfo) {
|
||||||
const expect: Expect = new Proxy(expectLibrary, {
|
const expectInstance: Expect = new Proxy(expectLibrary, {
|
||||||
apply: function(target: any, thisArg: any, argumentsList: [unknown, ExpectMessage?]) {
|
apply: function(target: any, thisArg: any, argumentsList: [unknown, ExpectMessage?]) {
|
||||||
const [actual, messageOrOptions] = argumentsList;
|
const [actual, messageOrOptions] = argumentsList;
|
||||||
const message = isString(messageOrOptions) ? messageOrOptions : messageOrOptions?.message || info.message;
|
const message = isString(messageOrOptions) ? messageOrOptions : messageOrOptions?.message || info.message;
|
||||||
|
|
@ -126,19 +126,29 @@ function createExpect(info: ExpectMetaInfo) {
|
||||||
newInfo.generator = actual as any;
|
newInfo.generator = actual as any;
|
||||||
}
|
}
|
||||||
return createMatchers(actual, newInfo);
|
return createMatchers(actual, newInfo);
|
||||||
}
|
},
|
||||||
|
|
||||||
|
get: function(target: any, property: string) {
|
||||||
|
if (property === 'configure')
|
||||||
|
return configure;
|
||||||
|
|
||||||
|
if (property === 'soft') {
|
||||||
|
return (actual: unknown, messageOrOptions?: ExpectMessage) => {
|
||||||
|
return configure({ soft: true })(actual, messageOrOptions) as any;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'poll') {
|
||||||
|
return (actual: unknown, messageOrOptions?: ExpectMessage & { timeout?: number, intervals?: number[] }) => {
|
||||||
|
const poll = isString(messageOrOptions) ? {} : messageOrOptions || {};
|
||||||
|
return configure({ poll })(actual, messageOrOptions) as any;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return expectLibrary[property];
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect.soft = (actual: unknown, messageOrOptions?: ExpectMessage) => {
|
const configure = (configuration: { message?: string, timeout?: number, soft?: boolean, poll?: boolean | { timeout?: number, intervals?: number[] } }) => {
|
||||||
return expect.configure({ soft: true })(actual, messageOrOptions) as any;
|
|
||||||
};
|
|
||||||
|
|
||||||
expect.poll = (actual: unknown, messageOrOptions?: ExpectMessage & { timeout?: number, intervals?: number[] }) => {
|
|
||||||
const poll = isString(messageOrOptions) ? {} : messageOrOptions || {};
|
|
||||||
return expect.configure({ poll })(actual, messageOrOptions) as any;
|
|
||||||
};
|
|
||||||
|
|
||||||
expect.configure = (configuration: { message?: string, timeout?: number, soft?: boolean, poll?: boolean | { timeout?: number, intervals?: number[] } }) => {
|
|
||||||
const newInfo = { ...info };
|
const newInfo = { ...info };
|
||||||
if ('message' in configuration)
|
if ('message' in configuration)
|
||||||
newInfo.message = configuration.message;
|
newInfo.message = configuration.message;
|
||||||
|
|
@ -156,7 +166,7 @@ function createExpect(info: ExpectMetaInfo) {
|
||||||
return createExpect(newInfo);
|
return createExpect(newInfo);
|
||||||
};
|
};
|
||||||
|
|
||||||
return expect;
|
return expectInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const expect: Expect = createExpect({});
|
export const expect: Expect = createExpect({});
|
||||||
|
|
|
||||||
|
|
@ -158,3 +158,16 @@ test('should configure soft poll', async ({ runInlineTest }) => {
|
||||||
expect(result.exitCode).toBe(1);
|
expect(result.exitCode).toBe(1);
|
||||||
expect(result.outputLines).toEqual(['woof-woof']);
|
expect(result.outputLines).toEqual(['woof-woof']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should configure soft after poll', async ({ runInlineTest }) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'a.spec.ts': `
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
test('should pass', async () => {
|
||||||
|
await expect.poll(() => true).toBe(true);
|
||||||
|
expect.soft(1).toBe(1);
|
||||||
|
});
|
||||||
|
`
|
||||||
|
});
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue