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

Migrate to Cypress 10 #74

Merged
merged 13 commits into from
Nov 16, 2022
4 changes: 2 additions & 2 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ jobs:
fail-fast: false
matrix:
core:
- { name: 'WP latest', version: 'latest', number: '6.0' }
- { name: 'WP trunk', version: 'WordPress/WordPress#master', number: '6.1' }
- { name: 'WP latest', version: 'latest', number: '6.1' }
- { name: 'WP trunk', version: 'WordPress/WordPress#master', number: '6.2' }
- { name: 'WP minimum', version: 'WordPress/WordPress#5.2', number: '5.2' }
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion _templates/cypress-command/new/test.ejs.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
to: tests/cypress/integration/<%= h.changeCase.param(name) %>.test.js
to: tests/cypress/e2e/<%= h.changeCase.param(name) %>.test.js
---
describe('Command: <%= h.changeCase.camel(name) %>', () => {
it('Should be able to <%= h.changeCase.title(name) %>', () => {
Expand Down
1,230 changes: 577 additions & 653 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"prepare": "husky install",
"prettify": "prettier --write \"**/*.{ts,js}\"",
"typecheck": "tsc --noEmit",
"cypress:open": "cypress open --config-file tests/cypress/config.json",
"cypress:run": "cypress run --config-file tests/cypress/config.json",
"cypress:open": "cypress open --config-file tests/cypress/cypress-config.js --e2e --browser chrome",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use a custom script that allows the --browser parameter to be overridden when running the script?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterwilsoncc The --browser parameter was added here to the auto-select browser during the test, otherwise, we have to select the browser from UI during the run test in open mode.

Also, we can use a script like this npm run cypress:open -- --browser=firefox to select the Firefox browser or npm run cypress:open -- --browser=electron for Electron.

Should I remove the --browser parameter?

"cypress:run": "cypress run --config-file tests/cypress/cypress-config.js",
"env": "wp-env",
"env:start": "wp-env start",
"env:stop": "wp-env stop",
Expand Down Expand Up @@ -50,11 +50,11 @@
"@types/node": "^12.20.11",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"@wordpress/env": "^4.2.2",
"@wordpress/env": "^5.5.0",
"codecov": "^3.8.1",
"compare-versions": "^4.1.3",
"cypress": "^9.5.1",
"cypress-mochawesome-reporter": "^3.0.1",
"compare-versions": "^4.1.3",
"cypress": "^10.11.0",
"cypress-mochawesome-reporter": "^3.2.3",
"eslint": "^7.25.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-cypress": "^2.12.1",
Expand All @@ -72,4 +72,4 @@
"*.ts": "eslint --cache --cache-location .eslintcache --fix",
"*.{ts,js}": "prettier --write"
}
}
}
18 changes: 0 additions & 18 deletions tests/cypress/config.json

This file was deleted.

46 changes: 46 additions & 0 deletions tests/cypress/cypress-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const { defineConfig } = require('cypress');
const { readConfig } = require('@wordpress/env/lib/config');

module.exports = defineConfig({
fixturesFolder: 'tests/cypress/fixtures',
screenshotsFolder: 'tests/cypress/screenshots',
videosFolder: 'tests/cypress/videos',
downloadsFolder: 'tests/cypress/downloads',
video: false,
e2e: {
setupNodeEvents(on, config) {
return setBaseUrl(on, config);
},
specPattern: 'tests/cypress/e2e/**/*.test.{js,jsx,ts,tsx}',
supportFile: 'tests/cypress/support/e2e.js',
},
reporter: 'mochawesome',
reporterOptions: {
reportFilename: 'mochawesome-[name]',
reportDir: 'tests/cypress/reports',
overwrite: false,
html: false,
json: true,
},
});

/**
* Set WP URL as baseUrl in Cypress config.
*
* @param {Function} on function that used to register listeners on various events.
* @param {object} config Cypress Config object.
* @returns config Updated Cypress Config object.
*/
const setBaseUrl = async (on, config) => {
const wpEnvConfig = await readConfig('wp-env');

if (wpEnvConfig) {
const port = wpEnvConfig.env.tests.port || null;

if (port) {
config.baseUrl = wpEnvConfig.env.tests.config.WP_SITEURL;
}
}

return config;
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('Command: checkBlockPatternExists', () => {
it(`Pattern "${testCase.title}" ${shouldIt} exist in category "${testCase.cat}"`, () => {
// Wait for patterns to load on the post edit page.


const args = {
title: testCase.title,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,20 @@ describe('Command: createPost', () => {
title: postTitle,
content: postContent,
beforeSave: () => {
cy.openDocumentSettingsPanel('Status & visibility');
// WP 6.1 renamed the panel name "Status & visibility" to "Summary".
cy.openDocumentSettingsSidebar('Post');
cy.get('body').then($body => {
let name = 'Status & visibility';
if (
$body.find(
'.components-panel__body .components-panel__body-title button:contains("Summary")'
).length > 0
) {
name = 'Summary';
}
cy.openDocumentSettingsPanel(name);
});
Comment on lines +88 to +98
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The selector for the component hasn't changed, ie it is .components-panel .edit-post-post-status in both 6.0 and 6.1. Is it possible to use that instead?

Otherwise, maybe see if it's possible to catch the change in openDocumentSettingsPanel to maintain backward compatibility for other repos using the function. @cadic may have some thoughts here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterwilsoncc the cy.openDocumentSettingsPanel() command is using the title as identifier of the panel because in general most of panels doesn't have a unique class :(

Screenshot 2022-11-09 at 15 37 29

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it is better to catch the change in openDocumentSettingsPanel to get this maintained among other repos as well. what do you think @cadic @Sidsector9?


cy.get('label')
.contains('Stick to the top of the blog')
.click()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,27 @@ describe('Commands: openDocumentSettings*', () => {
cy.visit(`/wp-admin/post-new.php`);
cy.closeWelcomeGuide();

const name = 'Status & visibility';
cy.openDocumentSettingsPanel(name);

// Assertion: Stick to the top checkbox should be visible
cy.get('.components-panel__body .components-panel__body-title button')
.contains(name, { matchCase: false })
.then($button => {
const $panel = $button.parents('.components-panel__body');
cy.wrap($panel).should('contain', 'Stick to the top of the blog');
});
// WP 6.1 renamed the panel name "Status & visibility" to "Summary".
cy.openDocumentSettingsSidebar('Post');
cy.get('body').then($body => {
let name = 'Status & visibility';
if (
$body.find(
'.components-panel__body .components-panel__body-title button:contains("Summary")'
).length > 0
) {
name = 'Summary';
}
cy.openDocumentSettingsPanel(name);

// Assertion: Stick to the top checkbox should be visible
cy.get('.components-panel__body .components-panel__body-title button')
.contains(name, { matchCase: false })
.then($button => {
const $panel = $button.parents('.components-panel__body');
cy.wrap($panel).should('contain', 'Stick to the top of the blog');
});
});
});

it('Should be able to open Tags panel on the existing post', () => {
Expand Down
33 changes: 0 additions & 33 deletions tests/cypress/plugins/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ***********************************************************
// This example support/index.js is processed and
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
Expand Down