Skip to content

Commit fcdd9b7

Browse files
Replace deprecated waitFor in e2e tests (#28360)
* Replace waitFor with waitForTimeout * Replace waitFor with waitForFunction * Replace waitFor with waitForSelector and waitForTimeout * Update message for waitFor and add rule for waitForTimeout * Disable rule for next line
1 parent d69bd86 commit fcdd9b7

11 files changed

Lines changed: 19 additions & 11 deletions

File tree

.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ module.exports = {
110110
{
111111
selector:
112112
'CallExpression[callee.object.name="page"][callee.property.name="waitFor"]',
113+
message:
114+
'This method is deprecated. You should use the more explicit API methods available.',
115+
},
116+
{
117+
selector:
118+
'CallExpression[callee.object.name="page"][callee.property.name="waitForTimeout"]',
113119
message: 'Prefer page.waitForSelector instead.',
114120
},
115121
{

packages/e2e-test-utils/src/delete-theme.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function deleteTheme(
4141

4242
// Wait for the theme to be removed from the page.
4343
// eslint-disable-next-line no-restricted-syntax
44-
await page.waitFor(
44+
await page.waitForFunction(
4545
( themeSlug ) =>
4646
! document.querySelector( `[data-slug="${ themeSlug }"]` ),
4747
slug

packages/e2e-test-utils/src/preview.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ export async function openPreviewPage( editorPage = page ) {
1515
let openTabs = await browser.pages();
1616
const expectedTabsCount = openTabs.length + 1;
1717
await editorPage.click( '.block-editor-post-preview__button-toggle' );
18-
await editorPage.waitFor( '.edit-post-header-preview__button-external' );
18+
await editorPage.waitForSelector(
19+
'.edit-post-header-preview__button-external'
20+
);
1921
await editorPage.click( '.edit-post-header-preview__button-external' );
2022

2123
// Wait for the new tab to open.
2224
while ( openTabs.length < expectedTabsCount ) {
23-
await editorPage.waitFor( 1 );
25+
await editorPage.waitForTimeout( 1 );
2426
openTabs = await browser.pages();
2527
}
2628

packages/e2e-tests/specs/editor/plugins/custom-post-types.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ describe( 'Test Custom Post Types', () => {
6363
await page.waitForSelector( PARENT_PAGE_INPUT );
6464
// Wait for the list of suggestions to fetch
6565
// There should be a better way to do that.
66-
// eslint-disable-next-line no-restricted-syntax
67-
await page.waitFor(
66+
await page.waitForFunction(
6867
( [ value, inputSelector ] ) =>
6968
document.querySelector( inputSelector ).value === value,
7069
{},

packages/e2e-tests/specs/editor/plugins/nonce.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe( 'Nonce', () => {
2424
it( 'should refresh when expired', async () => {
2525
await page.keyboard.press( 'Enter' );
2626
// eslint-disable-next-line no-restricted-syntax
27-
await page.waitFor( 5000 );
27+
await page.waitForTimeout( 5000 );
2828
await page.keyboard.type( 'test' );
2929
// `saveDraft` waits for saving to be successful, so this test would
3030
// timeout if it's not.

packages/e2e-tests/specs/editor/various/adding-blocks.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ describe( 'adding blocks', () => {
293293
// We need to wait a bit after typing otherwise we might an "early" result
294294
// that is going to be "detached" when trying to click on it
295295
// eslint-disable-next-line no-restricted-syntax
296-
await page.waitFor( 100 );
296+
await page.waitForTimeout( 100 );
297297
const coverBlock = await page.waitForSelector(
298298
'.block-editor-block-types-list .editor-block-list-item-cover'
299299
);

packages/e2e-tests/specs/editor/various/autosave.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async function sleep( durationInSeconds ) {
3434
// `waitFor`, which isn't apt for the use case, when provided an integer,
3535
// of waiting for a given amount of time.
3636
// eslint-disable-next-line no-restricted-syntax
37-
await page.waitFor( durationInSeconds * 1000 );
37+
await page.waitForTimeout( durationInSeconds * 1000 );
3838
}
3939

4040
async function clearSessionStorage() {

packages/e2e-tests/specs/editor/various/links.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ describe( 'Links', () => {
318318
// Disable reason: Wait for the animation to complete, since otherwise the
319319
// click attempt may occur at the wrong point.
320320
// eslint-disable-next-line no-restricted-syntax
321-
await page.waitFor( 100 );
321+
await page.waitForTimeout( 100 );
322322

323323
// Publish the post
324324
await page.click( '.editor-post-publish-button' );

packages/e2e-tests/specs/editor/various/nux.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe( 'New User Experience (NUX)', () => {
5050
);
5151
// This shouldn't be necessary
5252
// eslint-disable-next-line no-restricted-syntax
53-
await page.waitFor( 500 );
53+
await page.waitForTimeout( 500 );
5454

5555
// Press the right arrow key for Page 3
5656
await page.keyboard.press( 'ArrowRight' );

packages/e2e-tests/specs/editor/various/reusable-blocks.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ describe( 'Reusable blocks', () => {
315315

316316
// Wait for async mode to dispatch the update.
317317
// eslint-disable-next-line no-restricted-syntax
318-
await page.waitFor( 1000 );
318+
await page.waitForTimeout( 1000 );
319319

320320
// Check that the content of the second reusable block has been updated.
321321
const reusableBlocks = await page.$$( '.wp-block-block' );

0 commit comments

Comments
 (0)