From 91f8a95385b2440a888cd4a153f0816907d34105 Mon Sep 17 00:00:00 2001 From: Noah Allen Date: Wed, 8 Jul 2020 12:08:07 -0700 Subject: [PATCH 01/11] Use local wp-env sourcecode for test-unit-php script --- docs/contributors/testing-overview.md | 11 ++++++++++- package.json | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/contributors/testing-overview.md b/docs/contributors/testing-overview.md index d02d4cd15a657c..7460249eabef0f 100644 --- a/docs/contributors/testing-overview.md +++ b/docs/contributors/testing-overview.md @@ -453,7 +453,16 @@ Every core block is required to have at least one set of fixture files for its m ## PHP Testing -Tests for PHP use [PHPUnit](https://phpunit.de/) as the testing framework. If you're using the built-in [local environment](/docs/contributors/getting-started.md#local-environment), you can run the PHP tests locally using this command: +Tests for PHP use [PHPUnit](https://phpunit.de/) as the testing framework. If you're using the built-in [local environment](/docs/contributors/getting-started.md#local-environment), you can run the PHP tests locally using this command. + +Note that these commands require the local environment to be initalized first: + +```bash +# Reference the local sourcecode for wp-env in the Gutenberg repo: +npx wp-env start +``` + +Using `npx` above ensures that we always use the latest wp-env sourcecode in the Gutenberg repo. ```bash npm run test-php diff --git a/package.json b/package.json index 962eb596afbd0c..b899fae229806e 100644 --- a/package.json +++ b/package.json @@ -251,8 +251,8 @@ "test-unit:debug": "wp-scripts --inspect-brk test-unit-js --runInBand --no-cache --verbose --config test/unit/jest.config.js ", "test-unit:update": "npm run test-unit -- --updateSnapshot", "test-unit:watch": "npm run test-unit -- --watch", - "test-unit-php": "wp-env run phpunit 'phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose'", - "test-unit-php-multisite": "wp-env run phpunit 'WP_MULTISITE=1 phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit/multisite.xml --verbose'", + "test-unit-php": "npm run wp-env run phpunit 'phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose'", + "test-unit-php-multisite": "npm run wp-env run phpunit 'WP_MULTISITE=1 phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit/multisite.xml --verbose'", "test-unit:native": "cd test/native/ && cross-env NODE_ENV=test jest --config ./jest.config.js", "test-unit:native:debug": "cd test/native/ && node --inspect ../../node_modules/.bin/jest --runInBand --config ./jest.config.js", "prestorybook:build": "npm run build:packages", From fcb8a99944184ff216767760be6a3644a455f5cc Mon Sep 17 00:00:00 2001 From: Noah Allen Date: Wed, 8 Jul 2020 13:46:57 -0700 Subject: [PATCH 02/11] Switch to wp-env without npm run wp-env --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index b899fae229806e..3e887ceb0262be 100644 --- a/package.json +++ b/package.json @@ -225,8 +225,8 @@ "lint": "concurrently \"npm run lint-lockfile\" \"npm run lint-js\" \"npm run lint-pkg-json\" \"npm run lint-css\"", "lint-js": "wp-scripts lint-js", "lint-js:fix": "npm run lint-js -- --fix", - "prelint-php": "npm run wp-env run composer install -- --no-interaction", - "lint-php": "npm run wp-env run composer run-script lint", + "prelint-php": "wp-env run composer install -- --no-interaction", + "lint-php": "wp-env run composer run-script lint", "lint-pkg-json": "wp-scripts lint-pkg-json . 'packages/*/package.json'", "lint-lockfile": "node ./bin/validate-package-lock.js", "lint-css": "wp-scripts lint-style '**/*.scss'", @@ -251,8 +251,8 @@ "test-unit:debug": "wp-scripts --inspect-brk test-unit-js --runInBand --no-cache --verbose --config test/unit/jest.config.js ", "test-unit:update": "npm run test-unit -- --updateSnapshot", "test-unit:watch": "npm run test-unit -- --watch", - "test-unit-php": "npm run wp-env run phpunit 'phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose'", - "test-unit-php-multisite": "npm run wp-env run phpunit 'WP_MULTISITE=1 phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit/multisite.xml --verbose'", + "test-unit-php": "wp-env run phpunit 'phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose'", + "test-unit-php-multisite": "wp-env run phpunit 'WP_MULTISITE=1 phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit/multisite.xml --verbose'", "test-unit:native": "cd test/native/ && cross-env NODE_ENV=test jest --config ./jest.config.js", "test-unit:native:debug": "cd test/native/ && node --inspect ../../node_modules/.bin/jest --runInBand --config ./jest.config.js", "prestorybook:build": "npm run build:packages", From 4d6ba7d52d8363402dac283672a8ed8baecd3f37 Mon Sep 17 00:00:00 2001 From: Noah Allen Date: Wed, 8 Jul 2020 17:38:40 -0700 Subject: [PATCH 03/11] Replace "npx wp-env" with "npm run wp-env" --- docs/contributors/getting-started.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/contributors/getting-started.md b/docs/contributors/getting-started.md index fc8645f78c7fd4..a6362e2886fbbd 100644 --- a/docs/contributors/getting-started.md +++ b/docs/contributors/getting-started.md @@ -36,7 +36,8 @@ To install Docker Compose, [follow their instructions here](https://docs.docker. Once Docker is installed and running, run this script to install WordPress, and build your local environment: ```bash -npx wp-env start +# Note: prefixing with "npm run" will resolve npm from the local Gutenberg source code, rather than a global install which may be out of date. +npm run wp-env start ``` ### Step 2: Accessing and Configuring the Local WordPress Install @@ -46,7 +47,7 @@ npx wp-env start The WordPress installation should now be available at `http://localhost:8888` (**Username**: `admin`, **Password**: `password`). If this port is in use, you can override it using the `WP_ENV_PORT` environment variable. For more information, consult the `wp-env` [README](https://github.com/WordPress/gutenberg/blob/master/packages/env/README.md). -To shut down this local WordPress instance run `npx wp-env stop`. To start it back up again, run `npx wp-env start` again. +To shut down this local WordPress instance run `npm run wp-env stop`. To start it back up again, run `npm run wp-env start` again. #### Toggling Debug Systems From c4759322dd7be331df86d25ef09b23233d843f7b Mon Sep 17 00:00:00 2001 From: Noah Allen Date: Wed, 8 Jul 2020 19:05:00 -0700 Subject: [PATCH 04/11] Add wp-env start to test-unit-php --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3e887ceb0262be..24aac3805eff39 100644 --- a/package.json +++ b/package.json @@ -251,8 +251,8 @@ "test-unit:debug": "wp-scripts --inspect-brk test-unit-js --runInBand --no-cache --verbose --config test/unit/jest.config.js ", "test-unit:update": "npm run test-unit -- --updateSnapshot", "test-unit:watch": "npm run test-unit -- --watch", - "test-unit-php": "wp-env run phpunit 'phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose'", - "test-unit-php-multisite": "wp-env run phpunit 'WP_MULTISITE=1 phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit/multisite.xml --verbose'", + "test-unit-php": "wp-env start && wp-env run phpunit 'phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose'", + "test-unit-php-multisite": "wp-env start && wp-env run phpunit 'WP_MULTISITE=1 phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit/multisite.xml --verbose'", "test-unit:native": "cd test/native/ && cross-env NODE_ENV=test jest --config ./jest.config.js", "test-unit:native:debug": "cd test/native/ && node --inspect ../../node_modules/.bin/jest --runInBand --config ./jest.config.js", "prestorybook:build": "npm run build:packages", From b9fba2cb4322b0382667b94191483a0ca4a7fd22 Mon Sep 17 00:00:00 2001 From: Noah Allen Date: Wed, 8 Jul 2020 19:07:27 -0700 Subject: [PATCH 05/11] Add note about when wp-env needs to be running --- docs/contributors/testing-overview.md | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/docs/contributors/testing-overview.md b/docs/contributors/testing-overview.md index 7460249eabef0f..5fda57dae3ca36 100644 --- a/docs/contributors/testing-overview.md +++ b/docs/contributors/testing-overview.md @@ -453,21 +453,14 @@ Every core block is required to have at least one set of fixture files for its m ## PHP Testing -Tests for PHP use [PHPUnit](https://phpunit.de/) as the testing framework. If you're using the built-in [local environment](/docs/contributors/getting-started.md#local-environment), you can run the PHP tests locally using this command. - -Note that these commands require the local environment to be initalized first: - -```bash -# Reference the local sourcecode for wp-env in the Gutenberg repo: -npx wp-env start -``` - -Using `npx` above ensures that we always use the latest wp-env sourcecode in the Gutenberg repo. +Tests for PHP use [PHPUnit](https://phpunit.de/) as the testing framework. If you're using the built-in [local environment](/docs/contributors/getting-started.md#local-environment), you can run the PHP tests locally using this command: ```bash npm run test-php ``` +_Note: The phpunit commands require `wp-env` to be running. The package script will start wp-env for you if it is not already running._ + Code style in PHP is enforced using [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer). It is recommended that you install PHP_CodeSniffer and the [WordPress Coding Standards for PHP_CodeSniffer](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#installation) ruleset using [Composer](https://getcomposer.org/). With Composer installed, run `composer install` from the project directory to install dependencies. The above `npm run test-php` will execute both unit tests and code linting. Code linting can be verified independently by running `npm run lint-php`. To run unit tests only, without the linter, use `npm run test-unit-php` instead. From 659616d16bf998e349044382dc21d6394375e5cb Mon Sep 17 00:00:00 2001 From: Noah Allen Date: Tue, 14 Jul 2020 12:33:43 -0700 Subject: [PATCH 06/11] Try chmod --- packages/env/lib/wordpress.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/env/lib/wordpress.js b/packages/env/lib/wordpress.js index 385b8911a4eeaf..1c8fe2bf261763 100644 --- a/packages/env/lib/wordpress.js +++ b/packages/env/lib/wordpress.js @@ -130,7 +130,7 @@ async function configureWordPress( environment, config, spinner ) { [ 'sh', '-c', - 'sed "/^require.*wp-settings.php/d" /var/www/html/wp-config.php > /var/www/html/phpunit-wp-config.php', + 'sed "/^require.*wp-settings.php/d" /var/www/html/wp-config.php > /var/www/html/phpunit-wp-config.php && chmod 777 /var/www/html/phpunit-wp-config.php', ], { config: config.dockerComposeConfigPath, From e3dde3f06411f576e1dce4eb4c3f9ce6a93b98d8 Mon Sep 17 00:00:00 2001 From: Noah Allen Date: Tue, 14 Jul 2020 14:17:26 -0700 Subject: [PATCH 07/11] Try removing RN runner from wp-env --- .github/workflows/rnmobile-android-runner.yml | 1 + .github/workflows/rnmobile-ios-runner.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/rnmobile-android-runner.yml b/.github/workflows/rnmobile-android-runner.yml index c424385527f045..efb4ac544f89d1 100644 --- a/.github/workflows/rnmobile-android-runner.yml +++ b/.github/workflows/rnmobile-android-runner.yml @@ -4,6 +4,7 @@ on: pull_request: paths-ignore: - '**.md' + - '/packages/env/*' jobs: test: diff --git a/.github/workflows/rnmobile-ios-runner.yml b/.github/workflows/rnmobile-ios-runner.yml index 7a7a69a14d564c..a95ad4b5d59fdb 100644 --- a/.github/workflows/rnmobile-ios-runner.yml +++ b/.github/workflows/rnmobile-ios-runner.yml @@ -3,6 +3,7 @@ on: pull_request: paths-ignore: - '**.md' + - '/packages/env/*' jobs: test: From 38362f16edf367712ba130e3318fdaa5ae5daeb9 Mon Sep 17 00:00:00 2001 From: Noah Allen Date: Tue, 14 Jul 2020 14:18:04 -0700 Subject: [PATCH 08/11] undo --- .github/workflows/rnmobile-android-runner.yml | 1 - .github/workflows/rnmobile-ios-runner.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/rnmobile-android-runner.yml b/.github/workflows/rnmobile-android-runner.yml index efb4ac544f89d1..c424385527f045 100644 --- a/.github/workflows/rnmobile-android-runner.yml +++ b/.github/workflows/rnmobile-android-runner.yml @@ -4,7 +4,6 @@ on: pull_request: paths-ignore: - '**.md' - - '/packages/env/*' jobs: test: diff --git a/.github/workflows/rnmobile-ios-runner.yml b/.github/workflows/rnmobile-ios-runner.yml index a95ad4b5d59fdb..7a7a69a14d564c 100644 --- a/.github/workflows/rnmobile-ios-runner.yml +++ b/.github/workflows/rnmobile-ios-runner.yml @@ -3,7 +3,6 @@ on: pull_request: paths-ignore: - '**.md' - - '/packages/env/*' jobs: test: From e96666ffd60624470ab07629ff987d8d917f8d2b Mon Sep 17 00:00:00 2001 From: Noah Allen Date: Tue, 14 Jul 2020 14:20:44 -0700 Subject: [PATCH 09/11] Add note about dashes --- packages/env/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/env/README.md b/packages/env/README.md index 4eb9d65287dbe4..28c61f1bb6d405 100644 --- a/packages/env/README.md +++ b/packages/env/README.md @@ -51,13 +51,14 @@ Then modify your package.json and add an extra command to npm `scripts` (https:/ When installing `wp-env` in this way, all `wp-env` commands detailed in these docs must be prefixed with `npm run`, for example: ```sh -$ npm run wp-env start +# You must add another dash to pass the "update" flag to wp-env +$ npm run wp-env start -- --update ``` instead of: ```sh -$ wp-env start +$ wp-env start --update ``` ## Usage From 376216d5c1687c67d7bc13374b877f33aff1ff6c Mon Sep 17 00:00:00 2001 From: Noah Allen Date: Tue, 14 Jul 2020 14:23:13 -0700 Subject: [PATCH 10/11] Clarify docs --- docs/contributors/testing-overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/contributors/testing-overview.md b/docs/contributors/testing-overview.md index 5fda57dae3ca36..7170cb20ec5228 100644 --- a/docs/contributors/testing-overview.md +++ b/docs/contributors/testing-overview.md @@ -459,7 +459,7 @@ Tests for PHP use [PHPUnit](https://phpunit.de/) as the testing framework. If yo npm run test-php ``` -_Note: The phpunit commands require `wp-env` to be running. The package script will start wp-env for you if it is not already running._ +_Note: The phpunit commands require `wp-env` to be running and composer dependencies to be installed. The package script will start wp-env for you if it is not already running._ Code style in PHP is enforced using [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer). It is recommended that you install PHP_CodeSniffer and the [WordPress Coding Standards for PHP_CodeSniffer](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#installation) ruleset using [Composer](https://getcomposer.org/). With Composer installed, run `composer install` from the project directory to install dependencies. The above `npm run test-php` will execute both unit tests and code linting. Code linting can be verified independently by running `npm run lint-php`. From aa11386408f765c26469217a40a1a281e739278f Mon Sep 17 00:00:00 2001 From: Noah Allen Date: Tue, 14 Jul 2020 14:29:11 -0700 Subject: [PATCH 11/11] run wp-env during pretest --- package.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 24aac3805eff39..e5bb48ee5ae6a5 100644 --- a/package.json +++ b/package.json @@ -225,7 +225,7 @@ "lint": "concurrently \"npm run lint-lockfile\" \"npm run lint-js\" \"npm run lint-pkg-json\" \"npm run lint-css\"", "lint-js": "wp-scripts lint-js", "lint-js:fix": "npm run lint-js -- --fix", - "prelint-php": "wp-env run composer install -- --no-interaction", + "prelint-php": "wp-env run composer 'install --no-interaction'", "lint-php": "wp-env run composer run-script lint", "lint-pkg-json": "wp-scripts lint-pkg-json . 'packages/*/package.json'", "lint-lockfile": "node ./bin/validate-package-lock.js", @@ -251,8 +251,10 @@ "test-unit:debug": "wp-scripts --inspect-brk test-unit-js --runInBand --no-cache --verbose --config test/unit/jest.config.js ", "test-unit:update": "npm run test-unit -- --updateSnapshot", "test-unit:watch": "npm run test-unit -- --watch", - "test-unit-php": "wp-env start && wp-env run phpunit 'phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose'", - "test-unit-php-multisite": "wp-env start && wp-env run phpunit 'WP_MULTISITE=1 phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit/multisite.xml --verbose'", + "pretest-unit-php": "wp-env start", + "test-unit-php": "wp-env run phpunit 'phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose'", + "pretest-unit-php-multisite": "wp-env start", + "test-unit-php-multisite": "wp-env run phpunit 'WP_MULTISITE=1 phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit/multisite.xml --verbose'", "test-unit:native": "cd test/native/ && cross-env NODE_ENV=test jest --config ./jest.config.js", "test-unit:native:debug": "cd test/native/ && node --inspect ../../node_modules/.bin/jest --runInBand --config ./jest.config.js", "prestorybook:build": "npm run build:packages",