From 688bccf1f792fb430a93679b38d9ac800c966557 Mon Sep 17 00:00:00 2001 From: Hansanto Date: Thu, 21 Mar 2024 11:45:52 +0100 Subject: [PATCH] feat: Support intervals arg for toPass --- docs/src/release-notes-js.md | 2 +- packages/playwright/src/matchers/matchers.ts | 3 ++- packages/playwright/types/test.d.ts | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/src/release-notes-js.md b/docs/src/release-notes-js.md index 423dcc9b60..6f43af2156 100644 --- a/docs/src/release-notes-js.md +++ b/docs/src/release-notes-js.md @@ -29,7 +29,7 @@ await page.getByRole('link', { name: 'Collection of blue and white' }).click(); await expect(page.getByRole('heading', { name: 'Light and easy' })).toBeVisible(); ``` -- `expect(callback).toPass()` timeout can now be configured by `expect.toPass.timeout` option [globally](./api/class-testconfig#test-config-expect) or in [project config](./api/class-testproject#test-project-expect) +- `expect(callback).toPass()` timeout and intervals can now be configured by `expect.toPass.timeout` and `expect.toPass.intervals` options [globally](./api/class-testconfig#test-config-expect) or in [project config](./api/class-testproject#test-project-expect) - [`event: ElectronApplication.console`] event is emitted when Electron main process calls console API methods. ```js diff --git a/packages/playwright/src/matchers/matchers.ts b/packages/playwright/src/matchers/matchers.ts index 01d1dfad25..c7a5ebde7a 100644 --- a/packages/playwright/src/matchers/matchers.ts +++ b/packages/playwright/src/matchers/matchers.ts @@ -369,6 +369,7 @@ export async function toPass( ) { const testInfo = currentTestInfo(); const timeout = takeFirst(options.timeout, testInfo?._projectInternal.expect?.toPass?.timeout, 0); + const intervals = takeFirst(options.intervals, testInfo?._projectInternal.expect?.toPass?.intervals, [100, 250, 500, 1000]); const { deadline, timeoutMessage } = testInfo ? testInfo._deadlineForMatcher(timeout) : TestInfoImpl._defaultDeadlineForMatcher(timeout); const result = await pollAgainstDeadline(async () => { @@ -380,7 +381,7 @@ export async function toPass( } catch (e) { return { continuePolling: !this.isNot, result: e }; } - }, deadline, options.intervals || [100, 250, 500, 1000]); + }, deadline, intervals); if (result.timedOut) { const message = result.result ? [ diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts index 497b137774..aa64030c37 100644 --- a/packages/playwright/types/test.d.ts +++ b/packages/playwright/types/test.d.ts @@ -702,6 +702,11 @@ interface TestConfig { * timeout for toPass method in milliseconds. */ timeout?: number; + + /** + * intervals for toPass method in milliseconds. + */ + intervals?: number[]; }; }; @@ -8596,6 +8601,11 @@ interface TestProject { * timeout for toPass method in milliseconds. */ timeout?: number; + + /** + * interval for toPass method in milliseconds. + */ + intervals?: number[]; }; };