-
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.
- Loading branch information
1 parent
dfcbed2
commit c662f0d
Showing
16 changed files
with
4,929 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,141 @@ | ||
name: E2E Test | ||
|
||
env: | ||
COMPOSER_VERSION: "2" | ||
NODE_VERSION: "20" | ||
|
||
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: 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: 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 | ||
run: npm run cypress:setup -- --ep-host=${{ secrets.EPIO_HOST }} --es-shield='${{ secrets.EPIO_SHIELD }}' --ep-index-prefix=${{ secrets.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/ | ||
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,18 @@ | ||
{ | ||
"config": { | ||
"WP_DEBUG": true, | ||
"WP_DEBUG_DISPLAY": true, | ||
"WP_DISABLE_FATAL_ERROR_HANDLER": true | ||
}, | ||
"env": { | ||
"tests": { | ||
"plugins": [ | ||
".", | ||
"https://downloads.wordpress.org/plugin/elasticpress.zip" | ||
], | ||
"mappings": { | ||
".htaccess": "./tests/cypress/wordpress-files/.htaccess" | ||
} | ||
} | ||
} | ||
} |
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,44 @@ | ||
#!/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 | ||
|
||
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://raw.githubusercontent.com/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,80 @@ | ||
#!/bin/bash | ||
|
||
EP_HOST="" | ||
ES_SHIELD="" | ||
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=*) | ||
ES_SHIELD="${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 | ||
|
||
if [ ! -z $WP_VERSION ]; then | ||
./bin/wp-env-cli tests-wordpress "wp --allow-root core update --version=${WP_VERSION} --force" | ||
fi | ||
|
||
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" |
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,52 @@ | ||
#!/usr/bin/env node | ||
|
||
const path = require('path'); | ||
const { spawn } = require('child_process'); | ||
const { loadConfig } = require('@wordpress/env/lib/config'); | ||
|
||
function spawnCommandDirectly({ container, command, dockerComposeConfigPath }) { | ||
const composeCommand = [ | ||
'-f', | ||
dockerComposeConfigPath, | ||
'exec -T', | ||
container, | ||
...command.split(' '), // The command will fail if passed as a complete string. | ||
]; | ||
|
||
return new Promise((resolve, reject) => { | ||
const childProc = spawn('docker compose', composeCommand, { | ||
stdio: 'inherit', | ||
shell: true, | ||
}); | ||
childProc.on('error', reject); | ||
childProc.on('exit', (code) => { | ||
// Code 130 is set if the user tries to exit with ctrl-c before using | ||
// ctrl-d (so it is not an error which should fail the script.) | ||
if (code === 0 || code === 130) { | ||
resolve(); | ||
} else { | ||
reject(code); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
const run = async () => { | ||
const configPath = path.resolve(); | ||
const { dockerComposeConfigPath } = await loadConfig(configPath); | ||
|
||
const container = process.argv[2]; | ||
const command = process.argv.splice(3).join(' '); | ||
|
||
try { | ||
await spawnCommandDirectly({ | ||
container, | ||
command, | ||
dockerComposeConfigPath, | ||
}); | ||
} catch (errorCode) { | ||
process.exit(errorCode); | ||
} | ||
}; | ||
|
||
run(); |
Oops, something went wrong.