-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathplaywright.config.ts
More file actions
80 lines (70 loc) · 2.35 KB
/
Copy pathplaywright.config.ts
File metadata and controls
80 lines (70 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { defineConfig, devices } from "@playwright/test";
// Get a random port between 10000 and 65000
const getRandomPort = () => Math.floor(Math.random() * (65000 - 10000) + 10000);
// Check if we're testing against production build
const isTestingBuild = process.env.TEST_BUILD === "true";
// Check which type of tests to run
const testType = process.env.TEST_TYPE || "e2e"; // "e2e" or "visuals"
// Use TEST_PORT environment variable if set, otherwise generate a random port
const port = process.env.TEST_PORT
? parseInt(process.env.TEST_PORT)
: process.env.PLAYWRIGHT_TEST_PORT
? parseInt(process.env.PLAYWRIGHT_TEST_PORT)
: getRandomPort();
// Set it in env to ensure consistency across config reloads
process.env.PLAYWRIGHT_TEST_PORT = String(port);
// console.log(
// `Using port ${port} for Playwright ${testType} tests (${isTestingBuild ? "preview" : "dev"} mode)`,
// );
// Get base path from environment variable
const basePath = process.env.BASE_PATH || "";
export default defineConfig({
testDir: testType === "screenshots" ? "./test/screenshots" : "./test/e2e",
outputDir:
testType === "screenshots" ? "./test/results/screenshots" : "./test/results/test-results",
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
// reporter: [
// [
// "html",
// {
// outputFolder:
// testType === "visuals"
// ? "./test/results/playwright-visual-report"
// : "./test/results/playwright-report",
// },
// ],
// ],
use: {
baseURL: `http://localhost:${port}${basePath}`,
trace: "on-first-retry",
// Visual tests typically need more time for screenshot operations
...(testType === "visuals" && {
navigationTimeout: 30000,
actionTimeout: 15000,
}),
},
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},
],
webServer: {
command: isTestingBuild
? `npm run preview -- --port ${port}${basePath ? ` --base ${basePath}` : ""}`
: `npm run dev -- --port ${port}`,
port: port,
timeout: 120 * 1000,
reuseExistingServer: false,
stdout: "pipe",
stderr: "pipe",
env: {
...process.env,
DEV_PORT: String(port), // Pass the test port as DEV_PORT to the server
BASE_PATH: basePath,
},
},
});