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 1 commit
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"
npx wp-env run cli wp core version
npx wp-env run cli php --version

- name: Test
run: npm run cypress:run
Expand Down
62 changes: 46 additions & 16 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"devDependencies": {
"@10up/cypress-wp-utils": "^0.2.0",
"@wordpress/env": "^5.16.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"
npx wp-env run tests-wordpress chmod -c ugo+w /var/www/html
kirtangajjar marked this conversation as resolved.
Show resolved Hide resolved
npx wp-env run tests-cli wp rewrite structure '/%postname%/' --hard

status=0
npm run env run tests-cli "wp site list" || status=$?
npx 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"
npx wp-env run tests-cli wp core multisite-convert --title='Distributor Multisite'
npx wp-env run tests-cli wp user create second '[email protected]' --user_pass=password --role=administrator
npx wp-env run tests-cli wp site create --slug=second --title='Second Site' --email='[email protected]'
npx wp-env run tests-cli wp theme enable twentytwentyone --activate
npx wp-env run tests-cli wp theme enable twentytwentyone --url=localhost/second --activate
npx 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
Loading