From 69edc4386d834f63f6a2c9e25da0bb46d1e3c2e6 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar <8456197+kirtangajjar@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:47:51 +0530 Subject: [PATCH 1/5] Fix cypress tests --- .github/workflows/cypress.yml | 4 +-- package-lock.json | 62 ++++++++++++++++++++++++++--------- package.json | 6 ++-- tests/bin/initialize.sh | 18 +++++----- tests/cypress/config.js | 6 ++-- 5 files changed, 64 insertions(+), 32 deletions(-) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 65ef3ed29..20939439a 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -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" + npx wp-env run cli wp core version + npx wp-env run cli php --version - name: Test run: npm run cypress:run diff --git a/package-lock.json b/package-lock.json index a90feccc9..f472e27ab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,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", @@ -4814,14 +4814,14 @@ } }, "node_modules/@wordpress/env": { - "version": "5.16.0", - "resolved": "https://registry.npmjs.org/@wordpress/env/-/env-5.16.0.tgz", - "integrity": "sha512-zx6UO8PuJBrQ34cfeedK1HlGHLFaj7oWzTo9tTt+noB79Ttqc4+a0lYwDqBLLJhlHU+cWgcyOP2lB6TboXH0xA==", + "version": "10.2.0", + "resolved": "https://registry.npmjs.org/@wordpress/env/-/env-10.2.0.tgz", + "integrity": "sha512-EToZYPGXpl42Asw3bxpX8aKmHfRUdGxKPjQ9CHZVQoTAL27Af4FyjyGnepsnDpnYdIeI8VPb2S3k2NL/1+fpIA==", "dev": true, "dependencies": { "chalk": "^4.0.0", "copy-dir": "^1.3.0", - "docker-compose": "^0.22.2", + "docker-compose": "^0.24.3", "extract-zip": "^1.6.7", "got": "^11.8.5", "inquirer": "^7.1.0", @@ -4834,6 +4834,10 @@ }, "bin": { "wp-env": "bin/wp-env" + }, + "engines": { + "node": ">=18.12.0", + "npm": ">=8.19.2" } }, "node_modules/@wordpress/eslint-plugin": { @@ -8388,14 +8392,29 @@ } }, "node_modules/docker-compose": { - "version": "0.22.2", - "resolved": "https://registry.npmjs.org/docker-compose/-/docker-compose-0.22.2.tgz", - "integrity": "sha512-iXWb5+LiYmylIMFXvGTYsjI1F+Xyx78Jm/uj1dxwwZLbWkUdH6yOXY5Nr3RjbYX15EgbGJCq78d29CmWQQQMPg==", + "version": "0.24.8", + "resolved": "https://registry.npmjs.org/docker-compose/-/docker-compose-0.24.8.tgz", + "integrity": "sha512-plizRs/Vf15H+GCVxq2EUvyPK7ei9b/cVesHvjnX4xaXjM9spHe2Ytq0BitndFgvTJ3E3NljPNUEl7BAN43iZw==", "dev": true, + "dependencies": { + "yaml": "^2.2.2" + }, "engines": { "node": ">= 6.0.0" } }, + "node_modules/docker-compose/node_modules/yaml": { + "version": "2.4.5", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.4.5.tgz", + "integrity": "sha512-aBx2bnqDzVOyNKfsysjA2ms5ZlnjSAW2eG3/L5G/CSujfjLJTJsEw1bGw8kCf04KodQWk1pxlGnZ56CRxiawmg==", + "dev": true, + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -24809,14 +24828,14 @@ } }, "@wordpress/env": { - "version": "5.16.0", - "resolved": "https://registry.npmjs.org/@wordpress/env/-/env-5.16.0.tgz", - "integrity": "sha512-zx6UO8PuJBrQ34cfeedK1HlGHLFaj7oWzTo9tTt+noB79Ttqc4+a0lYwDqBLLJhlHU+cWgcyOP2lB6TboXH0xA==", + "version": "10.2.0", + "resolved": "https://registry.npmjs.org/@wordpress/env/-/env-10.2.0.tgz", + "integrity": "sha512-EToZYPGXpl42Asw3bxpX8aKmHfRUdGxKPjQ9CHZVQoTAL27Af4FyjyGnepsnDpnYdIeI8VPb2S3k2NL/1+fpIA==", "dev": true, "requires": { "chalk": "^4.0.0", "copy-dir": "^1.3.0", - "docker-compose": "^0.22.2", + "docker-compose": "^0.24.3", "extract-zip": "^1.6.7", "got": "^11.8.5", "inquirer": "^7.1.0", @@ -27471,10 +27490,21 @@ } }, "docker-compose": { - "version": "0.22.2", - "resolved": "https://registry.npmjs.org/docker-compose/-/docker-compose-0.22.2.tgz", - "integrity": "sha512-iXWb5+LiYmylIMFXvGTYsjI1F+Xyx78Jm/uj1dxwwZLbWkUdH6yOXY5Nr3RjbYX15EgbGJCq78d29CmWQQQMPg==", - "dev": true + "version": "0.24.8", + "resolved": "https://registry.npmjs.org/docker-compose/-/docker-compose-0.24.8.tgz", + "integrity": "sha512-plizRs/Vf15H+GCVxq2EUvyPK7ei9b/cVesHvjnX4xaXjM9spHe2Ytq0BitndFgvTJ3E3NljPNUEl7BAN43iZw==", + "dev": true, + "requires": { + "yaml": "^2.2.2" + }, + "dependencies": { + "yaml": { + "version": "2.4.5", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.4.5.tgz", + "integrity": "sha512-aBx2bnqDzVOyNKfsysjA2ms5ZlnjSAW2eG3/L5G/CSujfjLJTJsEw1bGw8kCf04KodQWk1pxlGnZ56CRxiawmg==", + "dev": true + } + } }, "doctrine": { "version": "3.0.0", diff --git a/package.json b/package.json index d39ed73c8..c512c5a3a 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": [ diff --git a/tests/bin/initialize.sh b/tests/bin/initialize.sh index 06c8cae4f..4d2e7d920 100755 --- a/tests/bin/initialize.sh +++ b/tests/bin/initialize.sh @@ -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 +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 'second@admin.local' --user_pass=password --role=administrator" - npm run env run tests-cli "wp site create --slug=second --title='Second Site' --email='second@admin.local'" - 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 'second@admin.local' --user_pass=password --role=administrator + npx wp-env run tests-cli wp site create --slug=second --title='Second Site' --email='second@admin.local' + 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 diff --git a/tests/cypress/config.js b/tests/cypress/config.js index 103de3a39..1d34e7abf 100644 --- a/tests/cypress/config.js +++ b/tests/cypress/config.js @@ -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, @@ -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; From 5f10990f095a9623e591330ddd084f140bf404f7 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar <8456197+kirtangajjar@users.noreply.github.com> Date: Tue, 9 Jul 2024 15:59:26 +0530 Subject: [PATCH 2/5] Correct CLI commands --- .github/workflows/cypress.yml | 4 ++-- tests/bin/initialize.sh | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 20939439a..0cb7316c7 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -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 diff --git a/tests/bin/initialize.sh b/tests/bin/initialize.sh index 4d2e7d920..7b15041c6 100755 --- a/tests/bin/initialize.sh +++ b/tests/bin/initialize.sh @@ -1,21 +1,21 @@ #!/bin/bash set -e -npx wp-env run tests-wordpress chmod -c ugo+w /var/www/html -npx wp-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 -npx wp-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" - npx wp-env run tests-cli wp core multisite-convert --title='Distributor Multisite' - npx wp-env run tests-cli wp user create second 'second@admin.local' --user_pass=password --role=administrator - npx wp-env run tests-cli wp site create --slug=second --title='Second Site' --email='second@admin.local' - 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 + wp-env run tests-cli wp core multisite-convert --title='Distributor Multisite' + wp-env run tests-cli wp user create second 'second@admin.local' --user_pass=password --role=administrator + wp-env run tests-cli wp site create --slug=second --title='Second Site' --email='second@admin.local' + 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 From c8b9c23026447174a534972e7cb7cfac024491f1 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar <8456197+kirtangajjar@users.noreply.github.com> Date: Wed, 31 Jul 2024 02:55:28 +0530 Subject: [PATCH 3/5] update @10up/cypress-wp-utils to 0.4.0 --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index f472e27ab..20615fc32 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "mustache": "^4.2.0" }, "devDependencies": { - "@10up/cypress-wp-utils": "^0.2.0", + "@10up/cypress-wp-utils": "^0.4.0", "@wordpress/env": "^10.1.0", "@wordpress/scripts": "^26.19.0", "compare-versions": "^4.1.3", @@ -30,9 +30,9 @@ } }, "node_modules/@10up/cypress-wp-utils": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@10up/cypress-wp-utils/-/cypress-wp-utils-0.2.0.tgz", - "integrity": "sha512-5gzamtHIFojT+wx0OzSAEeVY6FVrlcVPHVFH23uExkaqQhNsJvrnpdtqtT98wAYkXg56c1qDN7Ju7ZRTaNzP5g==", + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@10up/cypress-wp-utils/-/cypress-wp-utils-0.4.0.tgz", + "integrity": "sha512-7cNELIX6ml5V9JEU83iEyQ6dkZ77ImdR5HKjUP4oyArQogPVcFPUnokU7GInH8DicqXbESrrkxZ0IfnNtNWh+A==", "dev": true, "engines": { "node": ">=12.0" @@ -21259,9 +21259,9 @@ }, "dependencies": { "@10up/cypress-wp-utils": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@10up/cypress-wp-utils/-/cypress-wp-utils-0.2.0.tgz", - "integrity": "sha512-5gzamtHIFojT+wx0OzSAEeVY6FVrlcVPHVFH23uExkaqQhNsJvrnpdtqtT98wAYkXg56c1qDN7Ju7ZRTaNzP5g==", + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@10up/cypress-wp-utils/-/cypress-wp-utils-0.4.0.tgz", + "integrity": "sha512-7cNELIX6ml5V9JEU83iEyQ6dkZ77ImdR5HKjUP4oyArQogPVcFPUnokU7GInH8DicqXbESrrkxZ0IfnNtNWh+A==", "dev": true }, "@ampproject/remapping": { diff --git a/package.json b/package.json index c512c5a3a..823127fcd 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "mustache": "^4.2.0" }, "devDependencies": { - "@10up/cypress-wp-utils": "^0.2.0", + "@10up/cypress-wp-utils": "^0.4.0", "@wordpress/env": "^10.1.0", "@wordpress/scripts": "^26.19.0", "compare-versions": "^4.1.3", From 6f54ad0bd939fb2e0c9a99f771c6c5983902fa54 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar <8456197+kirtangajjar@users.noreply.github.com> Date: Wed, 31 Jul 2024 03:20:56 +0530 Subject: [PATCH 4/5] Update tests --- tests/cypress/e2e/internal-push.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cypress/e2e/internal-push.test.js b/tests/cypress/e2e/internal-push.test.js index b3169fdd6..39353a0d5 100644 --- a/tests/cypress/e2e/internal-push.test.js +++ b/tests/cypress/e2e/internal-push.test.js @@ -48,8 +48,8 @@ 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( From c3b2dc428cdcb4efe6be18afe47ce62f1c987819 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar <8456197+kirtangajjar@users.noreply.github.com> Date: Wed, 31 Jul 2024 03:34:20 +0530 Subject: [PATCH 5/5] Fix eslint issue --- tests/cypress/e2e/internal-push.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/cypress/e2e/internal-push.test.js b/tests/cypress/e2e/internal-push.test.js index 39353a0d5..f882203b8 100644 --- a/tests/cypress/e2e/internal-push.test.js +++ b/tests/cypress/e2e/internal-push.test.js @@ -48,7 +48,9 @@ describe( 'Internal Push', () => { cy.createPost( { title: postTitle, content } ).then( ( post ) => { // Set category and tag - cy.wpCli( `wp post term set ${ post.id } category ${ categoryName }` ); + cy.wpCli( + `wp post term set ${ post.id } category ${ categoryName }` + ); cy.wpCli( `wp post term set ${ post.id } post_tag ${ tagName }` ); // Set post meta.