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

Testing: Speed up Docker setup on Travis for e2e tests #15748

Merged
merged 4 commits into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 9 additions & 26 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 )

Expand All @@ -172,4 +156,3 @@ jobs:
env: WP_VERSION=latest SWITCH_TO_PHP=5.2
script:
- ./bin/run-wp-unit-tests.sh

13 changes: 0 additions & 13 deletions bin/install-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion bin/install-wordpress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
38 changes: 29 additions & 9 deletions bin/run-wp-unit-tests.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
13 changes: 13 additions & 0 deletions bin/setup-local-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
,⁻⁻⁻· . |
| ،⁓’. . |--- ,---. ,---. |---. ,---. ,---. ,---.
Expand Down
28 changes: 28 additions & 0 deletions bin/setup-travis-e2e-tests.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion docker-compose-localdev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.1'

services:

wordpress:
wordpress_dev:
volumes:
- ./wordpress:/var/www/html

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down