Skip to content

Commit

Permalink
Merge pull request #1242 from 10up/fix/e2e-tests
Browse files Browse the repository at this point in the history
Fix cypress tests
  • Loading branch information
Sidsector9 authored Aug 5, 2024
2 parents 7181cf2 + 850c691 commit ff4f06b
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ jobs:

- name: Log WP environment versions
run: |
npx wp-env run cli "wp core version"
npx wp-env run cli "php --version"
npm run env run cli -- wp core version
npm run env run cli -- php --version
- name: Test
run: npm run cypress:run
Expand Down
76 changes: 53 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"mustache": "^4.2.0"
},
"devDependencies": {
"@10up/cypress-wp-utils": "^0.2.0",
"@wordpress/env": "^5.16.0",
"@10up/cypress-wp-utils": "^0.4.0",
"@wordpress/env": "^10.1.0",
"@wordpress/scripts": "^26.19.0",
"compare-versions": "^4.1.3",
"cypress": "^13.1.0",
Expand Down Expand Up @@ -61,8 +61,8 @@
"env:start": "wp-env start",
"env:stop": "wp-env stop",
"env:destroy": "wp-env destroy",
"to-multisite": "wp-env run tests-cli \"wp core multisite-convert --title='Distributor Multisite'\"",
"copy-htaccess": "wp-env run tests-cli \"cp wp-content/plugins/distributor/tests/cypress/.htaccess .htaccess\"",
"to-multisite": "wp-env run tests-cli wp core multisite-convert --title='Distributor Multisite'",
"copy-htaccess": "wp-env run tests-cli cp wp-content/plugins/distributor/tests/cypress/.htaccess .htaccess",
"postenv:start": "./tests/bin/initialize.sh"
},
"files": [
Expand Down
18 changes: 9 additions & 9 deletions tests/bin/initialize.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#!/bin/bash
set -e

npm run env run tests-wordpress "chmod -c ugo+w /var/www/html"
npm run env run tests-cli "wp rewrite structure '/%postname%/' --hard"
wp-env run tests-wordpress chmod -c ugo+w /var/www/html
wp-env run tests-cli wp rewrite structure '/%postname%/' --hard

status=0
npm run env run tests-cli "wp site list" || status=$?
wp-env run tests-cli wp site list || status=$?

if [ $status -eq 0 ]
then
echo "Multisite already initialized"
else
echo "Converting to multisite"
npm run env run tests-cli "wp core multisite-convert --title='Distributor Multisite'"
npm run env run tests-cli "wp user create second '[email protected]' --user_pass=password --role=administrator"
npm run env run tests-cli "wp site create --slug=second --title='Second Site' --email='[email protected]'"
npm run env run tests-cli "wp theme enable twentytwentyone --activate"
npm run env run tests-cli "wp theme enable twentytwentyone --url=localhost/second --activate"
npm run env run tests-cli "cp wp-content/plugins/distributor/tests/cypress/.htaccess .htaccess"
wp-env run tests-cli wp core multisite-convert --title='Distributor Multisite'
wp-env run tests-cli wp user create second '[email protected]' --user_pass=password --role=administrator
wp-env run tests-cli wp site create --slug=second --title='Second Site' --email='[email protected]'
wp-env run tests-cli wp theme enable twentytwentyone --activate
wp-env run tests-cli wp theme enable twentytwentyone --url=localhost/second --activate
wp-env run tests-cli cp wp-content/plugins/distributor/tests/cypress/.htaccess .htaccess
fi
6 changes: 4 additions & 2 deletions tests/cypress/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { defineConfig } = require( 'cypress' );
const { readConfig } = require( '@wordpress/env/lib/config' );
const { loadConfig } = require( '@wordpress/env/lib/config' );
const getCacheDirectory = require( '@wordpress/env/lib/config/get-cache-directory' );

module.exports = defineConfig( {
chromeWebSecurity: false,
Expand Down Expand Up @@ -34,7 +35,8 @@ module.exports = defineConfig( {
* @return {Object} Updated Cypress Config object.
*/
const setBaseUrl = async ( on, config ) => {
const wpEnvConfig = await readConfig( 'wp-env' );
const cacheDirectory = await getCacheDirectory();
const wpEnvConfig = await loadConfig( cacheDirectory );

if ( wpEnvConfig ) {
const port = wpEnvConfig.env.tests.port || null;
Expand Down
6 changes: 4 additions & 2 deletions tests/cypress/e2e/internal-push.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ describe( 'Internal Push', () => {

cy.createPost( { title: postTitle, content } ).then( ( post ) => {
// Set category and tag
cy.wpCli( `post term set ${ post.id } category ${ categoryName }` );
cy.wpCli( `post term set ${ post.id } post_tag ${ tagName }` );
cy.wpCli(
`wp post term set ${ post.id } category ${ categoryName }`
);
cy.wpCli( `wp post term set ${ post.id } post_tag ${ tagName }` );

// Set post meta.
cy.wpCli(
Expand Down

0 comments on commit ff4f06b

Please sign in to comment.