Skip to content

Commit 27e6de3

Browse files
committed
test(playwright): refactor testing framework to use projects
1 parent 6ab9614 commit 27e6de3

14 files changed

+44
-38
lines changed

.github/workflows/test.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ jobs:
7474
KEYCLOAK_URL: "https://keycloak.xchem-dev.diamond.ac.uk/auth/realms/xchem"
7575
PW_USERNAME: "dmit-user-a"
7676
PW_PASSWORD: "${{ secrets.DMIT_USER_A_PASSWORD }}"
77-
TEST_PORT: 3000
7877
run: pnpm test:ci
7978
- name: Upload results for bath path
8079
if: always()

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"typescript.tsdk": "node_modules/typescript/lib",
3-
"iridium.npm.packageManager": "pnpm",
43
"editor.tabSize": 2,
54
"emmet.includeLanguages": {
65
"mdx": "html"
@@ -21,4 +20,5 @@
2120
".env": "shellscript",
2221
".env.*": "shellscript",
2322
},
23+
"playwright.reuseBrowser": false,
2424
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"lint": "eslint --cache --max-warnings=0",
2323
"format": "eslint --fix --cache --max-warnings=0",
2424
"format:all": "eslint --fix --cache .",
25-
"test": "export $(cat .env.test.local | xargs) && playwright test",
25+
"test": "playwright test",
2626
"test:debug": "PWDEBUG=1 pnpm t -- --headed",
2727
"test:ci": "playwright test",
2828
"analyze": "ANALYZE=true next build",
@@ -106,6 +106,7 @@
106106
"@next/bundle-analyzer": "13.2.4",
107107
"@playwright/test": "1.31.2",
108108
"@squonk/eslint-config": "0.5.0",
109+
"dotenv": "^16.0.3",
109110
"eslint": "8.36.0",
110111
"husky": "8.0.3",
111112
"identity-obj-proxy": "3.0.0",

playwright.config.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1-
import type { PlaywrightTestConfig } from "@playwright/test";
1+
import { defineConfig } from "@playwright/test";
2+
import path from "node:path";
23

3-
const { BASE_URL, BASE_PATH = "", TEST_PORT } = process.env;
4+
const { BASE_URL, BASE_PATH = "" } = process.env;
45

5-
if (!BASE_URL || !TEST_PORT) {
6-
throw new Error("Possible missing environment variable: BASE_URL or TEST_PORT");
7-
}
6+
require("dotenv").config({ path: path.resolve(process.cwd(), ".env.test.local") });
87

9-
const config: PlaywrightTestConfig = {
10-
globalSetup: require.resolve("./global-setup"),
11-
webServer: {
12-
command: `pnpm start -- -p ${TEST_PORT}`,
13-
port: Number(TEST_PORT),
14-
timeout: 200 * 1000,
15-
env: {
16-
NODE_ENV: "test",
8+
export default defineConfig({
9+
projects: [
10+
{ name: "setup", testMatch: "**/*.setup.ts" },
11+
{
12+
name: "browser",
13+
dependencies: ["setup"],
14+
use: { storageState: "storageState.json" },
15+
retries: 3,
16+
timeout: 60000,
17+
testMatch: "**/*.browser.ts",
1718
},
18-
},
19+
{ name: "node", testMatch: "**/*.node.ts" },
20+
],
1921
use: {
2022
baseURL: BASE_URL + BASE_PATH,
21-
storageState: "storageState.json",
2223
screenshot: "on",
2324
trace: "on-first-retry", // record traces on first retry of each test
2425
},
25-
timeout: 60000,
26-
retries: 3,
27-
};
28-
29-
export default config;
26+
webServer: {
27+
command: `pnpm start`,
28+
port: 3000,
29+
timeout: 200 * 1000,
30+
env: {
31+
NODE_ENV: "test",
32+
},
33+
},
34+
testDir: "tests",
35+
});

pnpm-lock.yaml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)