From ac7b87c91de32c587d01884d70336afb18737385 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Wed, 31 Jan 2024 16:31:52 -0800 Subject: [PATCH] Fix pretty permalink setup --- tests/cypress/support/commands.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index b15dac9b6..44c73615a 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -58,7 +58,26 @@ Cypress.Commands.add( 'logout', () => { Cypress.Commands.add( 'setPermalinkStructure', ( structure = '/%postname%/' ) => { - cy.exec( `npx wp-env run cli wp rewrite structure "${ structure }"` ); + cy.request({ + method: 'GET', + url: '/wp-json/', + failOnStatusCode: false, + }).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/'); + }); + }); } );