Skip to content

Commit 6cd2c47

Browse files
authored
Update e2e test setup (#3031)
1 parent 0303912 commit 6cd2c47

9 files changed

+107
-71
lines changed

.travis.yml

+2-17
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,11 @@ jobs:
9292
install:
9393
- nvm install
9494
- composer install
95-
# npm is handled by `npm run env:start`
95+
- npm install
9696
script:
97-
- npm run env:start # also install npm dependencies
98-
- npm run build:js
99-
- npm run build:css
100-
- npm run env:reset-site
101-
- npm run test:e2e:ci
102-
- npm run env:stop
103-
104-
- name: E2E tests (Author)
105-
php: "7.3"
106-
env: WP_VERSION=latest DEV_LIB_SKIP=phpcs,eslint,xmllint,phpsyntax,phpunit PUPPETEER_SKIP_CHROMIUM_DOWNLOAD= E2E_ROLE=author
107-
install:
108-
- nvm install
109-
- composer install
110-
# npm is handled by `npm run env:start`
111-
script:
112-
- npm run env:start # also install npm dependencies
11397
- npm run build:js
11498
- npm run build:css
99+
- npm run env:start
115100
- npm run env:reset-site
116101
- npm run test:e2e:ci
117102
- npm run env:stop

bin/local-env/docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ services:
2929
depends_on:
3030
- mysql
3131
- wordpress
32+
command: tail -f /dev/null
3233

3334
mysql:
3435
image: mysql:5.7

bin/local-env/includes.sh

+34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#!/bin/bash
22

3+
# Common variables.
4+
DOCKER_COMPOSE_FILE_OPTIONS="-f $(dirname "$0")/docker-compose.yml"
5+
# These are the containers and values for the development site.
6+
CLI='cli'
7+
CONTAINER='wordpress'
8+
SITE_TITLE='AMP Dev'
9+
310
##
411
# Ask a Yes/No question, and way for a reply.
512
#
@@ -132,3 +139,30 @@ action_format() {
132139
command_exists() {
133140
type -t "$1" >/dev/null 2>&1
134141
}
142+
143+
##
144+
# Docker Compose helper
145+
#
146+
# Calls docker-compose with common options.
147+
##
148+
dc() {
149+
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS "$@"
150+
}
151+
152+
##
153+
# WP CLI
154+
#
155+
# Executes a WP CLI request in the CLI container.
156+
##
157+
wp() {
158+
dc exec -u xfs $CLI wp "$@"
159+
}
160+
161+
##
162+
# WordPress Container helper.
163+
#
164+
# Executes the given command in the wordpress container.
165+
##
166+
container() {
167+
dc exec $CONTAINER "$@"
168+
}

bin/local-env/install-node-nvm.sh

+7-5
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ if [ "$TRAVIS" != "true" ] && [ "$(nvm current)" != "$(nvm version-remote --lts)
6565
exit 1
6666
fi
6767

68-
# Install/update packages
69-
echo -e $(status_message "Installing and updating NPM packages..." )
70-
npm install
68+
if [ "$TRAVIS" != "true" ]; then
69+
# Install/update packages
70+
echo -e $(status_message "Installing and updating NPM packages..." )
71+
npm install
7172

72-
# Make sure npm is up-to-date
73-
npm install npm -g
73+
# Make sure npm is up-to-date
74+
npm install npm -g
75+
fi
7476

7577
# There was a bug in NPM that caused changes in package-lock.json. Handle that.
7678
if [ "$TRAVIS" != "true" ] && ! git diff --no-ext-diff --exit-code package-lock.json >/dev/null; then

bin/local-env/install-wordpress.sh

+56-38
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@
44
set -e
55

66
# Common variables.
7-
DOCKER_COMPOSE_FILE_OPTIONS="-f $(dirname "$0")/docker-compose.yml"
87
WP_DEBUG=${WP_DEBUG-true}
98
SCRIPT_DEBUG=${SCRIPT_DEBUG-true}
9+
WP_VERSION=${WP_VERSION-"latest"}
1010

1111
# Include useful functions
1212
. "$(dirname "$0")/includes.sh"
1313

14-
# These are the containers and values for the development site.
15-
CLI='cli'
16-
CONTAINER='wordpress'
17-
SITE_TITLE='AMP Dev'
14+
# Make sure Docker containers are running
15+
dc up -d >/dev/null 2>&1
1816

1917
# Get the host port for the WordPress container.
20-
HOST_PORT=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS port $CONTAINER 80 | awk -F : '{printf $2}')
18+
HOST_PORT=$(dc port $CONTAINER 80 | awk -F : '{printf $2}')
2119

2220
# Wait until the Docker containers are running and the WordPress site is
2321
# responding to requests.
@@ -32,72 +30,92 @@ echo ''
3230
# dirty up the tests.
3331
if [ "$1" == '--reset-site' ]; then
3432
echo -e $(status_message "Resetting test database...")
35-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI db reset --yes --quiet
33+
wp db reset --yes --quiet
34+
fi
35+
36+
if [ ! -z "$WP_VERSION" ] && [ "$WP_VERSION" != "latest" ]; then
37+
# Potentially downgrade WordPress
38+
echo -e $(status_message "Downloading WordPress version $WP_VERSION...")
39+
wp core download --version=${WP_VERSION} --force --quiet
3640
fi
3741

3842
# Install WordPress.
3943
echo -e $(status_message "Installing WordPress...")
40-
# The `-u 33` flag tells Docker to run the command as a particular user and
41-
# prevents permissions errors. See: https://github.com/WordPress/gutenberg/pull/8427#issuecomment-410232369
42-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI core install --title="$SITE_TITLE" --admin_user=admin --admin_password=password --admin_email=test@test.com --skip-email --url=http://localhost:$HOST_PORT --quiet
43-
44-
if [ "$E2E_ROLE" = "author" ]; then
45-
echo -e $(status_message "Creating an additional author user for testing...")
46-
# Create an additional author user for testing.
47-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI user create author author@example.com --role=author --user_pass=authpass --quiet
48-
# Assign the existing Hello World post to the author.
49-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI post update 1 --post_author=2 --quiet
50-
fi
44+
wp core install --title="$SITE_TITLE" --admin_user=admin --admin_password=password --admin_email=test@test.com --skip-email --url=http://localhost:$HOST_PORT --quiet
45+
46+
# Create additional users.
47+
echo -e $(status_message "Creating additional users...")
48+
wp user create editor editor@example.com --role=editor --user_pass=password --quiet
49+
echo -e $(status_message "Editor created! Username: editor Password: password")
50+
wp user create author author@example.com --role=author --user_pass=password --quiet
51+
echo -e $(status_message "Author created! Username: author Password: password")
52+
wp user create contributor contributor@example.com --role=contributor --user_pass=password --quiet
53+
echo -e $(status_message "Contributor created! Username: contributor Password: password")
54+
wp user create subscriber subscriber@example.com --role=subscriber --user_pass=password --quiet
55+
echo -e $(status_message "Subscriber created! Username: subscriber Password: password")
5156

5257
# Make sure the uploads and upgrade folders exist and we have permissions to add files.
5358
echo -e $(status_message "Ensuring that files can be uploaded...")
54-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CONTAINER mkdir -p /var/www/html/wp-content/uploads /var/www/html/wp-content/upgrade
55-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CONTAINER chmod 767 /var/www/html/wp-content/plugins /var/www/html/wp-config.php /var/www/html/wp-settings.php /var/www/html/wp-content/uploads /var/www/html/wp-content/upgrade
56-
57-
CURRENT_WP_VERSION=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm $CLI core version)
59+
container mkdir -p \
60+
/var/www/html/wp-content/uploads \
61+
/var/www/html/wp-content/upgrade
62+
container chmod 767 \
63+
/var/www/html/wp-content \
64+
/var/www/html/wp-content/plugins \
65+
/var/www/html/wp-config.php \
66+
/var/www/html/wp-settings.php \
67+
/var/www/html/wp-content/uploads \
68+
/var/www/html/wp-content/upgrade
69+
70+
CURRENT_WP_VERSION=$(wp core version | tr -d '\r')
5871
echo -e $(status_message "Current WordPress version: $CURRENT_WP_VERSION...")
5972

6073
if [ "$WP_VERSION" == "latest" ]; then
6174
# Check for WordPress updates, to make sure we're running the very latest version.
6275
echo -e $(status_message "Updating WordPress to the latest version...")
63-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI core update --quiet
76+
wp core update --quiet
6477
echo -e $(status_message "Updating The WordPress Database...")
65-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI core update-db --quiet
78+
wp core update-db --quiet
6679
fi
6780

6881
# If the 'wordpress' volume wasn't during the down/up earlier, but the post port has changed, we need to update it.
6982
echo -e $(status_message "Checking the site's url...")
70-
CURRENT_URL=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm $CLI option get siteurl)
83+
CURRENT_URL=$(wp option get siteurl)
7184
if [ "$CURRENT_URL" != "http://localhost:$HOST_PORT" ]; then
72-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI option update home "http://localhost:$HOST_PORT" --quiet
73-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI option update siteurl "http://localhost:$HOST_PORT" --quiet
85+
wp option update home "http://localhost:$HOST_PORT" --quiet
86+
wp option update siteurl "http://localhost:$HOST_PORT" --quiet
7487
fi
7588

7689
# Install a dummy favicon to avoid 404 errors.
7790
echo -e $(status_message "Installing a dummy favicon...")
78-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CONTAINER touch /var/www/html/favicon.ico
91+
container touch /var/www/html/favicon.ico
92+
container chmod 767 /var/www/html/favicon.ico
7993

8094
# Activate AMP plugin.
8195
echo -e $(status_message "Activating AMP plugin...")
82-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI plugin activate amp --quiet
96+
wp plugin activate amp --quiet
8397

8498
# Install & activate Gutenberg plugin.
8599
echo -e $(status_message "Installing and activating Gutenberg plugin...")
86-
# todo: Use `wp plugin install --activate` once WP-CLI is updated, see https://github.com/wp-cli/extension-command/issues/176.
87-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI plugin install gutenberg --activate --quiet
88-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI plugin activate gutenberg --quiet
100+
wp plugin install gutenberg --activate --force --quiet
101+
102+
# Set pretty permalinks.
103+
echo -e $(status_message "Setting permalink structure...")
104+
wp rewrite structure '%postname%' --hard --quiet
89105

90106
# Configure site constants.
91107
echo -e $(status_message "Configuring site constants...")
92-
WP_DEBUG_CURRENT=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm -u 33 $CLI config get --type=constant --format=json WP_DEBUG)
108+
WP_DEBUG_CURRENT=$(wp config get --type=constant --format=json WP_DEBUG | tr -d '\r')
109+
93110
if [ "$WP_DEBUG" != $WP_DEBUG_CURRENT ]; then
94-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI config set WP_DEBUG $WP_DEBUG --raw --type=constant --quiet
95-
WP_DEBUG_RESULT=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm -u 33 $CLI config get --type=constant --format=json WP_DEBUG)
111+
wp config set WP_DEBUG $WP_DEBUG --raw --type=constant --quiet
112+
WP_DEBUG_RESULT=$(wp config get --type=constant --format=json WP_DEBUG | tr -d '\r')
96113
echo -e $(status_message "WP_DEBUG: $WP_DEBUG_RESULT...")
97114
fi
98-
SCRIPT_DEBUG_CURRENT=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm -u 33 $CLI config get --type=constant --format=json SCRIPT_DEBUG)
115+
116+
SCRIPT_DEBUG_CURRENT=$(wp config get --type=constant --format=json SCRIPT_DEBUG | tr -d '\r')
99117
if [ "$SCRIPT_DEBUG" != $SCRIPT_DEBUG_CURRENT ]; then
100-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI config set SCRIPT_DEBUG $SCRIPT_DEBUG --raw --type=constant --quiet
101-
SCRIPT_DEBUG_RESULT=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm -u 33 $CLI config get --type=constant --format=json SCRIPT_DEBUG)
118+
wp config set SCRIPT_DEBUG $SCRIPT_DEBUG --raw --type=constant --quiet
119+
SCRIPT_DEBUG_RESULT=$(wp config get --type=constant --format=json SCRIPT_DEBUG | tr -d '\r')
102120
echo -e $(status_message "SCRIPT_DEBUG: $SCRIPT_DEBUG_RESULT...")
103121
fi

bin/local-env/launch-containers.sh

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
# Exit if any command fails.
44
set -e
55

6-
# Common variables.
7-
DOCKER_COMPOSE_FILE_OPTIONS="-f $(dirname "$0")/docker-compose.yml"
8-
96
# Include useful functions.
107
. "$(dirname "$0")/includes.sh"
118

@@ -23,12 +20,12 @@ fi
2320

2421
# Stop existing containers.
2522
echo -e $(status_message "Stopping Docker containers...")
26-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS down --remove-orphans >/dev/null 2>&1
23+
dc down --remove-orphans >/dev/null 2>&1
2724

2825
# Download image updates.
2926
echo -e $(status_message "Downloading Docker image updates...")
30-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS pull
27+
dc pull
3128

3229
# Launch the containers.
3330
echo -e $(status_message "Starting Docker containers...")
34-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS up -d >/dev/null
31+
dc up -d >/dev/null

bin/local-env/start.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
5252
5353
EOT
5454

55-
CURRENT_URL=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm cli option get siteurl)
55+
CURRENT_URL=$(wp option get siteurl | tr -d '\r')
5656

5757
echo -e "\nWelcome to...\n"
5858
echo -e "\033[95m$AMP\033[0m"

bin/local-env/stop.sh

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
# Exit if any command fails.
44
set -e
55

6-
# Common variables.
7-
DOCKER_COMPOSE_FILE_OPTIONS="-f $(dirname "$0")/docker-compose.yml"
8-
96
# Include useful functions.
107
. "$(dirname "$0")/includes.sh"
118

@@ -23,4 +20,4 @@ fi
2320

2421
# Stop existing containers.
2522
echo -e $(status_message "Stopping Docker containers...")
26-
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS down --remove-orphans >/dev/null 2>&1
23+
dc down --remove-orphans >/dev/null 2>&1

tests/e2e/specs/stories-editor/code-editor.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ describe( 'Code Editor', () => {
2424

2525
await expect( page ).not.toMatchElement( '.block-editor-writing-flow__click-redirect' );
2626

27+
// Ensure the menu is available before switching mode.
28+
await page.waitForSelector( '.edit-post-more-menu [aria-label="More tools & options"]' );
2729
await switchEditorModeTo( 'Code' );
2830
await page.click( '.edit-post-more-menu [aria-label="More tools & options"]' );
2931

0 commit comments

Comments
 (0)