Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/e2e tests workflow #776

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
de23420
Install needed packages & setup new e2e scripts
carstingaxion Aug 11, 2024
493c9aa
REMOVE special port settings for wp-env (which may be a problem, I'm …
carstingaxion Aug 11, 2024
c38da61
Add configuration files to run Playwright tests
carstingaxion Aug 11, 2024
673e566
Update Github workflow to use wp-env for e2e tests
carstingaxion Aug 11, 2024
e20f215
Rename folder with tests
carstingaxion Aug 11, 2024
1ed3bd1
NEW (WIP) e2e-tests utilising the wordpress/e2e-test-utils-playwright…
carstingaxion Aug 11, 2024
da4fe13
Fix script name to start wp-env
carstingaxion Aug 11, 2024
6a4ea6f
Add basic dev-documentation about e2e-tests
carstingaxion Aug 11, 2024
9477ecc
Run BUILD before Playwright tests
carstingaxion Aug 12, 2024
94d99f6
DO NOT MERGE // FOR DEBUGGING ONLY // simple Gutenberg paragraph bloc…
carstingaxion Aug 12, 2024
eb8dbdc
Remove custom globalSetup & env vars in favor of Gutenbergs defaults
carstingaxion Aug 12, 2024
a888cc2
TRY: Disable blank mappings for themes & plugins in wp-env
carstingaxion Aug 12, 2024
ee9544c
Add caching to the Playwright browser download step
carstingaxion Aug 12, 2024
d1b3b3a
Creating a short lived node_modules cache to be used by multiple accr…
carstingaxion Aug 12, 2024
308ca4e
DISABLED TEMPORARY // REVERT BEFORE MERGE // to make debugging easier
carstingaxion Aug 12, 2024
9cd89ad
Fix the artifacts upload on CI, to get traces and screenshots from fa…
carstingaxion Aug 12, 2024
ea0739d
Update actions/checkout to v4
carstingaxion Aug 12, 2024
6f2c8f5
Run npm install, only when really needed
carstingaxion Aug 12, 2024
f3c6ad4
Remove steps, that are being done via npm pre-script runs
carstingaxion Aug 12, 2024
b7fad4b
Cleanup
carstingaxion Aug 12, 2024
421c3b0
Move doc into contributor folder
carstingaxion Aug 16, 2024
ed4ff96
Rename scripts to align with screenshot-workflow
carstingaxion Aug 16, 2024
cb6e65b
Remove debug stuff
carstingaxion Aug 16, 2024
c7dae87
Clean up
carstingaxion Aug 16, 2024
345fd9e
Re-Enable 'publish event through admin side' (WIP)
carstingaxion Aug 16, 2024
cab2d14
Resolve merge conflicts
carstingaxion Aug 17, 2024
d8e59a0
Re-Add test:e2e scripts
carstingaxion Aug 17, 2024
158a7ef
Merge branch 'main' into feature/e2e-tests-workflow
carstingaxion Aug 17, 2024
082f6c5
Fix indention
carstingaxion Aug 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 75 additions & 33 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,81 @@
name: E2E Tests

on:
push:
branches:
- main
workflow_dispatch:
pull_request:

# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the branch name for pull requests
# or the commit hash for any other events.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true


jobs:
playwright:
name: Playwright Tests
e2e-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
# matrix:
# node: ['14']

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Log debug information
run: |
npm --version
node --version
git --version
php --version
composer --version

- name: Install NodeJS
uses: actions/setup-node@v2
with:
node-version-file: '.nvmrc'

- name: NPM install
run: npm ci --legacy-peer-deps

- name: Playwright install
run: npx playwright install --with-deps

- name: Run Playwright
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WP_ADMIN_PASSWORD: ${{ secrets.WP_ADMIN_PASSWORD }}
run: npm run test:e2e
if: ${{ success() || failure() }}
- name: Checkout
uses: actions/checkout@v4

- uses: actions/cache@v4
id: playwright-cache
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }}

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
# Enable built-in functionality for caching and restoring dependencies, which is disabled by default.
# The actions/setup-node uses actions/cache under the hood.
# https://github.com/actions/setup-node#caching-global-packages-data
cache: 'npm'


# Restoring the short lived node_modules cache
# to be used accross all workflows running on the last commit.
# https://github.com/actions/cache/blob/main/caching-strategies.md#creating-a-short-lived-cache
- uses: actions/cache/restore@v4
id: node_modules-cache
with:
path: |
./node_modules
key: ${{ runner.os }}-node_modules-${{ github.sha }}-${{ hashFiles('package-lock.json') }}

- name: NPM install
if: steps.node_modules-cache.outputs.cache-hit != 'true'
run: npm ci --legacy-peer-deps

# Creating a short lived node_modules cache
- uses: actions/cache/save@v4
if: steps.node_modules-cache.outputs.cache-hit != 'true'
with:
path: |
./node_modules
key: ${{ steps.node_modules-cache.outputs.cache-primary-key }}

- name: Install Playwright dependencies
run: npx playwright install --with-deps
if: steps.playwright-cache.outputs.cache-hit != 'true'
- run: npx playwright install-deps
if: steps.playwright-cache.outputs.cache-hit == 'true'

- name: Starting Playwright & Running the tests
run: |
npm run test:e2e

- name: Retain failed test results
uses: actions/upload-artifact@v3
if: failure()
with:
name: test-results-matrix-less-debugging
path: artifacts/test-results/
30 changes: 30 additions & 0 deletions docs/contributor/e2e-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# e2e testing

GatherPress allows to run automated and manual end-to-end tests, while sharing the same, `wp-env` based, setup.

## Automated tests

Check the results of the _e2e-tests action workflow_ at `https://github.com/GatherPress/gatherpress/actions/workflows/e2e-tests.yml`.

## Manual testing

0. Have `node` installed
1. Have `docker` running
2. Open the plugin folder in a terminal
3. _Choose one of the following options_
- Run Playwright normally
```
npm run test:e2e
```

- Run Playwright visually (and change what's happening)
```
npm run test:e2e:ui
```
![grafik](https://github.com/user-attachments/assets/1627dff7-363e-447e-9981-adac610ac888)

- Run Playwright in debugging mode (and record what's happening)
```
npm run test:e2e:debug
```
- Run Tests independently _AND_ visually using the [Playwright VSCode extension](https://playwright.dev/docs/getting-started-vscode)
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
"screenshots:wporg": "wp-scripts test-playwright --config .github/scripts/wordpress-org-screenshots/playwright.config.ts",
"screenshots:wporg:debug": "wp-scripts test-playwright --config .github/scripts/wordpress-org-screenshots/playwright.config.ts --debug",
"screenshots:wporg:ui": "wp-scripts test-playwright --config .github/scripts/wordpress-org-screenshots/playwright.config.ts --ui",
"test:e2e": "playwright test --config=playwright.config.js",
"pretest:e2e": "wp-scripts build && wp-env start",
"pretest:e2e:debug": "wp-scripts build && wp-env start",
"pretest:e2e:ui": "wp-scripts build && wp-env start",
"test:e2e": "wp-scripts test-playwright --config test/e2e/playwright.config.ts",
"test:e2e:debug": "wp-scripts test-playwright --config test/e2e/playwright.config.ts --debug",
"test:e2e:ui": "wp-scripts test-playwright --config test/e2e/playwright.config.ts --ui",
"test:unit:js": "wp-scripts test-unit-js --coverage --testResultsProcessor=jest-sonar-reporter",
"pretest:unit:php": "wp-env start --xdebug",
"test:unit:php": "wp-env run tests-wordpress php -dxdebug.mode=coverage /var/www/html/wp-content/plugins/gatherpress/vendor/bin/phpunit -c /var/www/html/wp-content/plugins/gatherpress/phpunit.xml.dist --coverage-clover=coverage.xml --coverage-html=build/coverage-report",
Expand Down
83 changes: 0 additions & 83 deletions playwright.config.js

This file was deleted.

41 changes: 0 additions & 41 deletions test/e2e/admin-tests/gatherpress-admin-venue.spec.js

This file was deleted.

29 changes: 0 additions & 29 deletions test/e2e/admin-tests/gatherpress-admin.spec.js

This file was deleted.

66 changes: 66 additions & 0 deletions test/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* External dependencies
*/
import { defineConfig, devices } from '@playwright/test';

/**

Check failure on line 6 in test/e2e/playwright.config.ts

View workflow job for this annotation

GitHub Actions / JavaScript Coding Standards

Expected JSDoc block lines to be aligned
* WordPress dependencies
*

Check failure on line 8 in test/e2e/playwright.config.ts

View workflow job for this annotation

GitHub Actions / JavaScript Coding Standards

Delete `·`
* Playwright default configuration, that is used & provided by Gutenberg.
* https://github.com/WordPress/gutenberg/blob/trunk/packages/scripts/config/playwright.config.js
*/
// using Object Rest Spread operator magic
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax
// const { use, ...baseConfig} = require( '@wordpress/scripts/config/playwright.config' );
const { ...baseConfig} = require( '@wordpress/scripts/config/playwright.config' );

Check failure on line 15 in test/e2e/playwright.config.ts

View workflow job for this annotation

GitHub Actions / JavaScript Coding Standards

Replace `·...baseConfig}·=·require(·'@wordpress/scripts/config/playwright.config'·` with `⏎↹...baseConfig⏎}·=·require('@wordpress/scripts/config/playwright.config'`

export default defineConfig({
...baseConfig,

Check failure on line 18 in test/e2e/playwright.config.ts

View workflow job for this annotation

GitHub Actions / JavaScript Coding Standards

Replace `····` with `↹`

// This directory holds all the test files.

Check failure on line 20 in test/e2e/playwright.config.ts

View workflow job for this annotation

GitHub Actions / JavaScript Coding Standards

Replace `····` with `↹`
// https://playwright.dev/docs/api/class-testconfig#test-config-test-dir

Check failure on line 21 in test/e2e/playwright.config.ts

View workflow job for this annotation

GitHub Actions / JavaScript Coding Standards

Replace `····` with `↹`
//

Check failure on line 22 in test/e2e/playwright.config.ts

View workflow job for this annotation

GitHub Actions / JavaScript Coding Standards

Replace `····` with `↹`
// IDEA: Maybe this should be set to "../../src/"

Check failure on line 23 in test/e2e/playwright.config.ts

View workflow job for this annotation

GitHub Actions / JavaScript Coding Standards

Replace `····` with `↹`
// where the test files would be housed directly with their components, blocks, etc.

Check failure on line 24 in test/e2e/playwright.config.ts

View workflow job for this annotation

GitHub Actions / JavaScript Coding Standards

Replace `····` with `↹`
testDir: 'tests',

Check failure on line 25 in test/e2e/playwright.config.ts

View workflow job for this annotation

GitHub Actions / JavaScript Coding Standards

Replace `····` with `↹`

// Configure projects for major browsers
// We can test on different or multiple browsers if needed.
// https://playwright.dev/docs/test-projects#configure-projects-for-multiple-browsers
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},

// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },

// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],
});
Loading
Loading