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

Fix cypress tests #1242

Merged
merged 10 commits into from
Aug 5, 2024
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
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"
iamdharmesh marked this conversation as resolved.
Show resolved Hide resolved
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
Loading