From 83f2f3c948d6510ef956be3cfc89d36eb8d90ffa Mon Sep 17 00:00:00 2001 From: Kai Hao Date: Tue, 8 Nov 2022 11:57:36 +0800 Subject: [PATCH] Ignore warnings for window.wp in Playwright --- .../src/admin/visit-site-editor.ts | 3 --- .../src/editor/get-edited-post-content.ts | 1 - .../src/editor/insert-block.ts | 2 -- .../src/editor/set-content.ts | 2 -- .../src/editor/transform-block-to.ts | 14 ++++++-------- packages/e2e-test-utils-playwright/src/index.ts | 1 + packages/e2e-test-utils-playwright/src/types.ts | 8 ++++++++ 7 files changed, 15 insertions(+), 16 deletions(-) create mode 100644 packages/e2e-test-utils-playwright/src/types.ts diff --git a/packages/e2e-test-utils-playwright/src/admin/visit-site-editor.ts b/packages/e2e-test-utils-playwright/src/admin/visit-site-editor.ts index 17fccd4c599180..278bc341d096ee 100644 --- a/packages/e2e-test-utils-playwright/src/admin/visit-site-editor.ts +++ b/packages/e2e-test-utils-playwright/src/admin/visit-site-editor.ts @@ -38,13 +38,10 @@ export async function visitSiteEditor( if ( skipWelcomeGuide ) { await this.page.evaluate( () => { - // TODO, type `window.wp`. - // @ts-ignore window.wp.data .dispatch( 'core/preferences' ) .set( 'core/edit-site', 'welcomeGuide', false ); - // @ts-ignore window.wp.data .dispatch( 'core/preferences' ) .toggle( 'core/edit-site', 'welcomeGuideStyles', false ); diff --git a/packages/e2e-test-utils-playwright/src/editor/get-edited-post-content.ts b/packages/e2e-test-utils-playwright/src/editor/get-edited-post-content.ts index db32b4df01b6e4..1fa73270132e9f 100644 --- a/packages/e2e-test-utils-playwright/src/editor/get-edited-post-content.ts +++ b/packages/e2e-test-utils-playwright/src/editor/get-edited-post-content.ts @@ -12,7 +12,6 @@ import type { Editor } from './index'; */ export async function getEditedPostContent( this: Editor ) { return await this.page.evaluate( () => - // @ts-ignore (Reason: wp isn't typed) window.wp.data.select( 'core/editor' ).getEditedPostContent() ); } diff --git a/packages/e2e-test-utils-playwright/src/editor/insert-block.ts b/packages/e2e-test-utils-playwright/src/editor/insert-block.ts index 96138258f98135..30860dd5764af1 100644 --- a/packages/e2e-test-utils-playwright/src/editor/insert-block.ts +++ b/packages/e2e-test-utils-playwright/src/editor/insert-block.ts @@ -25,7 +25,6 @@ async function insertBlock( attributes = {}, innerBlocks = [], }: BlockRepresentation ): Object { - // @ts-ignore (Reason: wp isn't typed). return window.wp.blocks.createBlock( name, attributes, @@ -36,7 +35,6 @@ async function insertBlock( } const block = recursiveCreateBlock( _blockRepresentation ); - // @ts-ignore (Reason: wp isn't typed). window.wp.data.dispatch( 'core/block-editor' ).insertBlock( block ); }, blockRepresentation ); } diff --git a/packages/e2e-test-utils-playwright/src/editor/set-content.ts b/packages/e2e-test-utils-playwright/src/editor/set-content.ts index 04deaba6a1ad3d..790a39ddcd2d00 100644 --- a/packages/e2e-test-utils-playwright/src/editor/set-content.ts +++ b/packages/e2e-test-utils-playwright/src/editor/set-content.ts @@ -11,10 +11,8 @@ import type { Editor } from './index'; */ async function setContent( this: Editor, html: string ) { await this.page.evaluate( ( _html ) => { - // @ts-ignore (Reason: wp isn't typed). const blocks = window.wp.blocks.parse( _html ); - // @ts-ignore (Reason: wp isn't typed). window.wp.data.dispatch( 'core/block-editor' ).resetBlocks( blocks ); }, html ); } diff --git a/packages/e2e-test-utils-playwright/src/editor/transform-block-to.ts b/packages/e2e-test-utils-playwright/src/editor/transform-block-to.ts index e5f4c64d7c6bc8..dab77b852f8a77 100644 --- a/packages/e2e-test-utils-playwright/src/editor/transform-block-to.ts +++ b/packages/e2e-test-utils-playwright/src/editor/transform-block-to.ts @@ -12,20 +12,18 @@ import type { Editor } from './index'; export async function transformBlockTo( this: Editor, name: string ) { await this.page.evaluate( ( [ blockName ] ) => { - // @ts-ignore (Reason: wp isn't typed) const clientIds = window.wp.data .select( 'core/block-editor' ) .getSelectedBlockClientIds(); - // @ts-ignore (Reason: wp isn't typed) const blocks = window.wp.data .select( 'core/block-editor' ) .getBlocksByClientId( clientIds ); - // @ts-ignore (Reason: wp isn't typed) - window.wp.data.dispatch( 'core/block-editor' ).replaceBlocks( - clientIds, - // @ts-ignore (Reason: wp isn't typed) - window.wp.blocks.switchToBlockType( blocks, blockName ) - ); + window.wp.data + .dispatch( 'core/block-editor' ) + .replaceBlocks( + clientIds, + window.wp.blocks.switchToBlockType( blocks, blockName ) + ); }, [ name ] ); diff --git a/packages/e2e-test-utils-playwright/src/index.ts b/packages/e2e-test-utils-playwright/src/index.ts index a21de06b2d6e63..9f283017f10161 100644 --- a/packages/e2e-test-utils-playwright/src/index.ts +++ b/packages/e2e-test-utils-playwright/src/index.ts @@ -1,3 +1,4 @@ +export * from './types'; export { Admin } from './admin'; export { Editor } from './editor'; export { PageUtils } from './page-utils'; diff --git a/packages/e2e-test-utils-playwright/src/types.ts b/packages/e2e-test-utils-playwright/src/types.ts new file mode 100644 index 00000000000000..b642c6bd7fca73 --- /dev/null +++ b/packages/e2e-test-utils-playwright/src/types.ts @@ -0,0 +1,8 @@ +declare global { + interface Window { + // Silence the warning for `window.wp` in Playwright's evaluate functions. + wp: any; + } +} + +export {};