Skip to content

Commit

Permalink
Merge pull request #385 from woocommerce/dev/add-e2e-tests
Browse files Browse the repository at this point in the history
Add E2E testing to track events across all page types
  • Loading branch information
mikkamp authored Mar 11, 2024
2 parents 01a2377 + f5ae330 commit 128ef39
Show file tree
Hide file tree
Showing 27 changed files with 2,669 additions and 21 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: E2E Tests

on:
push:
branches:
- "release/**"
pull_request:
branches:
- "release/**"
workflow_dispatch:
inputs:
wp-rc-version:
description: 'WordPress version for Release Candidate (ex. 6.3-RC3)'
wc-rc-version:
description: 'WooCommerce version for Release Candidate (ex. 8.0.0-rc.1)'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
E2ETests:
name: E2E Tests
runs-on: ubuntu-latest
env:
FORCE_COLOR: 2
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Prepare PHP
uses: woocommerce/grow/prepare-php@actions-v1
with:
install-deps: "no"

- name: Prepare node
uses: woocommerce/grow/prepare-node@actions-v1
with:
node-version-file: ".nvmrc"
ignore-scripts: "no"

- name: Build production bundle
run: |
echo "::group::Build log"
npm run build
echo "::endgroup::"
- name: Start wp-env container
run: npm run wp-env:up

- name: Install WP release candidate (optional)
if: github.event.inputs.wp-rc-version != ''
run: |
npm run -- wp-env run tests-cli -- wp core update --version=${{ github.event.inputs.wp-rc-version }}
npm run -- wp-env run tests-cli -- wp core update-db
- name: Install WC release candidate (optional)
if: github.event.inputs.wc-rc-version != ''
run: |
npm run -- wp-env run tests-cli -- wp plugin update woocommerce --version=${{ github.event.inputs.wc-rc-version }}
npm run -- wp-env run tests-cli -- wp wc update
- name: Download and install Chromium browser.
run: npx playwright install chromium

- name: Run tests
run: npm run test:e2e

- name: Archive e2e failure screenshots
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: e2e-screenshots
path: tests/e2e/test-results/report/**/*.png
if-no-files-found: ignore
retention-days: 5
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ build
/logs/*
!/logs/.htaccess

tests/e2e/config/local-*
tests/e2e/test-results
.phpunit.result.cache
.eslintcache

Expand Down
16 changes: 16 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"phpVersion": "8.0",
"plugins": [
"https://github.com/WP-API/Basic-Auth/archive/master.zip",
"./tests/e2e/test-data",
"./tests/e2e/test-snippets",
"."
],
"mappings": {
"wp-cli.yml": "./tests/e2e/config/wp-cli.yml"
},
"lifecycleScripts": {
"afterStart": "./tests/e2e/bin/test-env-setup.sh",
"afterClean": "./tests/e2e/bin/test-env-setup.sh"
}
}
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ Google Analytics for WooCommerce utilizes npm scripts for task management utilit

_For more info see: [WordPress.org > Plugin Unit Tests](https://make.wordpress.org/cli/handbook/misc/plugin-unit-tests/#running-tests-locally)._

## E2E Testing

E2E testing uses [wp-env](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/) which requires [Docker](https://www.docker.com/).

Make sure Docker is running in your machine, and run the following:

`npm run wp-env:up` - This will automatically download and run WordPress in a Docker container. You can access it at http://localhost:8889 (Username: admin, Password: password).

To install the PlayWright browser locally you can run:
`npx playwright install chromium`

Run E2E testing:

- `npm run test:e2e` to run the test in headless mode.
- `npm run test:e2e-dev` to run the tests in Chromium browser.

To remove the Docker container and images (this will **delete everything** in the WordPress Docker container):

`npm run wp-env destroy`

:warning: Currently, the E2E testing on GitHub Actions is only run automatically after opening a PR with `release/*` branches or pushing changes to `release/*` branches. To run it manually, please visit [here](../../actions/workflows/e2e-tests.yml) and follow [this instruction](https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow?tool=webui) to do so.

## Coding standards checks

1. Run `composer install` (_if you haven't done so already_)
Expand Down
Loading

0 comments on commit 128ef39

Please sign in to comment.