Skip to content

Commit fd103f9

Browse files
tests: Setup E2E testing with playwright (#107)
* feat: add `.wp-env.json` * feat: update `playwright.config.js` with setup and teardown * feat: scaffold the `e2e-tests` package * feat: add e2e-test utils * feat: add an example test * refactor: ignore `n/no-process-env` and `no-console` for e2e-tests/utils * chore: delete .gitkeep * chore: update package and package-lock * feat: add `test:e2e:headed` command * fix: update snapwp-helper download path to latest * refactor: change theme to twentytwentyfive * refactor: convert into utility functions * refactor: add setup * refactor: projects in playwright config * refactor: retry for `n` attempts in `waitForServer` * chore: update .gitignore * feat: add `setupSnapWPHelper` * feat: add `startProxyRegistry` * feat: add `cleanup` function * refactor: call `startProxyRegistry` in `setupNextApp` * refactor: call `setupSnapWPHelper` in `setupWordPress` * refactor: call `cleanup` if `setup` fails * refactor: use `cleanup` in `teardown` * refactor: use local snapwp-helper in `wp-env.json` * chore: add test-app and snapwp-helper to .gitignore * chore: format * refactor: `waitForServer` * fix: remove unnecessary build step * chore: add changelog * Apply suggestions from code review --------- Co-authored-by: Dovid Levine <[email protected]> Co-authored-by: Dovid Levine <[email protected]>
1 parent c3c045c commit fd103f9

21 files changed

+1725
-15
lines changed

.changeset/sweet-mangos-help.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@snapwp/e2e-tests": patch
3+
---
4+
5+
tests: Setup E2E testing with Playwright

.eslintrc.cjs

+7
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,12 @@ module.exports = {
138138
project: true,
139139
},
140140
},
141+
{
142+
files: [ '**/packages/e2e-tests/src/utils/*.ts' ],
143+
rules: {
144+
'n/no-process-env': 'off',
145+
'no-console': 'off',
146+
},
147+
},
141148
],
142149
};

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ coverage
3434

3535
# Build output
3636
dist/
37+
38+
# E2E test files
39+
test-app/
40+
snapwp-helper/

.wp-env.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"core": null,
3+
"plugins": [
4+
"https://downloads.wordpress.org/plugin/wp-graphql.zip",
5+
"https://github.com/wpengine/wp-graphql-content-blocks/releases/latest/download/wp-graphql-content-blocks.zip",
6+
"./snapwp-helper"
7+
],
8+
"themes": [ "https://downloads.wordpress.org/theme/twentytwentyfive.zip" ],
9+
"config": {
10+
"WP_DEBUG": true,
11+
"SCRIPT_DEBUG": true,
12+
"WP_DEBUG_LOG": true,
13+
"WP_DEBUG_DISPLAY": false,
14+
"WP_ENVIRONMENT_TYPE": "local",
15+
"GRAPHQL_DEBUG": true
16+
}
17+
}

config/playwright.config.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
import { defineConfig, devices } from '@playwright/test';
22

33
export default defineConfig( {
4-
testDir: '../e2e-tests',
4+
testDir: '../packages/e2e-tests/src',
55
fullyParallel: true,
66
forbidOnly: !! process.env.CI,
77
retries: process.env.CI ? 2 : 0,
88
workers: process.env.CI ? 1 : undefined,
9-
reporter: 'html',
9+
reporter: process.env.CI ? 'dot' : 'list',
1010
use: {
1111
trace: 'on-first-retry',
1212
},
13-
1413
projects: [
14+
{
15+
name: 'setup wordpress and next app',
16+
testMatch: /setup\.ts/,
17+
teardown: 'teardown',
18+
},
1519
{
1620
name: 'chromium',
1721
use: { ...devices[ 'Desktop Chrome' ] },
22+
dependencies: [ 'setup wordpress and next app' ],
23+
},
24+
{
25+
name: 'teardown',
26+
testMatch: /teardown\.ts/,
1827
},
1928
],
20-
21-
/* Run local dev server before starting the tests */
22-
// TODO: This should be implemented after scaffolding the next app.
23-
// webServer: {
24-
// command: 'npm run start',
25-
// url: 'http://127.0.0.1:3000',
26-
// reuseExistingServer: !process.env.CI,
27-
// },
2829
} );

e2e-tests/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)