Skip to content

Commit

Permalink
Migrate to Cypress 10 (#74)
Browse files Browse the repository at this point in the history
* Upgrade NPM packages.

* Upgrade config file.

* Renamed test folder

* Removed plugins

* upgrade support file

* Update npm scripts.

* Test folder path update.

* downgrade typedoc package to keep doc site as it is.

* Stop video to check if it can make e2e tests fast.

* Fix test failing in 6.1

* Add dependencies back

* Fix tests.

Co-authored-by: Max Lyuchin <maxim.lyuchin@gmail.com>
  • Loading branch information
iamdharmesh and cadic authored Nov 16, 2022
1 parent 6479371 commit f716bda
Show file tree
Hide file tree
Showing 23 changed files with 669 additions and 727 deletions.
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",
"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
File renamed without changes.
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);
});

cy.get('label')
.contains('Stick to the top of the blog')
.click()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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

0 comments on commit f716bda

Please sign in to comment.