From e51459a30fab9a469cdeb9dfdd4b16a45ac57d6a Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Mon, 21 Aug 2023 14:23:15 -0600 Subject: [PATCH 01/18] Add the Cypress iframe package to better work with iframes --- package-lock.json | 38 ++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 39 insertions(+) diff --git a/package-lock.json b/package-lock.json index 24b2e74..42ef971 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "codecov": "^3.8.1", "compare-versions": "^4.1.3", "cypress": "^10.11.0", + "cypress-iframe": "^1.0.1", "cypress-mochawesome-reporter": "^3.2.3", "eslint": "^7.25.0", "eslint-config-prettier": "^8.3.0", @@ -350,6 +351,17 @@ "@types/responselike": "*" } }, + "node_modules/@types/cypress": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@types/cypress/-/cypress-1.1.3.tgz", + "integrity": "sha512-OXe0Gw8LeCflkG1oPgFpyrYWJmEKqYncBsD/J0r17r0ETx/TnIGDNLwXt/pFYSYuYTpzcq1q3g62M9DrfsBL4g==", + "deprecated": "This is a stub types definition for cypress (https://cypress.io). cypress provides its own type definitions, so you don't need @types/cypress installed!", + "dev": true, + "peer": true, + "dependencies": { + "cypress": "*" + } + }, "node_modules/@types/http-cache-semantics": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz", @@ -1551,6 +1563,15 @@ "node": ">=12.0.0" } }, + "node_modules/cypress-iframe": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/cypress-iframe/-/cypress-iframe-1.0.1.tgz", + "integrity": "sha512-Ne+xkZmWMhfq3x6wbfzK/SzsVTCrJru3R3cLXsoSAZyfUtJDamXyaIieHXeea3pQDXF4wE2w4iUuvCYHhoD31g==", + "dev": true, + "peerDependencies": { + "@types/cypress": "^1.1.0" + } + }, "node_modules/cypress-mochawesome-reporter": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/cypress-mochawesome-reporter/-/cypress-mochawesome-reporter-3.2.3.tgz", @@ -6721,6 +6742,16 @@ "@types/responselike": "*" } }, + "@types/cypress": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@types/cypress/-/cypress-1.1.3.tgz", + "integrity": "sha512-OXe0Gw8LeCflkG1oPgFpyrYWJmEKqYncBsD/J0r17r0ETx/TnIGDNLwXt/pFYSYuYTpzcq1q3g62M9DrfsBL4g==", + "dev": true, + "peer": true, + "requires": { + "cypress": "*" + } + }, "@types/http-cache-semantics": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz", @@ -7664,6 +7695,13 @@ } } }, + "cypress-iframe": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/cypress-iframe/-/cypress-iframe-1.0.1.tgz", + "integrity": "sha512-Ne+xkZmWMhfq3x6wbfzK/SzsVTCrJru3R3cLXsoSAZyfUtJDamXyaIieHXeea3pQDXF4wE2w4iUuvCYHhoD31g==", + "dev": true, + "requires": {} + }, "cypress-mochawesome-reporter": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/cypress-mochawesome-reporter/-/cypress-mochawesome-reporter-3.2.3.tgz", diff --git a/package.json b/package.json index 7905813..4dedae8 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "codecov": "^3.8.1", "compare-versions": "^4.1.3", "cypress": "^10.11.0", + "cypress-iframe": "^1.0.1", "cypress-mochawesome-reporter": "^3.2.3", "eslint": "^7.25.0", "eslint-config-prettier": "^8.3.0", From 5cbf1c85fa910dfa8c250771180b1118102f5b4b Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Mon, 21 Aug 2023 14:27:10 -0600 Subject: [PATCH 02/18] Import the iframe package. Add our custom getBlockEditor command --- src/commands/get-block-editor.ts | 25 +++++++++++++++++++++++++ src/index.ts | 5 +++++ 2 files changed, 30 insertions(+) create mode 100644 src/commands/get-block-editor.ts diff --git a/src/commands/get-block-editor.ts b/src/commands/get-block-editor.ts new file mode 100644 index 0000000..374d110 --- /dev/null +++ b/src/commands/get-block-editor.ts @@ -0,0 +1,25 @@ +/** + * Get the Block Editor + * + * @returns Block Editor element. + * + * @example + * Find the title input and type in it + * ``` + * cy.getBlockEditor().find('.editor-post-title__input').type('Test Post'); + * ``` + */ +export const getBlockEditor = (): Cypress.Chainable => { + // Ensure the editor is loaded. + cy.get('.edit-post-visual-editor').should('exist'); + + return cy + .get('body') + .then($body => { + if ($body.find('iframe[name="editor-canvas"]').length) { + return cy.iframe('iframe[name="editor-canvas"]'); + } + return $body; + }) + .then(cy.wrap); // eslint-disable-line @typescript-eslint/unbound-method +}; diff --git a/src/index.ts b/src/index.ts index a711e7e..9565c57 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,8 @@ /* eslint-disable @typescript-eslint/no-namespace */ /// +import 'cypress-iframe'; + // Import commands. import { checkPostExists } from './commands/check-post-exists'; import { classicCreatePost } from './commands/classic-create-post'; @@ -23,6 +25,7 @@ import { login } from './commands/login'; import { createPost } from './commands/create-post'; import { uploadMedia } from './commands/upload-media'; import { checkSitemap } from './commands/check-sitemap-exists'; +import { getBlockEditor } from './commands/get-block-editor'; declare global { namespace Cypress { @@ -48,6 +51,7 @@ declare global { logout: typeof logout; login: typeof login; checkSitemap: typeof checkSitemap; + getBlockEditor: typeof getBlockEditor; } } } @@ -77,3 +81,4 @@ Cypress.Commands.add('uploadMedia', uploadMedia); Cypress.Commands.add('logout', logout); Cypress.Commands.add('login', login); Cypress.Commands.add('checkSitemap', checkSitemap); +Cypress.Commands.add('getBlockEditor', getBlockEditor); From fdd1bbff99476dd74efe70796061c5df626cfb29 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Mon, 21 Aug 2023 14:28:08 -0600 Subject: [PATCH 03/18] Use the new getBlockEditor function in createPost and closeWelcomeGuide to ensure these both work on WP 6.3 and below --- src/commands/close-welcome-guide.ts | 2 +- src/commands/create-post.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/commands/close-welcome-guide.ts b/src/commands/close-welcome-guide.ts index b1081ee..e03f82a 100644 --- a/src/commands/close-welcome-guide.ts +++ b/src/commands/close-welcome-guide.ts @@ -12,7 +12,7 @@ export const closeWelcomeGuide = (): void => { '.edit-post-welcome-guide .components-modal__header button'; // Wait for edit page to load - cy.get(titleInput).should('exist'); + cy.getBlockEditor().find(titleInput).should('exist'); cy.get('body').then($body => { if ($body.find(closeButtonSelector).length > 0) { diff --git a/src/commands/create-post.ts b/src/commands/create-post.ts index e226474..570f206 100644 --- a/src/commands/create-post.ts +++ b/src/commands/create-post.ts @@ -67,20 +67,20 @@ export const createPost = ({ const titleInput = 'h1.editor-post-title__input, #post-title-0'; const contentInput = '.block-editor-default-block-appender__content'; - // Make sure editor loaded properly. - cy.get(contentInput).should('exist'); - // Close Welcome Guide. cy.closeWelcomeGuide(); // Fill out data. if (title.length > 0) { - cy.get(titleInput).clear().type(title); + cy.getBlockEditor().find(titleInput).clear().type(title); } if (content.length > 0) { - cy.get(contentInput).click(); - cy.get('.block-editor-rich-text__editable').first().type(content); + cy.getBlockEditor().find(contentInput).click(); + cy.getBlockEditor() + .find('.block-editor-rich-text__editable') + .first() + .type(content); } if ('undefined' !== typeof beforeSave) { From 3333ff52f510f9fdfe52e6844b0d70206af276db Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Mon, 21 Aug 2023 14:28:34 -0600 Subject: [PATCH 04/18] Ensure Cypress loads the block editor iframe --- tests/cypress/cypress-config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cypress/cypress-config.js b/tests/cypress/cypress-config.js index c0bda23..e48c608 100644 --- a/tests/cypress/cypress-config.js +++ b/tests/cypress/cypress-config.js @@ -2,6 +2,7 @@ const { defineConfig } = require('cypress'); const { readConfig } = require('@wordpress/env/lib/config'); module.exports = defineConfig({ + chromeWebSecurity: false, fixturesFolder: 'tests/cypress/fixtures', screenshotsFolder: 'tests/cypress/screenshots', videosFolder: 'tests/cypress/videos', From 3f5965e19180f93d748fbf0910b8ae7f2370c4ae Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Mon, 21 Aug 2023 21:47:51 -0600 Subject: [PATCH 05/18] Ensure our insertBlock command works properly in the iframe editor --- src/commands/insert-block.ts | 58 +++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/src/commands/insert-block.ts b/src/commands/insert-block.ts index e69eb13..9368a51 100644 --- a/src/commands/insert-block.ts +++ b/src/commands/insert-block.ts @@ -43,10 +43,7 @@ export const insertBlock = (type: string, name?: string): void => { '.edit-post-header-toolbar__inserter-toggle, .edit-post-header-toolbar .block-editor-inserter__toggle' ).click(); - cy.get('.block-editor-inserter__search') - .click() - .type(search) - .type('{enter}', { delay: 500 }); + cy.get('.block-editor-inserter__search').click().type(search); // Insert the block cy.get(`.editor-block-list-item-${slug}, .editor-block-list-item-${slugAlt}`) @@ -69,21 +66,46 @@ export const insertBlock = (type: string, name?: string): void => { const blockTypeAlt = type.replace('/', '-'); // Get last block of the current type + // Pull from the iframe editor first, if it exists cy.get('body').then($body => { - if ($body.find(`.wp-block[data-type="${blockType}"]`).length > 0) { - cy.get(`.wp-block[data-type="${blockType}"]`) - .last() - .then(block => { - const id = block.prop('id'); - cy.wrap(id); - }); - } else if ($body.find(`.wp-block[data-type="${blockTypeAlt}"]`)) { - cy.get(`.wp-block[data-type="${blockTypeAlt}"]`) - .last() - .then(block => { - const id = block.prop('id'); - cy.wrap(id); - }); + if ($body.find('iframe[name="editor-canvas"]').length) { + cy.iframe('iframe[name="editor-canvas"]').then($iframe => { + if ($iframe.find(`.wp-block[data-type="${blockType}"]`).length > 0) { + cy.iframe('iframe[name="editor-canvas"]') + .find(`.wp-block[data-type="${blockType}"]`) + .last() + .then(block => { + const id = block.prop('id'); + cy.wrap(id); + }); + } else if ( + $iframe.find(`.wp-block[data-type="${blockTypeAlt}"]`).length + ) { + cy.iframe('iframe[name="editor-canvas"]') + .find(`.wp-block[data-type="${blockTypeAlt}"]`) + .last() + .then(block => { + const id = block.prop('id'); + cy.wrap(id); + }); + } + }); + } else { + if ($body.find(`.wp-block[data-type="${blockType}"]`).length > 0) { + cy.get(`.wp-block[data-type="${blockType}"]`) + .last() + .then(block => { + const id = block.prop('id'); + cy.wrap(id); + }); + } else if ($body.find(`.wp-block[data-type="${blockTypeAlt}"]`)) { + cy.get(`.wp-block[data-type="${blockTypeAlt}"]`) + .last() + .then(block => { + const id = block.prop('id'); + cy.wrap(id); + }); + } } }); }; From 9b6bd85bffc10ffa0672967c5f0b95816d47a8e1 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Mon, 21 Aug 2023 21:48:21 -0600 Subject: [PATCH 06/18] Update the insertBlock tests to account for iframed editor --- tests/cypress/e2e/insert-block.test.js | 36 ++++++++++++++++---------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/tests/cypress/e2e/insert-block.test.js b/tests/cypress/e2e/insert-block.test.js index a8815ee..6ffd5e7 100644 --- a/tests/cypress/e2e/insert-block.test.js +++ b/tests/cypress/e2e/insert-block.test.js @@ -22,12 +22,14 @@ describe('Command: insertBlock', () => { cy.createPost({ beforeSave: () => { cy.insertBlock('core/paragraph').then(id => { - cy.get(`#${id}`).click().type(paragraph); + cy.getBlockEditor().find(`#${id}`).click().type(paragraph); }); }, }); - cy.get('.block-editor-writing-flow').should('contain.text', paragraph); + cy.getBlockEditor() + .find('.wp-block-post-content') + .should('contain.text', paragraph); }); it('Should be able to Insert Heading', () => { @@ -35,12 +37,14 @@ describe('Command: insertBlock', () => { cy.createPost({ beforeSave: () => { cy.insertBlock('core/heading').then(id => { - cy.get(`#${id}`).click().type(heading); + cy.getBlockEditor().find(`#${id}`).click().type(heading); }); }, }); - cy.get('.block-editor-writing-flow h2').should('contain.text', heading); + cy.getBlockEditor() + .find('.wp-block-post-content h2') + .should('contain.text', heading); }); it('Should be able to insert Pullquote', () => { @@ -49,21 +53,24 @@ describe('Command: insertBlock', () => { cy.createPost({ beforeSave: () => { cy.insertBlock('core/pullquote').then(id => { - cy.get( - `#${id} [aria-label="Pullquote text"], #${id} [aria-label="Write quote…"]` - ) + cy.getBlockEditor() + .find( + `#${id} [aria-label="Pullquote text"], #${id} [aria-label="Write quote…"]` + ) .click() .type(quote); - cy.get( - `#${id} [aria-label="Pullquote citation text"], #${id} [aria-label="Write citation…"]` - ) + cy.getBlockEditor() + .find( + `#${id} [aria-label="Pullquote citation text"], #${id} [aria-label="Write citation…"]` + ) .click() .type(cite); }); }, }); - cy.get('.wp-block-pullquote') + cy.getBlockEditor() + .find('.wp-block-pullquote') .should('contain.text', quote) .should('contain.text', cite); }); @@ -75,7 +82,9 @@ describe('Command: insertBlock', () => { }, }); - cy.get('.wp-block-embed').should('contain.text', 'Twitter'); + cy.getBlockEditor() + .find('.wp-block-embed') + .should('contain.text', 'Twitter'); }); it('Should be able to insert custom block', () => { @@ -91,7 +100,8 @@ describe('Command: insertBlock', () => { }, }); - cy.get('.wp-block-tenup-winamp-block') + cy.getBlockEditor() + .find('.wp-block-tenup-winamp-block') .should('contain.text', 'Add Audio') .should('have.attr', 'data-type') .and('eq', 'tenup/winamp-block'); From 1dd897c4789dab442e7641719ee50031f490d8f0 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Mon, 21 Aug 2023 22:15:55 -0600 Subject: [PATCH 07/18] Fix the openDocumentSettings test --- .../e2e/open-document-settings.test.js | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/tests/cypress/e2e/open-document-settings.test.js b/tests/cypress/e2e/open-document-settings.test.js index e5c86a2..d0b809e 100644 --- a/tests/cypress/e2e/open-document-settings.test.js +++ b/tests/cypress/e2e/open-document-settings.test.js @@ -129,13 +129,32 @@ describe('Commands: openDocumentSettings*', () => { cy.closeWelcomeGuide(); cy.get('body').then($body => { - if ($body.find('.wp-block-post-content > .wp-block').length > 0) { - cy.get('.wp-block-post-content > .wp-block').first().click(); + if ($body.find('iframe[name="editor-canvas"]').length) { + if ( + cy + .iframe('iframe[name="editor-canvas"]') + .find('.wp-block-post-content > .wp-block').length > 0 + ) { + cy.iframe('iframe[name="editor-canvas"]') + .find('.wp-block-post-content > .wp-block') + .first() + .click(); + } else { + // Fallback for WordPress 5.7 + cy.iframe('iframe[name="editor-canvas"]') + .find('.block-editor-block-list__layout > .wp-block') + .first() + .click(); + } } else { - // Fallback for WordPress 5.7 - cy.get('.block-editor-block-list__layout > .wp-block') - .first() - .click(); + if ($body.find('.wp-block-post-content > .wp-block').length > 0) { + cy.get('.wp-block-post-content > .wp-block').first().click(); + } else { + // Fallback for WordPress 5.7 + cy.get('.block-editor-block-list__layout > .wp-block') + .first() + .click(); + } } }); From ecdda8f9d63a8304ef87cd0e79fed6d027f141a8 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Mon, 21 Aug 2023 22:22:32 -0600 Subject: [PATCH 08/18] Update actions; update WP core versions --- .github/workflows/cypress.yml | 14 +++++++------- run-all-cores.sh | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 4ccfbbb..252dd30 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -17,9 +17,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - id: changed-files - uses: tj-actions/changed-files@v18.7 + uses: tj-actions/changed-files@v37 with: files: | .github/workflows/cypress.yml @@ -37,7 +37,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Cache Node uses: actions/cache@v3 with: @@ -65,12 +65,12 @@ jobs: fail-fast: false matrix: core: - - { name: 'WP latest', version: 'latest', number: '6.1' } - - { name: 'WP trunk', version: 'WordPress/WordPress#master', number: '6.2' } + - { name: 'WP latest', version: 'latest', number: 'latest' } + - { name: 'WP trunk', version: 'WordPress/WordPress#master', number: '6.3' } - { name: 'WP minimum', version: 'WordPress/WordPress#5.7', number: '5.7' } steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Cache Node uses: actions/cache@v3 with: @@ -100,7 +100,7 @@ jobs: npx mochawesome-report-generator tests/cypress/reports/mochawesome.json -o tests/cypress/reports/ cat ./tests/cypress/reports/mochawesome.md >> $GITHUB_STEP_SUMMARY - name: Make artifacts available - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: failure() with: name: cypress-artifact diff --git a/run-all-cores.sh b/run-all-cores.sh index 6d0f01c..245c6b3 100755 --- a/run-all-cores.sh +++ b/run-all-cores.sh @@ -1,6 +1,6 @@ #!/bin/bash -VERSIONS="5.7 5.8 5.9 6.0 6.1 master:6.2" +VERSIONS="5.7 5.8 5.9 6.0 6.1 6.2 master:6.3" SPEC="-- --quiet" From 4cb1c14a551571ce9ad4afedd797ee6b8d6706c5 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Tue, 22 Aug 2023 08:47:54 -0600 Subject: [PATCH 09/18] Fix a few failing tests. Ensure we don't always have the Winamp plugin active. Update the README --- .github/workflows/cypress.yml | 2 +- .wp-env.json | 6 ++++-- README.md | 7 ++++--- package.json | 1 + tests/cypress/e2e/insert-block.test.js | 8 ++++++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 252dd30..3e1a6ed 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -65,7 +65,7 @@ jobs: fail-fast: false matrix: core: - - { name: 'WP latest', version: 'latest', number: 'latest' } + - { name: 'WP latest', version: 'latest', number: '6.3' } - { name: 'WP trunk', version: 'WordPress/WordPress#master', number: '6.3' } - { name: 'WP minimum', version: 'WordPress/WordPress#5.7', number: '5.7' } steps: diff --git a/.wp-env.json b/.wp-env.json index c75b262..a0287c3 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -1,9 +1,11 @@ { "plugins": [ ".", - "WordPress/classic-editor", - "https://github.com/10up/retro-winamp-block/releases/download/1.0.1/retro-winamp-block.zip" + "WordPress/classic-editor" ], + "mappings": { + "wp-content/plugins/retro-winamp-block": "https://github.com/10up/retro-winamp-block/releases/download/1.0.1/retro-winamp-block.zip" + }, "env": { "tests": { "mappings": { diff --git a/README.md b/README.md index 825e2f5..915eb33 100644 --- a/README.md +++ b/README.md @@ -61,12 +61,13 @@ npm i -D path/to/the/library ### Test against every WordPress major release -For every incoming pull request by default on GitHub Actions we automatically perform tests against: -- current minimum supported WordPress 5.2 +Every incoming pull request will automatically run tests against: + +- our current minimum supported WordPress version, 5.7 - WordPress [latest release](https://github.com/WordPress/WordPress/tags) - current WordPress [future release](https://github.com/WordPress/WordPress/tree/master) -To run tests locally against every WordPress major release since minimum support (5.2) to the latest nightly build (e.g., 6.0-alpha) use this script: +To run tests locally against every WordPress major release since minimum support (5.7) to the latest nightly build (e.g., 6.4s-alpha) use this script: ```sh ./run-all-cores.sh diff --git a/package.json b/package.json index 4dedae8..bb49522 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "env": "wp-env", "env:start": "wp-env start", "env:stop": "wp-env stop", + "env:destroy": "wp-env destroy", "postenv:start": "./tests/bin/initialize.sh" }, "repository": { diff --git a/tests/cypress/e2e/insert-block.test.js b/tests/cypress/e2e/insert-block.test.js index 6ffd5e7..b360d7e 100644 --- a/tests/cypress/e2e/insert-block.test.js +++ b/tests/cypress/e2e/insert-block.test.js @@ -28,7 +28,7 @@ describe('Command: insertBlock', () => { }); cy.getBlockEditor() - .find('.wp-block-post-content') + .find('.wp-block-post-content, .block-editor-writing-flow') .should('contain.text', paragraph); }); @@ -43,7 +43,7 @@ describe('Command: insertBlock', () => { }); cy.getBlockEditor() - .find('.wp-block-post-content h2') + .find('.wp-block-post-content h2, .block-editor-writing-flow h2') .should('contain.text', heading); }); @@ -94,6 +94,8 @@ describe('Command: insertBlock', () => { return; } + cy.activatePlugin('retro-winamp-block'); + cy.createPost({ beforeSave: () => { cy.insertBlock('tenup/winamp-block', 'WinAmp'); @@ -105,5 +107,7 @@ describe('Command: insertBlock', () => { .should('contain.text', 'Add Audio') .should('have.attr', 'data-type') .and('eq', 'tenup/winamp-block'); + + cy.deactivatePlugin('retro-winamp-block'); }); }); From 9f2b7ec243d4a876e86be57794fad45ebf6863aa Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Tue, 22 Aug 2023 11:21:02 -0600 Subject: [PATCH 10/18] Update README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 915eb33..f86327d 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ## Prerequisites -This library requires Cypress. Use [@10up/cypress-wp-setup](https://github.com/10up/cypress-wp-setup) to set up Cypress automatically, including this library. +This library requires Cypress. Use [@10up/cypress-wp-setup](https://github.com/10up/cypress-wp-setup) to set up Cypress automatically, including this library. If running tests against WordPress 6.3, you'll probably need to set `chromeWebSecurity: false` in your Cypress config file. This allows Cypress to properly interact with the iframed Block Editor. ## Installation @@ -23,7 +23,7 @@ Import the libary in `support/index.js` file: import '@10up/cypress-wp-utils'; ``` -Documentation for commands can be found at https://10up.github.io/cypress-wp-utils/. +Documentation for commands can be found at [https://10up.github.io/cypress-wp-utils/](https://10up.github.io/cypress-wp-utils/). ### IntelliSense and code completion for Cypress commands @@ -47,7 +47,7 @@ This project uses `hygen` to scaffold new commands to reduce the effort of manua $ npx hygen cypress-command new customCommand Loaded templates: _templates - added: src/commands/custom-command.ts + added: src/commands/custom-command.ts inject: src/index.ts inject: src/index.ts inject: src/index.ts @@ -67,7 +67,7 @@ Every incoming pull request will automatically run tests against: - WordPress [latest release](https://github.com/WordPress/WordPress/tags) - current WordPress [future release](https://github.com/WordPress/WordPress/tree/master) -To run tests locally against every WordPress major release since minimum support (5.7) to the latest nightly build (e.g., 6.4s-alpha) use this script: +To run tests locally against every WordPress major release since minimum support (5.7) to the latest nightly build (e.g., 6.4-alpha) use this script: ```sh ./run-all-cores.sh From f37dd54e194431da0fbdd8e3c8c21aadaad23024 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Tue, 22 Aug 2023 13:00:13 -0600 Subject: [PATCH 11/18] Add back code to delay searching for blocks to see if it fixes an issue --- src/commands/insert-block.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/commands/insert-block.ts b/src/commands/insert-block.ts index 9368a51..191e90c 100644 --- a/src/commands/insert-block.ts +++ b/src/commands/insert-block.ts @@ -43,7 +43,10 @@ export const insertBlock = (type: string, name?: string): void => { '.edit-post-header-toolbar__inserter-toggle, .edit-post-header-toolbar .block-editor-inserter__toggle' ).click(); - cy.get('.block-editor-inserter__search').click().type(search); + cy.get('.block-editor-inserter__search') + .click() + .type(search) + .type('{enter}', { delay: 500 }); // Insert the block cy.get(`.editor-block-list-item-${slug}, .editor-block-list-item-${slugAlt}`) From 64c629d71eba06080cbf1d3422d9e769ca447b7d Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Wed, 23 Aug 2023 12:57:12 +0530 Subject: [PATCH 12/18] Run tests on chrome. --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index bb49522..9b45a19 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "prettify": "prettier --write \"**/*.{ts,js}\"", "typecheck": "tsc --noEmit", "cypress:open": "cypress open --config-file tests/cypress/cypress-config.js --e2e --browser chrome", - "cypress:run": "cypress run --config-file tests/cypress/cypress-config.js", + "cypress:run": "cypress run --config-file tests/cypress/cypress-config.js --e2e --browser chrome", "env": "wp-env", "env:start": "wp-env start", "env:stop": "wp-env stop", @@ -76,4 +76,4 @@ "lib": "lib", "test": "tests" } -} +} \ No newline at end of file From 2b91e02ab82883ed4f26f83a43a8122bf7eb9da4 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Wed, 23 Aug 2023 13:29:56 -0600 Subject: [PATCH 13/18] Remove block patterns before opening the inserter. Add them back once inserter has been closed --- src/commands/insert-block.ts | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/commands/insert-block.ts b/src/commands/insert-block.ts index 191e90c..af22da6 100644 --- a/src/commands/insert-block.ts +++ b/src/commands/insert-block.ts @@ -1,5 +1,3 @@ -import { fail } from 'assert'; - /** * Inserts Block * @@ -38,6 +36,24 @@ export const insertBlock = (type: string, name?: string): void => { } } + // Remove block patterns + /* eslint-disable */ + let patterns: any[] = []; + cy.window() + .then(win => { + const settings = win.wp.data.select('core/block-editor').getSettings(); + patterns = settings?.__experimentalBlockPatterns || []; + if (patterns.length > 0) { + win.wp.data + .select('core/block-editor') + .getSettings().__experimentalBlockPatterns = []; + } + }) + .as('patternsRemoved'); + /* eslint-enable */ + + cy.wait('@patternsRemoved'); + // Open blocks panel cy.get( '.edit-post-header-toolbar__inserter-toggle, .edit-post-header-toolbar .block-editor-inserter__toggle' @@ -63,6 +79,19 @@ export const insertBlock = (type: string, name?: string): void => { } }); + // Add patterns back + /* eslint-disable */ + cy.window() + .then(win => { + win.wp.data + .select('core/block-editor') + .getSettings().__experimentalBlockPatterns = patterns || []; + }) + .as('patternsAdded'); + /* eslint-enable */ + + cy.wait('@patternsAdded'); + // Remove tailing suffix of sub-blocks const blockType = type.replace(/^(.*?)\/(.*?)\/[^/]+$/, '$1/$2'); From a7055af94c069b0b3eae9d2ed8b8ed97343bd29d Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Wed, 23 Aug 2023 13:30:27 -0600 Subject: [PATCH 14/18] Change back to not running tests in the browser --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9b45a19..d8013c2 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "prettify": "prettier --write \"**/*.{ts,js}\"", "typecheck": "tsc --noEmit", "cypress:open": "cypress open --config-file tests/cypress/cypress-config.js --e2e --browser chrome", - "cypress:run": "cypress run --config-file tests/cypress/cypress-config.js --e2e --browser chrome", + "cypress:run": "cypress run --config-file tests/cypress/cypress-config.js", "env": "wp-env", "env:start": "wp-env start", "env:stop": "wp-env stop", From cb60d39542ca537617e7d2e5248f6f9c7a6353f5 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Wed, 23 Aug 2023 13:42:43 -0600 Subject: [PATCH 15/18] Change how we wait --- src/commands/insert-block.ts | 40 ++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/commands/insert-block.ts b/src/commands/insert-block.ts index af22da6..5656fba 100644 --- a/src/commands/insert-block.ts +++ b/src/commands/insert-block.ts @@ -39,20 +39,18 @@ export const insertBlock = (type: string, name?: string): void => { // Remove block patterns /* eslint-disable */ let patterns: any[] = []; - cy.window() - .then(win => { - const settings = win.wp.data.select('core/block-editor').getSettings(); - patterns = settings?.__experimentalBlockPatterns || []; - if (patterns.length > 0) { - win.wp.data - .select('core/block-editor') - .getSettings().__experimentalBlockPatterns = []; - } - }) - .as('patternsRemoved'); - /* eslint-enable */ + cy.window().then(win => { + const settings = win.wp.data.select('core/block-editor').getSettings(); + patterns = settings?.__experimentalBlockPatterns || []; + if (patterns.length > 0) { + win.wp.data + .select('core/block-editor') + .getSettings().__experimentalBlockPatterns = []; + } + }); - cy.wait('@patternsRemoved'); + cy.wait(500); + /* eslint-enable */ // Open blocks panel cy.get( @@ -81,16 +79,14 @@ export const insertBlock = (type: string, name?: string): void => { // Add patterns back /* eslint-disable */ - cy.window() - .then(win => { - win.wp.data - .select('core/block-editor') - .getSettings().__experimentalBlockPatterns = patterns || []; - }) - .as('patternsAdded'); - /* eslint-enable */ + cy.window().then(win => { + win.wp.data + .select('core/block-editor') + .getSettings().__experimentalBlockPatterns = patterns || []; + }); - cy.wait('@patternsAdded'); + cy.wait(500); + /* eslint-enable */ // Remove tailing suffix of sub-blocks const blockType = type.replace(/^(.*?)\/(.*?)\/[^/]+$/, '$1/$2'); From 64570a7f677369457ad0fd06b3abc5995d95c5a3 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Wed, 23 Aug 2023 14:35:25 -0600 Subject: [PATCH 16/18] Simplify code a bit --- src/commands/insert-block.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/commands/insert-block.ts b/src/commands/insert-block.ts index 5656fba..c36456c 100644 --- a/src/commands/insert-block.ts +++ b/src/commands/insert-block.ts @@ -39,13 +39,12 @@ export const insertBlock = (type: string, name?: string): void => { // Remove block patterns /* eslint-disable */ let patterns: any[] = []; + let settings: any = {}; cy.window().then(win => { - const settings = win.wp.data.select('core/block-editor').getSettings(); + settings = win.wp.data.select('core/block-editor').getSettings(); patterns = settings?.__experimentalBlockPatterns || []; if (patterns.length > 0) { - win.wp.data - .select('core/block-editor') - .getSettings().__experimentalBlockPatterns = []; + settings.__experimentalBlockPatterns = []; } }); @@ -78,15 +77,10 @@ export const insertBlock = (type: string, name?: string): void => { }); // Add patterns back - /* eslint-disable */ - cy.window().then(win => { - win.wp.data - .select('core/block-editor') - .getSettings().__experimentalBlockPatterns = patterns || []; - }); - - cy.wait(500); - /* eslint-enable */ + if (patterns.length > 0) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + settings.__experimentalBlockPatterns = patterns; + } // Remove tailing suffix of sub-blocks const blockType = type.replace(/^(.*?)\/(.*?)\/[^/]+$/, '$1/$2'); From ca15b425490e613b1ede151fef676a50b3d21c72 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Wed, 23 Aug 2023 21:49:40 -0600 Subject: [PATCH 17/18] Add note in README about installing the cypress-iframe package --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f86327d..a6fbff4 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ## Prerequisites -This library requires Cypress. Use [@10up/cypress-wp-setup](https://github.com/10up/cypress-wp-setup) to set up Cypress automatically, including this library. If running tests against WordPress 6.3, you'll probably need to set `chromeWebSecurity: false` in your Cypress config file. This allows Cypress to properly interact with the iframed Block Editor. +This library requires Cypress. Use [@10up/cypress-wp-setup](https://github.com/10up/cypress-wp-setup) to set up Cypress automatically, including this library. If running tests against WordPress 6.3, you'll also need to install the [Cypress iframe package](https://gitlab.com/kgroat/cypress-iframe) and you'll probably need to set `chromeWebSecurity: false` in your Cypress config file. This allows Cypress to properly interact with the iframed Block Editor. ## Installation @@ -14,6 +14,12 @@ This library requires Cypress. Use [@10up/cypress-wp-setup](https://github.com/1 npm install @10up/cypress-wp-utils --save-dev ``` +If needed, install the Cypress iframe package: + +```sh +npm install cypress-iframe --save-dev +``` + ## Usage Import the libary in `support/index.js` file: From 8370fa11fd07df7c2fa4a61008d58aa7f2ed4259 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Thu, 24 Aug 2023 09:49:10 -0600 Subject: [PATCH 18/18] Remove the use of the cypress iframe package and instead copy the code we need from that into our utils. This means other projects don't have to load that same dependency for things to work --- README.md | 8 +- package-lock.json | 38 ------ package.json | 3 +- src/commands/get-block-editor.ts | 4 +- src/commands/insert-block.ts | 8 +- src/functions/get-iframe.ts | 119 ++++++++++++++++++ src/index.ts | 13 +- .../e2e/open-document-settings.test.js | 11 +- 8 files changed, 146 insertions(+), 58 deletions(-) create mode 100644 src/functions/get-iframe.ts diff --git a/README.md b/README.md index a6fbff4..f86327d 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ## Prerequisites -This library requires Cypress. Use [@10up/cypress-wp-setup](https://github.com/10up/cypress-wp-setup) to set up Cypress automatically, including this library. If running tests against WordPress 6.3, you'll also need to install the [Cypress iframe package](https://gitlab.com/kgroat/cypress-iframe) and you'll probably need to set `chromeWebSecurity: false` in your Cypress config file. This allows Cypress to properly interact with the iframed Block Editor. +This library requires Cypress. Use [@10up/cypress-wp-setup](https://github.com/10up/cypress-wp-setup) to set up Cypress automatically, including this library. If running tests against WordPress 6.3, you'll probably need to set `chromeWebSecurity: false` in your Cypress config file. This allows Cypress to properly interact with the iframed Block Editor. ## Installation @@ -14,12 +14,6 @@ This library requires Cypress. Use [@10up/cypress-wp-setup](https://github.com/1 npm install @10up/cypress-wp-utils --save-dev ``` -If needed, install the Cypress iframe package: - -```sh -npm install cypress-iframe --save-dev -``` - ## Usage Import the libary in `support/index.js` file: diff --git a/package-lock.json b/package-lock.json index 42ef971..24b2e74 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,6 @@ "codecov": "^3.8.1", "compare-versions": "^4.1.3", "cypress": "^10.11.0", - "cypress-iframe": "^1.0.1", "cypress-mochawesome-reporter": "^3.2.3", "eslint": "^7.25.0", "eslint-config-prettier": "^8.3.0", @@ -351,17 +350,6 @@ "@types/responselike": "*" } }, - "node_modules/@types/cypress": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/@types/cypress/-/cypress-1.1.3.tgz", - "integrity": "sha512-OXe0Gw8LeCflkG1oPgFpyrYWJmEKqYncBsD/J0r17r0ETx/TnIGDNLwXt/pFYSYuYTpzcq1q3g62M9DrfsBL4g==", - "deprecated": "This is a stub types definition for cypress (https://cypress.io). cypress provides its own type definitions, so you don't need @types/cypress installed!", - "dev": true, - "peer": true, - "dependencies": { - "cypress": "*" - } - }, "node_modules/@types/http-cache-semantics": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz", @@ -1563,15 +1551,6 @@ "node": ">=12.0.0" } }, - "node_modules/cypress-iframe": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/cypress-iframe/-/cypress-iframe-1.0.1.tgz", - "integrity": "sha512-Ne+xkZmWMhfq3x6wbfzK/SzsVTCrJru3R3cLXsoSAZyfUtJDamXyaIieHXeea3pQDXF4wE2w4iUuvCYHhoD31g==", - "dev": true, - "peerDependencies": { - "@types/cypress": "^1.1.0" - } - }, "node_modules/cypress-mochawesome-reporter": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/cypress-mochawesome-reporter/-/cypress-mochawesome-reporter-3.2.3.tgz", @@ -6742,16 +6721,6 @@ "@types/responselike": "*" } }, - "@types/cypress": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/@types/cypress/-/cypress-1.1.3.tgz", - "integrity": "sha512-OXe0Gw8LeCflkG1oPgFpyrYWJmEKqYncBsD/J0r17r0ETx/TnIGDNLwXt/pFYSYuYTpzcq1q3g62M9DrfsBL4g==", - "dev": true, - "peer": true, - "requires": { - "cypress": "*" - } - }, "@types/http-cache-semantics": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz", @@ -7695,13 +7664,6 @@ } } }, - "cypress-iframe": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/cypress-iframe/-/cypress-iframe-1.0.1.tgz", - "integrity": "sha512-Ne+xkZmWMhfq3x6wbfzK/SzsVTCrJru3R3cLXsoSAZyfUtJDamXyaIieHXeea3pQDXF4wE2w4iUuvCYHhoD31g==", - "dev": true, - "requires": {} - }, "cypress-mochawesome-reporter": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/cypress-mochawesome-reporter/-/cypress-mochawesome-reporter-3.2.3.tgz", diff --git a/package.json b/package.json index d8013c2..4943a3a 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,6 @@ "codecov": "^3.8.1", "compare-versions": "^4.1.3", "cypress": "^10.11.0", - "cypress-iframe": "^1.0.1", "cypress-mochawesome-reporter": "^3.2.3", "eslint": "^7.25.0", "eslint-config-prettier": "^8.3.0", @@ -76,4 +75,4 @@ "lib": "lib", "test": "tests" } -} \ No newline at end of file +} diff --git a/src/commands/get-block-editor.ts b/src/commands/get-block-editor.ts index 374d110..85fc868 100644 --- a/src/commands/get-block-editor.ts +++ b/src/commands/get-block-editor.ts @@ -1,3 +1,5 @@ +import { getIframe } from '../functions/get-iframe'; + /** * Get the Block Editor * @@ -17,7 +19,7 @@ export const getBlockEditor = (): Cypress.Chainable => { .get('body') .then($body => { if ($body.find('iframe[name="editor-canvas"]').length) { - return cy.iframe('iframe[name="editor-canvas"]'); + return getIframe('iframe[name="editor-canvas"]'); } return $body; }) diff --git a/src/commands/insert-block.ts b/src/commands/insert-block.ts index c36456c..bd18cd2 100644 --- a/src/commands/insert-block.ts +++ b/src/commands/insert-block.ts @@ -1,3 +1,5 @@ +import { getIframe } from '../functions/get-iframe'; + /** * Inserts Block * @@ -91,9 +93,9 @@ export const insertBlock = (type: string, name?: string): void => { // Pull from the iframe editor first, if it exists cy.get('body').then($body => { if ($body.find('iframe[name="editor-canvas"]').length) { - cy.iframe('iframe[name="editor-canvas"]').then($iframe => { + getIframe('iframe[name="editor-canvas"]').then($iframe => { if ($iframe.find(`.wp-block[data-type="${blockType}"]`).length > 0) { - cy.iframe('iframe[name="editor-canvas"]') + getIframe('iframe[name="editor-canvas"]') .find(`.wp-block[data-type="${blockType}"]`) .last() .then(block => { @@ -103,7 +105,7 @@ export const insertBlock = (type: string, name?: string): void => { } else if ( $iframe.find(`.wp-block[data-type="${blockTypeAlt}"]`).length ) { - cy.iframe('iframe[name="editor-canvas"]') + getIframe('iframe[name="editor-canvas"]') .find(`.wp-block[data-type="${blockTypeAlt}"]`) .last() .then(block => { diff --git a/src/functions/get-iframe.ts b/src/functions/get-iframe.ts new file mode 100644 index 0000000..73878fc --- /dev/null +++ b/src/functions/get-iframe.ts @@ -0,0 +1,119 @@ +/** + * Code taken from the Cypress iframe package. + * + * https://gitlab.com/kgroat/cypress-iframe + */ + +const DEFAULT_OPTS: Cypress.Loggable & Cypress.Timeoutable = { + log: true, + timeout: 30000, +}; + +const DEFAULT_IFRAME_SELECTOR = 'iframe'; + +function sleep(timeout: number) { + return new Promise(resolve => setTimeout(resolve, timeout)); +} + +const frameLoaded: Cypress.Chainable['frameLoaded'] = ( + selector?: string | Partial, + opts?: Partial +) => { + if (selector === undefined) { + selector = DEFAULT_IFRAME_SELECTOR; + } else if (typeof selector === 'object') { + opts = selector; + selector = DEFAULT_IFRAME_SELECTOR; + } + + const fullOpts: Cypress.IframeOptions = { + ...DEFAULT_OPTS, + ...opts, + }; + + const log = fullOpts.log + ? Cypress.log({ + name: 'frame loaded', + displayName: 'frame loaded', + message: [selector], + }).snapshot() + : null; + + return cy + .get(selector, { log: false }) + .then( + { timeout: fullOpts.timeout }, + async ($frame: JQuery) => { + log?.set('$el', $frame); + + if ($frame.length !== 1) { + throw new Error( + `cypress-iframe commands can only be applied to exactly one iframe at a time. Instead found ${$frame.length}` + ); + } + + const contentWindow: Window = $frame.prop('contentWindow'); + + const hasNavigated = fullOpts.url + ? () => + typeof fullOpts.url === 'string' + ? contentWindow.location.toString().includes(fullOpts.url) + : fullOpts.url?.test(contentWindow.location.toString()) + : () => contentWindow.location.toString() !== 'about:blank'; + + while (!hasNavigated()) { + await sleep(100); + } + + if (contentWindow.document.readyState === 'complete') { + return $frame; + } + + const loadLog = Cypress.log({ + name: 'Frame Load', + message: [contentWindow.location.toString()], + event: true, + } as any).snapshot(); + + await new Promise(resolve => { + Cypress.$(contentWindow).on('load', resolve); + }); + + loadLog.end(); + log?.finish(); + + return $frame; + } + ); +}; + +export const getIframe: Cypress.Chainable['iframe'] = ( + selector?: string | Partial, + opts?: Partial +) => { + if (selector === undefined) { + selector = DEFAULT_IFRAME_SELECTOR; + } else if (typeof selector === 'object') { + opts = selector; + selector = DEFAULT_IFRAME_SELECTOR; + } + + const fullOpts: Cypress.IframeOptions = { + ...DEFAULT_OPTS, + ...opts, + }; + + const log = fullOpts.log + ? Cypress.log({ + name: 'iframe', + displayName: 'iframe', + message: [selector], + }).snapshot() + : null; + + return frameLoaded(selector, { ...fullOpts, log: false }).then($frame => { + log?.set('$el', $frame).end(); + const contentWindow: Window = $frame.prop('contentWindow'); + return Cypress.$(contentWindow.document.body as HTMLBodyElement); + }); +}; diff --git a/src/index.ts b/src/index.ts index 9565c57..d8fbbef 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,6 @@ /* eslint-disable @typescript-eslint/no-namespace */ /// -import 'cypress-iframe'; - // Import commands. import { checkPostExists } from './commands/check-post-exists'; import { classicCreatePost } from './commands/classic-create-post'; @@ -52,6 +50,17 @@ declare global { login: typeof login; checkSitemap: typeof checkSitemap; getBlockEditor: typeof getBlockEditor; + frameLoaded: IframeHandler>; + iframe: IframeHandler>; + } + + interface IframeHandler { + (options?: Partial): Chainable; + (selector: string, options?: Partial): Chainable; + } + + interface IframeOptions extends Loggable, Timeoutable { + url?: RegExp | string; } } } diff --git a/tests/cypress/e2e/open-document-settings.test.js b/tests/cypress/e2e/open-document-settings.test.js index d0b809e..ead0168 100644 --- a/tests/cypress/e2e/open-document-settings.test.js +++ b/tests/cypress/e2e/open-document-settings.test.js @@ -1,4 +1,5 @@ const { randomName } = require('../support/functions'); +import { getIframe } from '../../../lib/functions/get-iframe'; describe('Commands: openDocumentSettings*', () => { before(() => { @@ -131,17 +132,17 @@ describe('Commands: openDocumentSettings*', () => { cy.get('body').then($body => { if ($body.find('iframe[name="editor-canvas"]').length) { if ( - cy - .iframe('iframe[name="editor-canvas"]') - .find('.wp-block-post-content > .wp-block').length > 0 + getIframe('iframe[name="editor-canvas"]').find( + '.wp-block-post-content > .wp-block' + ).length > 0 ) { - cy.iframe('iframe[name="editor-canvas"]') + getIframe('iframe[name="editor-canvas"]') .find('.wp-block-post-content > .wp-block') .first() .click(); } else { // Fallback for WordPress 5.7 - cy.iframe('iframe[name="editor-canvas"]') + getIframe('iframe[name="editor-canvas"]') .find('.block-editor-block-list__layout > .wp-block') .first() .click();