From 884b3f9e588246f40e13d01084655aed5564bd78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20=28Greg=29=20Zi=C3=B3=C5=82kowski?= Date: Wed, 22 May 2019 14:04:52 +0200 Subject: [PATCH] Testing: Speed up Docker setup on Travis for e2e tests (#15748) * Testing: Speed up Docker setup on Travis for e2e tests * Testing: Speed up Docker setup on Travis for PHP tests * Testing: Add back npm run build to jobs which run PHP unit tests * Revert Docker service name change for wordpress --- .travis.yml | 35 +++++------------ bin/install-docker.sh | 13 ------- bin/install-wordpress.sh | 2 +- ...-e2e-tests.sh => reset-local-e2e-tests.sh} | 0 bin/run-wp-unit-tests.sh | 38 ++++++++++++++----- bin/setup-local-env.sh | 13 +++++++ bin/setup-travis-e2e-tests.sh | 28 ++++++++++++++ docker-compose-localdev.yml | 2 +- package.json | 2 +- 9 files changed, 82 insertions(+), 51 deletions(-) rename bin/{reset-e2e-tests.sh => reset-local-e2e-tests.sh} (100%) create mode 100755 bin/setup-travis-e2e-tests.sh diff --git a/.travis.yml b/.travis.yml index 02b57e11c88e60..5fa24d4faf998c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,39 +23,31 @@ branches: - master before_install: - - nvm install + - nvm install --latest-npm env: PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true jobs: include: - name: Lint - before_install: - - nvm install --latest-npm install: - npm ci script: - npm run lint - name: Build artifacts - before_install: - - nvm install --latest-npm install: - npm ci script: - npm run check-local-changes - name: License compatibility - before_install: - - nvm install --latest-npm install: - npm ci script: - npm run check-licenses - name: JavaScript unit tests - before_install: - - nvm install --latest-npm install: - npm ci script: @@ -92,72 +84,64 @@ jobs: - name: E2E tests (Admin with plugins) (1/4) env: WP_VERSION=latest SCRIPT_DEBUG=false POPULAR_PLUGINS=true PUPPETEER_SKIP_CHROMIUM_DOWNLOAD= install: - - ./bin/setup-local-env.sh + - ./bin/setup-travis-e2e-tests.sh script: - - npm run build - $( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests - npm run test-e2e -- --ci --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % 4 == 0' < ~/.jest-e2e-tests ) - name: E2E tests (Admin with plugins) (2/4) env: WP_VERSION=latest SCRIPT_DEBUG=false POPULAR_PLUGINS=true PUPPETEER_SKIP_CHROMIUM_DOWNLOAD= install: - - ./bin/setup-local-env.sh + - ./bin/setup-travis-e2e-tests.sh script: - - npm run build - $( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests - npm run test-e2e -- --ci --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % 4 == 1' < ~/.jest-e2e-tests ) - name: E2E tests (Admin with plugins) (3/4) env: WP_VERSION=latest SCRIPT_DEBUG=false POPULAR_PLUGINS=true PUPPETEER_SKIP_CHROMIUM_DOWNLOAD= install: - - ./bin/setup-local-env.sh + - ./bin/setup-travis-e2e-tests.sh script: - - npm run build - $( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests - npm run test-e2e -- --ci --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % 4 == 2' < ~/.jest-e2e-tests ) - name: E2E tests (Admin with plugins) (4/4) env: WP_VERSION=latest SCRIPT_DEBUG=false POPULAR_PLUGINS=true PUPPETEER_SKIP_CHROMIUM_DOWNLOAD= install: - - ./bin/setup-local-env.sh + - ./bin/setup-travis-e2e-tests.sh script: - - npm run build - $( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests - npm run test-e2e -- --ci --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % 4 == 3' < ~/.jest-e2e-tests ) - name: E2E tests (Author without plugins) (1/4) env: WP_VERSION=latest SCRIPT_DEBUG=false E2E_ROLE=author PUPPETEER_SKIP_CHROMIUM_DOWNLOAD= install: - - ./bin/setup-local-env.sh + - ./bin/setup-travis-e2e-tests.sh script: - - npm run build - $( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests - npm run test-e2e -- --ci --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % 4 == 0' < ~/.jest-e2e-tests ) - name: E2E tests (Author without plugins) (2/4) env: WP_VERSION=latest SCRIPT_DEBUG=false E2E_ROLE=author PUPPETEER_SKIP_CHROMIUM_DOWNLOAD= install: - - ./bin/setup-local-env.sh + - ./bin/setup-travis-e2e-tests.sh script: - - npm run build - $( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests - npm run test-e2e -- --ci --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % 4 == 1' < ~/.jest-e2e-tests ) - name: E2E tests (Author without plugins) (3/4) env: WP_VERSION=latest SCRIPT_DEBUG=false E2E_ROLE=author PUPPETEER_SKIP_CHROMIUM_DOWNLOAD= install: - - ./bin/setup-local-env.sh + - ./bin/setup-travis-e2e-tests.sh script: - - npm run build - $( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests - npm run test-e2e -- --ci --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % 4 == 2' < ~/.jest-e2e-tests ) - name: E2E tests (Author without plugins) (4/4) env: WP_VERSION=latest SCRIPT_DEBUG=false E2E_ROLE=author PUPPETEER_SKIP_CHROMIUM_DOWNLOAD= install: - - ./bin/setup-local-env.sh + - ./bin/setup-travis-e2e-tests.sh script: - - npm run build - $( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests - npm run test-e2e -- --ci --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % 4 == 3' < ~/.jest-e2e-tests ) @@ -172,4 +156,3 @@ jobs: env: WP_VERSION=latest SWITCH_TO_PHP=5.2 script: - ./bin/run-wp-unit-tests.sh - diff --git a/bin/install-docker.sh b/bin/install-docker.sh index 56bb4ad3ef1c6f..d6a10c498f0420 100755 --- a/bin/install-docker.sh +++ b/bin/install-docker.sh @@ -31,16 +31,3 @@ docker-compose $DOCKER_COMPOSE_FILE_OPTIONS pull # Launch the containers. echo -e $(status_message "Starting Docker containers...") docker-compose $DOCKER_COMPOSE_FILE_OPTIONS up -d >/dev/null - -# Set up WordPress Development site. -# Note: we don't bother installing the test site right now, because that's -# done on every time `npm run test-e2e` is run. -. "$(dirname "$0")/install-wordpress.sh" - -# Install the PHPUnit test scaffolding. -echo -e $(status_message "Installing PHPUnit test scaffolding...") -docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm wordpress_phpunit /app/bin/install-wp-tests.sh wordpress_test root example mysql $WP_VERSION false > /dev/null - -# Install Composer. This is only used to run WordPress Coding Standards checks. -echo -e $(status_message "Installing and updating Composer modules...") -docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm composer install diff --git a/bin/install-wordpress.sh b/bin/install-wordpress.sh index 8d20d91e3a8845..2b7b1ebf84b393 100755 --- a/bin/install-wordpress.sh +++ b/bin/install-wordpress.sh @@ -17,7 +17,7 @@ SITE_TITLE='Gutenberg Dev' # If we're installing/re-installing the test site, change the containers used. if [ "$1" == '--e2e_tests' ]; then CLI="${CLI}_e2e_tests" - CONTAINER="${CONTAINER}_e2e_tests" + CONTAINER='wordpress_e2e_tests' SITE_TITLE='Gutenberg Testing' if ! docker ps | grep -q $CONTAINER; then diff --git a/bin/reset-e2e-tests.sh b/bin/reset-local-e2e-tests.sh similarity index 100% rename from bin/reset-e2e-tests.sh rename to bin/reset-local-e2e-tests.sh diff --git a/bin/run-wp-unit-tests.sh b/bin/run-wp-unit-tests.sh index 8e1ee81db79e3d..2e5dc5b0809146 100755 --- a/bin/run-wp-unit-tests.sh +++ b/bin/run-wp-unit-tests.sh @@ -1,26 +1,46 @@ #!/usr/bin/env bash +# Exit if any command fails +set -e + +npm ci + +npm run build # Set up environment variables . "$(dirname "$0")/bootstrap-env.sh" +# Include useful functions +. "$(dirname "$0")/includes.sh" + cd "$(dirname "$0")/../" export PATH="$HOME/.composer/vendor/bin:$PATH" if [[ $DOCKER = "true" ]]; then - bin/setup-local-env.sh + # Download image updates. + echo -e $(status_message "Downloading Docker image updates...") + docker-compose $DOCKER_COMPOSE_FILE_OPTIONS pull composer mysql wordpress_phpunit + + # Launch the containers. + echo -e $(status_message "Starting Docker containers...") + docker-compose $DOCKER_COMPOSE_FILE_OPTIONS up -d composer mysql wordpress_phpunit >/dev/null + + # Install the PHPUnit test scaffolding. + echo -e $(status_message "Installing PHPUnit test scaffolding...") + docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm wordpress_phpunit /app/bin/install-wp-tests.sh wordpress_test root example mysql $WP_VERSION false > /dev/null + + # Install Composer. This is only used to run WordPress Coding Standards checks. + echo -e $(status_message "Installing and updating Composer modules...") + docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm composer install else 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()`. - composer install || exit 1 - npm install || exit 1 + composer install fi -npm run build || exit 1 - echo Running with the following versions: if [[ $DOCKER = "true" ]]; then docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm wordpress_phpunit php -v @@ -32,9 +52,9 @@ fi # Run PHPUnit tests if [[ $DOCKER = "true" ]]; then - npm run test-php || exit 1 - npm run test-unit-php-multisite || exit 1 + npm run test-php + npm run test-unit-php-multisite else - phpunit || exit 1 - WP_MULTISITE=1 phpunit || exit 1 + phpunit + WP_MULTISITE=1 phpunit fi diff --git a/bin/setup-local-env.sh b/bin/setup-local-env.sh index dcc86df34a279d..f618780e2d8c19 100755 --- a/bin/setup-local-env.sh +++ b/bin/setup-local-env.sh @@ -18,6 +18,19 @@ cd "$(dirname "$0")/.." # Check Docker is installed and running . "$(dirname "$0")/install-docker.sh" +# Set up WordPress Development site. +# Note: we don't bother installing the test site right now, because that's +# done on every time `npm run test-e2e` is run. +. "$(dirname "$0")/install-wordpress.sh" + +# Install the PHPUnit test scaffolding. +echo -e $(status_message "Installing PHPUnit test scaffolding...") +docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm wordpress_phpunit /app/bin/install-wp-tests.sh wordpress_test root example mysql $WP_VERSION false > /dev/null + +# Install Composer. This is only used to run WordPress Coding Standards checks. +echo -e $(status_message "Installing and updating Composer modules...") +docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm composer install + ! read -d '' GUTENBERG <<"EOT" ,⁻⁻⁻· . | | ،⁓’. . |--- ,---. ,---. |---. ,---. ,---. ,---. diff --git a/bin/setup-travis-e2e-tests.sh b/bin/setup-travis-e2e-tests.sh new file mode 100755 index 00000000000000..0ebc8bc1e6dff3 --- /dev/null +++ b/bin/setup-travis-e2e-tests.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Exit if any command fails +set -e + +npm ci + +npm run build + +# Set up environment variables +. "$(dirname "$0")/bootstrap-env.sh" + +# Include useful functions +. "$(dirname "$0")/includes.sh" + +# Change to the expected directory +cd "$(dirname "$0")/.." + +# Download image updates. +echo -e $(status_message "Downloading Docker image updates...") +docker-compose $DOCKER_COMPOSE_FILE_OPTIONS pull mysql wordpress_e2e_tests cli_e2e_tests + +# Launch the containers. +echo -e $(status_message "Starting Docker containers...") +docker-compose $DOCKER_COMPOSE_FILE_OPTIONS up -d --remove-orphans mysql wordpress_e2e_tests cli_e2e_tests >/dev/null + +# Set up WordPress Development site. +. "$(dirname "$0")/install-wordpress.sh" --e2e_tests diff --git a/docker-compose-localdev.yml b/docker-compose-localdev.yml index 4d58031eaa74be..502132973afbcd 100644 --- a/docker-compose-localdev.yml +++ b/docker-compose-localdev.yml @@ -2,7 +2,7 @@ version: '3.1' services: - wordpress: + wordpress_dev: volumes: - ./wordpress:/var/www/html diff --git a/package.json b/package.json index 8b0a3453903d4b..c9474bcfdc3e58 100644 --- a/package.json +++ b/package.json @@ -183,7 +183,7 @@ "publish:dev": "npm run build:packages && lerna publish --npm-tag next", "publish:prod": "npm run build:packages && lerna publish", "test": "npm run lint && npm run test-unit", - "pretest-e2e": "cross-env SCRIPT_DEBUG=false ./bin/reset-e2e-tests.sh", + "pretest-e2e": "cross-env SCRIPT_DEBUG=false ./bin/reset-local-e2e-tests.sh", "test-e2e": "wp-scripts test-e2e --config packages/e2e-tests/jest.config.js", "test-e2e:watch": "npm run test-e2e -- --watch", "test-php": "npm run lint-php && npm run test-unit-php",