-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Isolate e2e tests and reset them for each run (#8041)
- Loading branch information
Showing
8 changed files
with
154 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,44 @@ | ||
#!/bin/bash | ||
|
||
# Exit if any command fails | ||
# Exit if any command fails. | ||
set -e | ||
|
||
# Include useful functions | ||
# Include useful functions. | ||
. "$(dirname "$0")/includes.sh" | ||
|
||
# Check that Docker is installed | ||
# Check that Docker is installed. | ||
if ! command_exists "docker"; then | ||
echo -e $(error_message "Docker doesn't seem to be installed. Please head on over to the Docker site to download it: $(action_format "https://www.docker.com/community-edition#/download")") | ||
exit 1 | ||
fi | ||
|
||
# Check that Docker is running | ||
# Check that Docker is running. | ||
if ! docker info >/dev/null 2>&1; then | ||
echo -e $(error_message "Docker isn't running. Please check that you've started your Docker app, and see it in your system tray.") | ||
exit 1 | ||
fi | ||
|
||
# Stop existing containers | ||
# Stop existing containers. | ||
echo -e $(status_message "Stopping Docker containers...") | ||
docker-compose down --remove-orphans >/dev/null 2>&1 | ||
|
||
# Download image updates | ||
# Download image updates. | ||
echo -e $(status_message "Downloading Docker image updates...") | ||
docker-compose pull | ||
|
||
# Launch the containers | ||
# Launch the containers. | ||
echo -e $(status_message "Starting Docker containers...") | ||
docker-compose up -d >/dev/null | ||
|
||
HOST_PORT=$(docker-compose port wordpress 80 | awk -F : '{printf $2}') | ||
# 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" | ||
|
||
# Wait until the docker containers are setup properely | ||
echo -en $(status_message "Attempting to connect to wordpress...") | ||
until $(curl -L http://localhost:$HOST_PORT -so - 2>&1 | grep -q "WordPress"); do | ||
echo -n '.' | ||
sleep 5 | ||
done | ||
echo '' | ||
|
||
# Install WordPress | ||
echo -e $(status_message "Installing WordPress...") | ||
docker-compose run --rm -u 33 cli core install --url=localhost:$HOST_PORT --title=Gutenberg --admin_user=admin --admin_password=password --admin_email=test@test.com >/dev/null | ||
# Check for WordPress updates, just in case the WordPress image isn't up to date. | ||
docker-compose run --rm -u 33 cli core update >/dev/null | ||
|
||
# If the 'wordpress' volume wasn't during the down/up earlier, but the post port has changed, we need to update it. | ||
CURRENT_URL=$(docker-compose run -T --rm cli option get siteurl) | ||
if [ "$CURRENT_URL" != "http://localhost:$HOST_PORT" ]; then | ||
docker-compose run --rm cli option update home "http://localhost:$HOST_PORT" >/dev/null | ||
docker-compose run --rm cli option update siteurl "http://localhost:$HOST_PORT" >/dev/null | ||
fi | ||
|
||
# Activate Gutenberg | ||
echo -e $(status_message "Activating Gutenberg...") | ||
docker-compose run --rm cli plugin activate gutenberg >/dev/null | ||
|
||
# Install the PHPUnit test scaffolding | ||
# Install the PHPUnit test scaffolding. | ||
echo -e $(status_message "Installing PHPUnit test scaffolding...") | ||
docker-compose run --rm wordpress_phpunit /app/bin/install-wp-tests.sh wordpress_test root example mysql latest false >/dev/null | ||
|
||
# Install Composer | ||
# Install Composer. This is only used to run WordPress Coding Standards checks. | ||
echo -e $(status_message "Installing and updating Composer modules...") | ||
docker-compose run --rm composer install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/bin/bash | ||
|
||
# Exit if any command fails. | ||
set -e | ||
|
||
# Gutenberg script includes. | ||
. "$(dirname "$0")/includes.sh" | ||
|
||
# These are the containers and values for the development site. | ||
CLI='cli' | ||
CONTAINER='wordpress' | ||
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" | ||
SITE_TITLE='Gutenberg Testing' | ||
|
||
if ! docker ps | grep -q $CONTAINER; then | ||
echo -e $(error_message "WordPress e2e tests run in their own Docker container, but that container wasn't found.") | ||
echo "Please restart your Docker containers by running 'docker-compose down && docker-compose up -d' or" | ||
echo "by running './bin/setup-local-env.sh' again." | ||
echo "" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
# Get the host port for the WordPress container. | ||
HOST_PORT=$(docker-compose port $CONTAINER 80 | awk -F : '{printf $2}') | ||
|
||
# Wait until the Docker containers are running and the WordPress site is | ||
# responding to requests. | ||
echo -en $(status_message "Attempting to connect to WordPress...") | ||
until $(curl -L http://localhost:$HOST_PORT -so - 2>&1 | grep -q "WordPress"); do | ||
echo -n '.' | ||
sleep 5 | ||
done | ||
echo '' | ||
|
||
# If this is the test site, we reset the database so no posts/comments/etc. | ||
# dirty up the tests. | ||
if [ "$1" == '--e2e_tests' ]; then | ||
echo -e $(status_message "Resetting test database...") | ||
docker-compose run --rm $CLI db reset --yes >/dev/null | ||
fi | ||
|
||
# Install WordPress. | ||
echo -e $(status_message "Installing WordPress...") | ||
docker-compose run --rm $CLI core install --title="$SITE_TITLE" --admin_user=admin --admin_password=password --admin_email=test@test.com --skip-email --url=http://localhost:$HOST_PORT >/dev/null | ||
# Check for WordPress updates, just in case the WordPress image isn't up to date. | ||
docker-compose run --rm $CLI core update >/dev/null | ||
|
||
# If the 'wordpress' volume wasn't during the down/up earlier, but the post port has changed, we need to update it. | ||
CURRENT_URL=$(docker-compose run -T --rm $CLI option get siteurl) | ||
if [ "$CURRENT_URL" != "http://localhost:$HOST_PORT" ]; then | ||
docker-compose run --rm $CLI option update home "http://localhost:$HOST_PORT" >/dev/null | ||
docker-compose run --rm $CLI option update siteurl "http://localhost:$HOST_PORT" >/dev/null | ||
fi | ||
|
||
# Activate Gutenberg. | ||
echo -e $(status_message "Activating Gutenberg...") | ||
docker-compose run --rm $CLI plugin activate gutenberg >/dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
# Exit if any command fails. | ||
set -e | ||
|
||
# Include useful functions. | ||
. "$(dirname "$0")/includes.sh" | ||
|
||
# Set up WordPress site used for end-to-end (e2e) tests. | ||
. "$(dirname "$0")/install-wordpress.sh" --e2e_tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters