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

Tests: Clarify the travis tests using build stages #3150

Merged
merged 4 commits into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
94 changes: 37 additions & 57 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,69 +18,49 @@ before_install:
- nvm install 6.11.1 && nvm use 6.11.1
- npm install --global npm@5

matrix:
jobs:
include:
- php: 7.1
- stage: lint
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
- npm run ci || exit 1

- stage: unit
php: 7.1
env: WP_VERSION=latest
- php: 5.6
script:
- ./bin/run-wp-unit-tests.sh

- stage: unit
php: 5.6
env: WP_VERSION=latest
- php: 7.1
script:
- ./bin/run-wp-unit-tests.sh

- stage: unit
php: 7.1
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
script:
- ./bin/run-wp-unit-tests.sh

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
- stage: unit
php: 7.1
env: WP_VERSION=latest SWITCH_TO_PHP=5.2
script:
- ./bin/run-wp-unit-tests.sh

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
fi
stages:
- lint
- unit

before_deploy:
- npm install
Expand Down
28 changes: 28 additions & 0 deletions bin/run-wp-unit-tests.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to execute npm run build here, too? It's executed as part of bin/run-wp-unit-tests.sh for every PHP version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was added later to the PHP unit tests to build the parser. If the parser is no longer built this way in the future (say a Pure PHP parser), this could be removed.

While keeping it here ensure the build is tested as part of the JS unit tests which is more logical to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We moved lint out, so we could do the same with the build, and call npm run test-unit:coverage-ci directly from Travis. We can leave it as it is, too. I don't think it makes any difference in the end.

"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",
Expand Down