Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing E2E tests on trunk #264

Merged
merged 4 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ on:
pull_request:
branches:
- develop
paths:
- '**.js'
- '**.php'
- '**.css'

jobs:
build:
Expand Down
38 changes: 38 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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",
"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",
Expand Down Expand Up @@ -48,6 +49,7 @@
"babel-eslint": "^10.0.3",
"babel-loader": "^8.0.6",
"cypress": "^11.2.0",
"cypress-iframe": "^1.0.1",
"cypress-mochawesome-reporter": "^3.5.1",
"eslint": "^6.3.0",
"husky": "^3.0.5",
Expand Down
2 changes: 1 addition & 1 deletion tests/bin/set-wp-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require( 'fs' );

const path = `${ process.cwd() }/.wp-env.json`;

let config = fs.existsSync( path ) ? require( path ) : { plugins: [ '.', 'https://downloads.wordpress.org/plugin/classic-editor.1.6.1.zip' ] };
let config = fs.existsSync( path ) ? require( path ) : { plugins: [ '.', 'https://downloads.wordpress.org/plugin/classic-editor.zip' ] };

const args = {};
process.argv
Expand Down
1 change: 1 addition & 0 deletions tests/cypress/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
35 changes: 33 additions & 2 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ Cypress.Commands.add( 'startCreatePost', () => {
const titleInput = 'h1.editor-post-title__input, #post-title-0';

// Make sure editor loaded properly.
cy.get(titleInput).should('exist');
cy.closeWelcomeGuide();
cy.getBlockEditor().find(titleInput).should('exist');

cy.get(titleInput).clear().type(`Random Post Title ${getRandomText(6)}`);
cy.getBlockEditor()
.find(titleInput)
.clear()
.type(`Random Post Title ${getRandomText(6)}`);
});


Expand Down Expand Up @@ -165,3 +168,31 @@ Cypress.Commands.add( 'publishPost', () => {
cy.get('[aria-disabled="false"].editor-post-publish-button').click();
cy.wait('@publishPost');
});

Cypress.Commands.add('getBlockEditor', () => {
cy.get('.edit-post-visual-editor').should('be.visible');
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);
});

Cypress.Commands.add('closeWelcomeGuide', () => {
cy.window().then((win) => {
const { wp } = win;
if (
wp.data
.select('core/edit-post')
.isFeatureActive('welcomeGuide')
) {
wp.data
.dispatch('core/edit-post')
.toggleFeature('welcomeGuide');
}
});
});
1 change: 1 addition & 0 deletions tests/cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import '@10up/cypress-wp-utils';
import 'cypress-iframe';
import './commands';

beforeEach(() => {
Expand Down