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

Upgrade to Cypress 13 #110

Merged
merged 4 commits into from
Aug 30, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
233 changes: 125 additions & 108 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@wordpress/env": "^5.5.0",
"codecov": "^3.8.1",
"compare-versions": "^4.1.3",
"cypress": "^10.11.0",
"cypress": "^13.0.0",
"cypress-mochawesome-reporter": "^3.2.3",
"eslint": "^7.25.0",
"eslint-config-prettier": "^8.3.0",
Expand Down
31 changes: 17 additions & 14 deletions src/commands/check-block-pattern-exists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,33 @@ export const checkBlockPatternExists = ({
return new Promise(resolve => {
let elapsed = 0;

setInterval(function () {
const inverval = setInterval(function () {
if (elapsed > 2500) {
clearInterval(inverval);
resolve(false);
}

const { wp } = win;

const { getSettings } = wp.data.select('core/block-editor');
const allRegisteredPatterns =
getSettings().__experimentalBlockPatterns;
const getSettings =
wp?.data?.select('core/block-editor')?.getSettings;
if (undefined !== getSettings) {
const allRegisteredPatterns =
getSettings().__experimentalBlockPatterns;

if (undefined !== allRegisteredPatterns) {
for (let i = 0; i < allRegisteredPatterns.length; i++) {
if (
title === allRegisteredPatterns[i].title &&
allRegisteredPatterns[i].categories &&
allRegisteredPatterns[i].categories.includes(categoryValue)
) {
resolve(true);
return;
if (undefined !== allRegisteredPatterns) {
for (let i = 0; i < allRegisteredPatterns.length; i++) {
if (
title === allRegisteredPatterns[i].title &&
allRegisteredPatterns[i].categories &&
allRegisteredPatterns[i].categories.includes(categoryValue)
) {
resolve(true);
return;
}
}
}
}

elapsed += 100;
}, 100);
});
Expand Down
16 changes: 9 additions & 7 deletions src/commands/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
* ```
*/
export const login = (username = 'admin', password = 'password'): void => {
cy.visit('/wp-admin/');
cy.get('body').then($body => {
if ($body.find('#wpwrap').length == 0) {
cy.get('input#user_login').clear();
cy.get('input#user_login').click().type(username);
cy.get('input#user_pass').type(`${password}{enter}`);
}
cy.session([username, password], () => {
cy.visit('/wp-admin/');
cy.get('body').then($body => {
if ($body.find('#wpwrap').length == 0) {
cy.get('input#user_login').clear();
cy.get('input#user_login').click().type(username);
cy.get('input#user_pass').type(`${password}{enter}`);
}
});
});
};
5 changes: 5 additions & 0 deletions tests/cypress/e2e/check-block-pattern-exists.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ describe('Command: checkBlockPatternExists', () => {
before(() => {
cy.login();
cy.deactivatePlugin('classic-editor');
});

beforeEach(() => {
cy.login();
cy.visit('/wp-admin/post-new.php');
cy.get('.edit-post-header').should('exist');
cy.closeWelcomeGuide();
});

Expand Down
4 changes: 4 additions & 0 deletions tests/cypress/e2e/check-post-exists.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ describe('Command: checkPostExists', () => {
});
});

beforeEach(() => {
cy.login();
});

// Run the tests again after seeding posts to ensure we get the correct response.
tests.forEach(test => {
const shouldIt = test.expected ? 'should' : 'should not';
Expand Down
4 changes: 4 additions & 0 deletions tests/cypress/e2e/classic-create-post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ describe('Command: classicCreatePost', () => {
cy.activatePlugin('classic-editor');
});

beforeEach(() => {
cy.login();
});

it('Should be able to Classic Create Post', () => {
const title = 'Title ' + randomName();
const content = 'Content ' + randomName();
Expand Down
4 changes: 4 additions & 0 deletions tests/cypress/e2e/close-welcome-guide.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ describe('Command: closeWelcomeGuide', () => {
});
});

beforeEach(() => {
cy.login();
});

it('Should be able to Close Welcome Guide', () => {
const welcomeGuideWindow = '.edit-post-welcome-guide';

Expand Down
4 changes: 4 additions & 0 deletions tests/cypress/e2e/create-post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ describe('Command: createPost', () => {
});
});

beforeEach(() => {
cy.login();
});

it('Should be able to create Post', () => {
const title = 'Test Post';
cy.createPost({
Expand Down
5 changes: 1 addition & 4 deletions tests/cypress/e2e/create-term.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
const { randomName } = require('../support/functions');

describe('Command: createTerm', () => {
before(() => {
cy.login();
});

beforeEach(() => {
cy.login();
cy.deleteAllTerms();
cy.deleteAllTerms('post_tag');
});
Expand Down
3 changes: 2 additions & 1 deletion tests/cypress/e2e/delete-all-terms.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
describe('Command: deleteAllTerms', () => {
before(() => {
beforeEach(() => {
cy.login();
});

after(() => {
cy.login();
// Restore default 20 items per page
cy.visit(`/wp-admin/edit-tags.php?taxonomy=category`);
cy.get('#show-settings-link').click();
Expand Down
4 changes: 4 additions & 0 deletions tests/cypress/e2e/insert-block.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ describe('Command: insertBlock', () => {
});
});

beforeEach(() => {
cy.login();
});

it('Should be able to Insert first paragraph on page', () => {
const paragraph = 'Paragraph ' + randomName();
cy.createPost({
Expand Down
1 change: 1 addition & 0 deletions tests/cypress/e2e/login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe('Command: login', () => {

it('Login admin by default', () => {
cy.login();
cy.visit('/wp-admin');
cy.get('h1').should('contain', 'Dashboard');
});
});
4 changes: 4 additions & 0 deletions tests/cypress/e2e/open-document-settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ describe('Commands: openDocumentSettings*', () => {
});
});

beforeEach(() => {
cy.login();
});

it("Should be able to open (don't close) Status Panel on a new post", () => {
cy.visit(`/wp-admin/post-new.php`);
cy.closeWelcomeGuide();
Expand Down
2 changes: 1 addition & 1 deletion tests/cypress/e2e/plugins.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Plugins commands', () => {
before(() => {
beforeEach(() => {
cy.login();
});

Expand Down
2 changes: 1 addition & 1 deletion tests/cypress/e2e/set-permalink-structure.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Command: setPermalinkStructure', () => {
before(() => {
beforeEach(() => {
cy.login();
});

Expand Down
2 changes: 1 addition & 1 deletion tests/cypress/e2e/upload-media.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Command: uploadMedia', () => {
before(() => {
beforeEach(() => {
cy.login();
});

Expand Down
8 changes: 0 additions & 8 deletions tests/cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,3 @@

// Import commands.js using ES2015 syntax:
import '../../../lib/index';

// Alternatively you can use CommonJS syntax:
// require('./commands')
beforeEach(() => {
Cypress.Cookies.defaults({
preserve: /^wordpress.*?/,
});
});
Loading