chore: remove expect.configure({poll}) (#23060)

This commit is contained in:
Pavel Feldman 2023-05-16 18:45:03 -07:00 committed by GitHub
parent fbc461ede0
commit 04070a59e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 29 deletions

View File

@ -121,10 +121,10 @@ The same works with soft assertions:
expect.soft(value, 'my soft assertion').toBe(56);
```
## expect.configurte
## expect.configure
You can create your own pre-configured `expect` instance to have its own
defaults such as `timeout`, `soft` and `poll`.
defaults such as `timeout` and `soft`.
```js
const slowExpect = expect.configure({ timeout: 10000 });

View File

@ -136,14 +136,14 @@ function createExpect(info: ExpectMetaInfo) {
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 configure({ _poll: poll })(actual, messageOrOptions) as any;
};
}
return expectLibrary[property];
},
});
const configure = (configuration: { message?: string, timeout?: number, soft?: boolean, poll?: boolean | { timeout?: number, intervals?: number[] } }) => {
const configure = (configuration: { message?: string, timeout?: number, soft?: boolean, _poll?: boolean | { timeout?: number, intervals?: number[] } }) => {
const newInfo = { ...info };
if ('message' in configuration)
newInfo.message = configuration.message;
@ -151,11 +151,11 @@ function createExpect(info: ExpectMetaInfo) {
newInfo.timeout = configuration.timeout;
if ('soft' in configuration)
newInfo.isSoft = configuration.soft;
if ('poll' in configuration) {
newInfo.isPoll = !!configuration.poll;
if (typeof configuration.poll === 'object') {
newInfo.pollTimeout = configuration.poll.timeout;
newInfo.pollIntervals = configuration.poll.intervals;
if ('_poll' in configuration) {
newInfo.isPoll = !!configuration._poll;
if (typeof configuration._poll === 'object') {
newInfo.pollTimeout = configuration._poll.timeout;
newInfo.pollIntervals = configuration._poll.intervals;
}
}
return createExpect(newInfo);

View File

@ -88,24 +88,6 @@ test('should configure soft', async ({ runInlineTest }) => {
expect(result.output).toContain('woof-woof');
});
test('should configure poll', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.spec.ts': `
import { test, expect } from '@playwright/test';
const pollingExpect = expect.configure({ poll: { timeout: 1000, intervals: [0, 10000] } });
test('should fail', async () => {
let probes = 0;
const startTime = Date.now();
await pollingExpect(() => ++probes).toBe(3).catch(() => {});
// Probe at 0 and epsilon.
expect(probes).toBe(2);
expect(Date.now() - startTime).toBeLessThan(5000);
});
`
});
expect(result.exitCode).toBe(0);
});
test('should chain configure', async ({ runInlineTest }) => {
const result = await runInlineTest({
'expect-test.spec.ts': `
@ -143,11 +125,11 @@ test('should configure soft poll', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.spec.ts': `
import { test, expect } from '@playwright/test';
const pollingExpect = expect.configure({ soft: true, poll: { timeout: 1000, intervals: [0, 10000] } });
const softExpect = expect.configure({ soft: true });
test('should fail', async () => {
let probes = 0;
const startTime = Date.now();
await pollingExpect(() => ++probes).toBe(3);
await softExpect.poll(() => ++probes, { timeout: 1000, intervals: [0, 10000] }).toBe(3);
// Probe at 0 and epsilon.
expect(probes).toBe(2);
expect(Date.now() - startTime).toBeLessThan(5000);