From f61ddca8f30d7288066315144bbce7684f0697c6 Mon Sep 17 00:00:00 2001 From: Bart Kalisz Date: Wed, 30 Aug 2023 16:54:41 +0200 Subject: [PATCH 1/2] Do not run page actions in beforeEach hook when using fixme --- .../e2e-test-utils-playwright/src/test.ts | 12 +++-- .../editor/various/inserting-blocks.spec.js | 52 +++++++++++++------ 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/packages/e2e-test-utils-playwright/src/test.ts b/packages/e2e-test-utils-playwright/src/test.ts index eec8e4e279c0ff..d65174f44695e5 100644 --- a/packages/e2e-test-utils-playwright/src/test.ts +++ b/packages/e2e-test-utils-playwright/src/test.ts @@ -120,9 +120,15 @@ const test = base.extend< await use( page ); // Clear local storage after each test. - await page.evaluate( () => { - window.localStorage.clear(); - } ); + // This needs to be wrapped with a try/catch because it can fail when + // the test is skipped (e.g. via fixme). + try { + await page.evaluate( () => { + window.localStorage.clear(); + } ); + } catch ( error ) { + // noop. + } await page.close(); }, diff --git a/test/e2e/specs/editor/various/inserting-blocks.spec.js b/test/e2e/specs/editor/various/inserting-blocks.spec.js index 39c159b00b75c0..822257e67deff7 100644 --- a/test/e2e/specs/editor/various/inserting-blocks.spec.js +++ b/test/e2e/specs/editor/various/inserting-blocks.spec.js @@ -15,23 +15,12 @@ test.use( { } ); test.describe( 'Inserting blocks (@firefox, @webkit)', () => { - test.beforeEach( async ( { admin, page } ) => { - await admin.createNewPost(); - // To do: some drag an drop tests are failing, so run them without - // iframe for now. - await page.evaluate( () => { - window.wp.blocks.registerBlockType( 'test/v2', { - apiVersion: '2', - title: 'test', - } ); - } ); - } ); - test.afterAll( async ( { requestUtils } ) => { await requestUtils.deleteAllPosts(); } ); test( 'inserts blocks by dragging and dropping from the global inserter', async ( { + admin, page, editor, insertingBlocksUtils, @@ -41,6 +30,9 @@ test.describe( 'Inserting blocks (@firefox, @webkit)', () => { 'The clientX value is always 0 in firefox, see https://github.com/microsoft/playwright/issues/17761 for more info.' ); + await admin.createNewPost(); + await insertingBlocksUtils.runWithoutIframe(); + // We need a dummy block in place to display the drop indicator due to a bug. // @see https://github.com/WordPress/gutenberg/issues/44064 await editor.insertBlock( { @@ -111,10 +103,14 @@ test.describe( 'Inserting blocks (@firefox, @webkit)', () => { } ); test( 'cancels dragging blocks from the global inserter by pressing Escape', async ( { + admin, page, editor, insertingBlocksUtils, } ) => { + await admin.createNewPost(); + await insertingBlocksUtils.runWithoutIframe(); + // We need a dummy block in place to display the drop indicator due to a bug. // @see https://github.com/WordPress/gutenberg/issues/44064 await editor.insertBlock( { @@ -168,6 +164,7 @@ test.describe( 'Inserting blocks (@firefox, @webkit)', () => { } ); test( 'inserts patterns by dragging and dropping from the global inserter', async ( { + admin, page, editor, insertingBlocksUtils, @@ -177,6 +174,9 @@ test.describe( 'Inserting blocks (@firefox, @webkit)', () => { 'The clientX value is always 0 in firefox, see https://github.com/microsoft/playwright/issues/17761 for more info.' ); + await admin.createNewPost(); + await insertingBlocksUtils.runWithoutIframe(); + // We need a dummy block in place to display the drop indicator due to a bug. // @see https://github.com/WordPress/gutenberg/issues/44064 await editor.insertBlock( { @@ -239,10 +239,14 @@ test.describe( 'Inserting blocks (@firefox, @webkit)', () => { } ); test( 'cancels dragging patterns from the global inserter by pressing Escape', async ( { + admin, page, editor, insertingBlocksUtils, } ) => { + await admin.createNewPost(); + await insertingBlocksUtils.runWithoutIframe(); + // We need a dummy block in place to display the drop indicator due to a bug. // @see https://github.com/WordPress/gutenberg/issues/44064 await editor.insertBlock( { @@ -300,9 +304,14 @@ test.describe( 'Inserting blocks (@firefox, @webkit)', () => { // A test for https://github.com/WordPress/gutenberg/issues/43090. test( 'should close the inserter when clicking on the toggle button', async ( { + admin, page, editor, + insertingBlocksUtils, } ) => { + await admin.createNewPost(); + await insertingBlocksUtils.runWithoutIframe(); + const inserterButton = page.getByRole( 'button', { name: 'Toggle block inserter', } ); @@ -341,13 +350,14 @@ test.describe( 'insert media from inserter', () => { requestUtils.deleteAllPosts(), ] ); } ); - test.beforeEach( async ( { admin } ) => { - await admin.createNewPost(); - } ); + test( 'insert media from the global inserter', async ( { + admin, page, editor, } ) => { + await admin.createNewPost(); + await page.click( 'role=region[name="Editor top bar"i] >> role=button[name="Toggle block inserter"i]' ); @@ -380,4 +390,16 @@ class InsertingBlocksUtils { 'data-testid=block-draggable-chip >> visible=true' ); } + + async runWithoutIframe() { + /** + * @todo Some drag an drop tests are failing, so run them without iframe for now. + */ + return await this.page.evaluate( () => { + window.wp.blocks.registerBlockType( 'test/v2', { + apiVersion: '2', + title: 'test', + } ); + } ); + } } From 5035fee69f007707c83176bd46822ca564248a07 Mon Sep 17 00:00:00 2001 From: Bart Kalisz Date: Thu, 31 Aug 2023 11:14:26 +0200 Subject: [PATCH 2/2] Revert "Attempt to fix intermittent e2e test failure (#53905)" This reverts commit 5a77e225057485e8a30335427a292c8964eed36a. --- test/e2e/playwright.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/playwright.config.ts b/test/e2e/playwright.config.ts index 2e117b9745840d..e1724a61d61263 100644 --- a/test/e2e/playwright.config.ts +++ b/test/e2e/playwright.config.ts @@ -17,7 +17,7 @@ const config = defineConfig( { forbidOnly: !! process.env.CI, workers: 1, retries: process.env.CI ? 2 : 0, - timeout: parseInt( process.env.TIMEOUT || '', 10 ) || 200_000, // Defaults to 200 seconds. + timeout: parseInt( process.env.TIMEOUT || '', 10 ) || 100_000, // Defaults to 100 seconds. // Don't report slow test "files", as we will be running our tests in serial. reportSlowTests: null, testDir: fileURLToPath( new URL( './specs', 'file:' + __filename ).href ),