chore: remove expect.configure({poll}) (#23060)
This commit is contained in:
parent
fbc461ede0
commit
04070a59e1
|
|
@ -121,10 +121,10 @@ The same works with soft assertions:
|
||||||
expect.soft(value, 'my soft assertion').toBe(56);
|
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
|
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
|
```js
|
||||||
const slowExpect = expect.configure({ timeout: 10000 });
|
const slowExpect = expect.configure({ timeout: 10000 });
|
||||||
|
|
|
||||||
|
|
@ -136,14 +136,14 @@ function createExpect(info: ExpectMetaInfo) {
|
||||||
if (property === 'poll') {
|
if (property === 'poll') {
|
||||||
return (actual: unknown, messageOrOptions?: ExpectMessage & { timeout?: number, intervals?: number[] }) => {
|
return (actual: unknown, messageOrOptions?: ExpectMessage & { timeout?: number, intervals?: number[] }) => {
|
||||||
const poll = isString(messageOrOptions) ? {} : messageOrOptions || {};
|
const poll = isString(messageOrOptions) ? {} : messageOrOptions || {};
|
||||||
return configure({ poll })(actual, messageOrOptions) as any;
|
return configure({ _poll: poll })(actual, messageOrOptions) as any;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return expectLibrary[property];
|
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 };
|
const newInfo = { ...info };
|
||||||
if ('message' in configuration)
|
if ('message' in configuration)
|
||||||
newInfo.message = configuration.message;
|
newInfo.message = configuration.message;
|
||||||
|
|
@ -151,11 +151,11 @@ function createExpect(info: ExpectMetaInfo) {
|
||||||
newInfo.timeout = configuration.timeout;
|
newInfo.timeout = configuration.timeout;
|
||||||
if ('soft' in configuration)
|
if ('soft' in configuration)
|
||||||
newInfo.isSoft = configuration.soft;
|
newInfo.isSoft = configuration.soft;
|
||||||
if ('poll' in configuration) {
|
if ('_poll' in configuration) {
|
||||||
newInfo.isPoll = !!configuration.poll;
|
newInfo.isPoll = !!configuration._poll;
|
||||||
if (typeof configuration.poll === 'object') {
|
if (typeof configuration._poll === 'object') {
|
||||||
newInfo.pollTimeout = configuration.poll.timeout;
|
newInfo.pollTimeout = configuration._poll.timeout;
|
||||||
newInfo.pollIntervals = configuration.poll.intervals;
|
newInfo.pollIntervals = configuration._poll.intervals;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return createExpect(newInfo);
|
return createExpect(newInfo);
|
||||||
|
|
|
||||||
|
|
@ -88,24 +88,6 @@ test('should configure soft', async ({ runInlineTest }) => {
|
||||||
expect(result.output).toContain('woof-woof');
|
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 }) => {
|
test('should chain configure', async ({ runInlineTest }) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'expect-test.spec.ts': `
|
'expect-test.spec.ts': `
|
||||||
|
|
@ -143,11 +125,11 @@ test('should configure soft poll', async ({ runInlineTest }) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'a.spec.ts': `
|
'a.spec.ts': `
|
||||||
import { test, expect } from '@playwright/test';
|
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 () => {
|
test('should fail', async () => {
|
||||||
let probes = 0;
|
let probes = 0;
|
||||||
const startTime = Date.now();
|
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.
|
// Probe at 0 and epsilon.
|
||||||
expect(probes).toBe(2);
|
expect(probes).toBe(2);
|
||||||
expect(Date.now() - startTime).toBeLessThan(5000);
|
expect(Date.now() - startTime).toBeLessThan(5000);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue