From 06b34035628f90ffbd901489e1c81651d5290aaa Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Wed, 25 Oct 2017 15:10:20 +0100 Subject: [PATCH 1/4] Tests: Clarify the travis tests using build stages --- .travis.yml | 88 ++++++++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 49 deletions(-) diff --git a/.travis.yml b/.travis.yml index a6eedf0a8849a6..69b8404e1d3f3a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,59 +28,49 @@ matrix: env: WP_VERSION=latest SWITCH_TO_PHP=5.3 - php: 7.1 env: WP_VERSION=latest SWITCH_TO_PHP=5.2 - - php: 5.6 - env: TRAVISCI=phpcs - - php: 7.1 - env: TRAVISCI=js - -before_script: - - export PATH="$HOME/.composer/vendor/bin:$PATH" - - | - if [[ ! -z "$WP_VERSION" ]] ; then - set -e - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION - source bin/install-php-phpunit.sh - set +e - fi - - | - if [[ "$TRAVISCI" == "phpcs" ]] ; then - composer install - fi script: - | - if [[ ! -z "$WP_VERSION" ]] ; then - # Run the build because otherwise there will be a bunch of warnings about - # failed `stat` calls from `filemtime()`. - npm install || exit 1 - npm run build || exit 1 - # Make sure phpegjs parser is up to date - node bin/create-php-parser.js || exit 1 - if ! git diff --quiet --exit-code lib/parser.php; then - echo 'ERROR: The PEG parser has been updated, but the generated PHP version' - echo ' (lib/parser.php) has not. Run `bin/create-php-parser.js` and' - echo ' commit the resulting changes to resolve this.' - sleep .2 # Otherwise Travis doesn't want to print the whole message - exit 1 - fi - echo Running with the following versions: - php -v - phpunit --version - # Check parser syntax - php lib/parser.php || exit 1 - # Run PHPUnit tests - phpunit || exit 1 - WP_MULTISITE=1 phpunit || exit 1 - fi - - | - if [[ "$TRAVISCI" == "phpcs" ]] ; then - ./vendor/bin/phpcs - fi - - | - if [[ "$TRAVISCI" == "js" ]] ; then - npm install || exit 1 - npm run ci || exit 1 + export PATH="$HOME/.composer/vendor/bin:$PATH" + bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION + source bin/install-php-phpunit.sh + # Run the build because otherwise there will be a bunch of warnings about + # failed `stat` calls from `filemtime()`. + npm install || exit 1 + npm run build || exit 1 + # Make sure phpegjs parser is up to date + node bin/create-php-parser.js || exit 1 + if ! git diff --quiet --exit-code lib/parser.php; then + echo 'ERROR: The PEG parser has been updated, but the generated PHP version' + echo ' (lib/parser.php) has not. Run `bin/create-php-parser.js` and' + echo ' commit the resulting changes to resolve this.' + sleep .2 # Otherwise Travis doesn't want to print the whole message + exit 1 fi + echo Running with the following versions: + php -v + phpunit --version + # Check parser syntax + php lib/parser.php || exit 1 + # Run PHPUnit tests + phpunit || exit 1 + WP_MULTISITE=1 phpunit || exit 1 + +jobs: + include: + - stage: lint + php: 5.6 + script: composer install && ./vendor/bin/phpcs + + - stage: unit + script: + - npm install || exit 1 + - npm run ci || exit 1 + +stages: + - lint + - unit + - test before_deploy: - npm install From a55eccc4fc74cb2d9594c6d3799225dd7ad6d60a Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Wed, 25 Oct 2017 15:19:58 +0100 Subject: [PATCH 2/4] Tests: Run linting and unit tests in separate stages --- .travis.yml | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 69b8404e1d3f3a..b79248d2b0a43f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -62,6 +62,11 @@ jobs: php: 5.6 script: composer install && ./vendor/bin/phpcs + - stage: lint + script: + - npm install || exit 1 + - npm run lint || exit 1 + - stage: unit script: - npm install || exit 1 diff --git a/package.json b/package.json index 16e407a94d4d7a..59f92a28a7db48 100644 --- a/package.json +++ b/package.json @@ -126,7 +126,7 @@ "lint": "eslint .", "dev": "cross-env BABEL_ENV=default webpack --watch", "test": "npm run lint && npm run test-unit", - "ci": "concurrently \"npm run lint && npm run build\" \"npm run test-unit:coverage-ci\"", + "ci": "concurrently \"npm run build\" \"npm run test-unit:coverage-ci\"", "fixtures:clean": "rimraf \"blocks/test/fixtures/*.+(json|serialized.html)\"", "fixtures:server-attributes": "./bin/get-server-block-attributes.php > blocks/test/server-attributes.json", "fixtures:generate": "npm run fixtures:server-attributes && cross-env GENERATE_MISSING_FIXTURES=y npm run test-unit", From 26039fe71200267afe738748770145509eaffcae Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Wed, 25 Oct 2017 15:22:23 +0100 Subject: [PATCH 3/4] Tests: Drop Travis matrix in favor or stages --- .travis.yml | 63 +++++++++++++++------------------------- bin/run-wp-unit-tests.sh | 28 ++++++++++++++++++ 2 files changed, 52 insertions(+), 39 deletions(-) create mode 100755 bin/run-wp-unit-tests.sh diff --git a/.travis.yml b/.travis.yml index b79248d2b0a43f..55528514996e7e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,44 +18,6 @@ before_install: - nvm install 6.11.1 && nvm use 6.11.1 - npm install --global npm@5 -matrix: - include: - - php: 7.1 - env: WP_VERSION=latest - - php: 5.6 - env: WP_VERSION=latest - - php: 7.1 - env: WP_VERSION=latest SWITCH_TO_PHP=5.3 - - php: 7.1 - env: WP_VERSION=latest SWITCH_TO_PHP=5.2 - -script: - - | - export PATH="$HOME/.composer/vendor/bin:$PATH" - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION - source bin/install-php-phpunit.sh - # Run the build because otherwise there will be a bunch of warnings about - # failed `stat` calls from `filemtime()`. - npm install || exit 1 - npm run build || exit 1 - # Make sure phpegjs parser is up to date - node bin/create-php-parser.js || exit 1 - if ! git diff --quiet --exit-code lib/parser.php; then - echo 'ERROR: The PEG parser has been updated, but the generated PHP version' - echo ' (lib/parser.php) has not. Run `bin/create-php-parser.js` and' - echo ' commit the resulting changes to resolve this.' - sleep .2 # Otherwise Travis doesn't want to print the whole message - exit 1 - fi - echo Running with the following versions: - php -v - phpunit --version - # Check parser syntax - php lib/parser.php || exit 1 - # Run PHPUnit tests - phpunit || exit 1 - WP_MULTISITE=1 phpunit || exit 1 - jobs: include: - stage: lint @@ -72,10 +34,33 @@ jobs: - npm install || exit 1 - npm run ci || exit 1 + - stage: unit + php: 7.1 + env: WP_VERSION=latest + script: + - ./bin/run-wp-unit-tests.sh + + - stage: unit + php: 5.6 + env: WP_VERSION=latest + script: + - ./bin/run-wp-unit-tests.sh + + - stage: unit + php: 7.1 + env: WP_VERSION=latest SWITCH_TO_PHP=5.3 + script: + - ./bin/run-wp-unit-tests.sh + + - stage: unit + php: 7.1 + env: WP_VERSION=latest SWITCH_TO_PHP=5.2 + script: + - ./bin/run-wp-unit-tests.sh + stages: - lint - unit - - test before_deploy: - npm install diff --git a/bin/run-wp-unit-tests.sh b/bin/run-wp-unit-tests.sh new file mode 100755 index 00000000000000..d78b4231e121d7 --- /dev/null +++ b/bin/run-wp-unit-tests.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +cd "$(dirname "$0")/../" + +export PATH="$HOME/.composer/vendor/bin:$PATH" +bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION +source bin/install-php-phpunit.sh +# Run the build because otherwise there will be a bunch of warnings about +# failed `stat` calls from `filemtime()`. +npm install || exit 1 +npm run build || exit 1 +# Make sure phpegjs parser is up to date +node bin/create-php-parser.js || exit 1 +if ! git diff --quiet --exit-code lib/parser.php; then + echo 'ERROR: The PEG parser has been updated, but the generated PHP version' + echo ' (lib/parser.php) has not. Run `bin/create-php-parser.js` and' + echo ' commit the resulting changes to resolve this.' + sleep .2 # Otherwise Travis doesn't want to print the whole message + exit 1 +fi +echo Running with the following versions: +php -v +phpunit --version +# Check parser syntax +php lib/parser.php || exit 1 +# Run PHPUnit tests +phpunit || exit 1 +WP_MULTISITE=1 phpunit || exit 1 From e527081fc1ffa427de0f3166dd387acc1b97c1cb Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Thu, 26 Oct 2017 13:30:59 +0100 Subject: [PATCH 4/4] CI: Run everything in parallel --- .travis.yml | 8 +------- package.json | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 55528514996e7e..feca329f2962f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,15 +20,10 @@ before_install: jobs: include: - - stage: lint + - stage: unit php: 5.6 script: composer install && ./vendor/bin/phpcs - - stage: lint - script: - - npm install || exit 1 - - npm run lint || exit 1 - - stage: unit script: - npm install || exit 1 @@ -59,7 +54,6 @@ jobs: - ./bin/run-wp-unit-tests.sh stages: - - lint - unit before_deploy: diff --git a/package.json b/package.json index 59f92a28a7db48..16e407a94d4d7a 100644 --- a/package.json +++ b/package.json @@ -126,7 +126,7 @@ "lint": "eslint .", "dev": "cross-env BABEL_ENV=default webpack --watch", "test": "npm run lint && npm run test-unit", - "ci": "concurrently \"npm run build\" \"npm run test-unit:coverage-ci\"", + "ci": "concurrently \"npm run lint && npm run build\" \"npm run test-unit:coverage-ci\"", "fixtures:clean": "rimraf \"blocks/test/fixtures/*.+(json|serialized.html)\"", "fixtures:server-attributes": "./bin/get-server-block-attributes.php > blocks/test/server-attributes.json", "fixtures:generate": "npm run fixtures:server-attributes && cross-env GENERATE_MISSING_FIXTURES=y npm run test-unit",