Repository navigation
Expand file tree
/
Copy pathplaywright.config.js
More file actions
81 lines (73 loc) · 2.61 KB
/
Copy pathplaywright.config.js
File metadata and controls
81 lines (73 loc) · 2.61 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
81
// @ts-check
const path = require("path");
const { devices } = require("@playwright/test");
const { loadEnvironment } = require("./src/config/environment");
const { ROOT_DIR, STORAGE_STATE } = require("./src/config/paths");
// Throws a clear error early if TEST_ENV is unknown or the environment file is invalid.
const env = loadEnvironment();
const isCI = !!process.env.CI;
const REPORTS_DIR = path.join(ROOT_DIR, "reports");
/**
* Environment is selected with TEST_ENV (dev | qa | staging | production). See docs/environments.md.
* @type {import('@playwright/test').PlaywrightTestConfig}
*/
const config = {
testDir: "./tests",
outputDir: path.join(REPORTS_DIR, "test-results"),
timeout: 30 * 1000,
expect: { timeout: 5 * 1000 },
forbidOnly: isCI,
retries: isCI ? 2 : 0,
workers: isCI ? 1 : undefined,
// Production is read-only: only @prod tests may run. Combines with --grep on the command line.
grep: env.readOnly ? /@prod/ : undefined,
reporter: [
isCI ? ["github"] : ["list"],
[
"monocart-reporter",
{
name: `Test report (${env.name})`,
outputFile: path.join(REPORTS_DIR, "monocart", "index.html"),
},
],
["html", { outputFolder: path.join(REPORTS_DIR, "html"), open: "never" }],
...(isCI
? [
["junit", { outputFile: path.join(REPORTS_DIR, "junit", "results.xml") }],
// JSON keeps the flaky-test count, which JUnit does not report. Read by scripts/ci-summary.js.
["json", { outputFile: path.join(REPORTS_DIR, "json", "results.json") }],
]
: []),
["./src/reporters/custom-reporter.js"],
],
use: {
baseURL: env.baseUrl,
headless: process.env.HEADED !== "true",
// A stuck click fails after 10 seconds with a clear message, instead of waiting for the whole test timeout.
actionTimeout: 10 * 1000,
screenshot: "only-on-failure",
trace: isCI ? "on-first-retry" : "retain-on-failure",
},
projects: [
// Logs in once and saves the session. Every test in it is a prerequisite, tagged to always run.
{
name: "setup",
testMatch: /auth\.setup\.js$/,
use: { ...devices["Desktop Chrome"] },
},
// Tests that must start logged out (the login page itself).
{
name: "public",
testMatch: /auth\/login\.spec\.js$/,
use: { ...devices["Desktop Chrome"] },
},
// Everything else reuses the saved session.
{
name: "authenticated",
testIgnore: [/auth\.setup\.js$/, /auth\/login\.spec\.js$/],
dependencies: ["setup"],
use: { ...devices["Desktop Chrome"], storageState: STORAGE_STATE },
},
],
};
module.exports = config;