Skip to content

Commit

Permalink
add wpLogin and add to each tests beforeEach
Browse files Browse the repository at this point in the history
  • Loading branch information
circlecube committed Nov 8, 2024
1 parent 2a75130 commit ebefd99
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 19 deletions.
1 change: 1 addition & 0 deletions tests/cypress/integration/help.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const pluginProductsFixture = require( '../fixtures/plugin-products.json' );

describe( 'Help Page', { testIsolation: true }, function () {
beforeEach( () => {
cy.wpLogin();
cy.intercept(
{
method: 'GET',
Expand Down
1 change: 1 addition & 0 deletions tests/cypress/integration/home.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe( 'Home Page', { testIsolation: true }, function () {
let NewfoldRuntime;

beforeEach( () => {
cy.wpLogin();
cy.visit(
'/wp-admin/admin.php?page=' + Cypress.env( 'pluginId' ) + '#/home'
);
Expand Down
1 change: 1 addition & 0 deletions tests/cypress/integration/navigation.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

describe( 'Navigation', { testIsolation: true }, function () {
beforeEach( () => {
cy.wpLogin();
cy.visit( '/wp-admin/admin.php?page=' + Cypress.env( 'pluginId' ) );
} );

Expand Down
3 changes: 2 additions & 1 deletion tests/cypress/integration/pages-and-posts.cy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
describe( 'Pages & Posts', { testIsolation: true }, function () {
let NewfoldRuntime;

before( () => {
beforeEach( () => {
cy.wpLogin();
cy.visit(
'/wp-admin/admin.php?page=' +
Cypress.env( 'pluginId' ) +
Expand Down
1 change: 1 addition & 0 deletions tests/cypress/integration/settings.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

describe( 'Settings Page', { testIsolation: true }, function () {
beforeEach( () => {
cy.wpLogin();
cy.visit(
'/wp-admin/admin.php?page=' +
Cypress.env( 'pluginId' ) +
Expand Down
2 changes: 1 addition & 1 deletion tests/cypress/integration/version-check.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe( 'Page', { testIsolation: true }, () => {
beforeEach( () => {
cy.login();
cy.wpLogin();
cy.visit( '/wp-admin/site-health.php?tab=debug' );
} );

Expand Down
36 changes: 21 additions & 15 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ Cypress.Commands.add( 'login', ( username, password ) => {
} );
} );

Cypress.Commands.add( 'wpLogin', () => {
cy.login( Cypress.env( 'wpUsername' ), Cypress.env( 'wpPassword' ) );
} );

Cypress.Commands.add( 'logout', () => {
cy.getCookies().then( ( cookies ) => {
cookies.forEach( ( cookie ) => {
Expand All @@ -58,26 +62,28 @@ Cypress.Commands.add( 'logout', () => {
Cypress.Commands.add(
'setPermalinkStructure',
( structure = '/%postname%/' ) => {
cy.request({
cy.request( {
method: 'GET',
url: '/wp-json/',
failOnStatusCode: false,
}).then(result => {
if(result.isOkStatusCode) {
} ).then( ( result ) => {
if ( result.isOkStatusCode ) {
return;
}
const permalinkWpCliCommand = `wp rewrite structure "${structure}" --hard;`;
const permalinkWpEnvCommand = `npx wp-env run cli ${permalinkWpCliCommand}`;
const permalinkWpEnvTestCommand = `npx wp-env run tests-cli ${permalinkWpCliCommand}`;
cy.exec( permalinkWpEnvCommand, {failOnNonZeroExit: true})
.then((result) => {
cy.request('/wp-json/');
});
cy.exec( permalinkWpEnvTestCommand, {failOnNonZeroExit: true})
.then((result) => {
cy.request('/wp-json/');
});
});
const permalinkWpCliCommand = `wp rewrite structure "${ structure }" --hard;`;
const permalinkWpEnvCommand = `npx wp-env run cli ${ permalinkWpCliCommand }`;
const permalinkWpEnvTestCommand = `npx wp-env run tests-cli ${ permalinkWpCliCommand }`;
cy.exec( permalinkWpEnvCommand, { failOnNonZeroExit: true } ).then(
( result ) => {
cy.request( '/wp-json/' );
}
);
cy.exec( permalinkWpEnvTestCommand, {
failOnNonZeroExit: true,
} ).then( ( result ) => {
cy.request( '/wp-json/' );
} );
} );
}
);

Expand Down
7 changes: 5 additions & 2 deletions tests/cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Cypress.on( 'uncaught:exception', ( err ) => {
}
} );

beforeEach( () => {
cy.login( Cypress.env( 'wpUsername' ), Cypress.env( 'wpPassword' ) );
// This needs to remain until all tests have been updated with testIsolation:
// at that point this can be updated to a beforeEach and testIsolation can be
// removed from the config as the default is true.
before( () => {
cy.wpLogin();
} );

0 comments on commit ebefd99

Please sign in to comment.