-
Notifications
You must be signed in to change notification settings - Fork 2
/
playwright.config.ts
139 lines (123 loc) · 4.64 KB
/
playwright.config.ts
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { defineConfig, devices } from '@playwright/test';
import { STORAGE_STATE_AUTHENTICATED, STORAGE_STATE_UNAUTHENTICATED } from './tests/e2e/constants';
/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
// Directory where all tests are located
testDir: './tests/e2e',
// Start local dev server before starting the tests
webServer: {
command: 'npm run start',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
},
// Shared settings for all the projects below.
// Docs: https://playwright.dev/docs/api/class-testoptions
use: {
// Base URL to use in actions like `await page.goto('/')`
baseURL: 'http://localhost:3000',
// Set whether to record traces
// Docs: https://playwright.dev/docs/api/class-testoptions#test-options-trace
trace: 'retain-on-failure',
// Set whether to record screenshots
// Docs: https://playwright.dev/docs/api/class-testoptions#test-options-screenshot
screenshot: 'off',
// Set whether to record videos
// Docs: https://playwright.dev/docs/api/class-testoptions#test-options-video
video: 'off',
},
// Reporter to use for test results
// Uses GitHub Actions reporter on CI, otherwise uses HTML reporter
// Docs: https://playwright.dev/docs/test-reporters
reporter: process.env.CI ? 'github' : 'html',
// Fail the build on CI if you accidentally left test.only in the source code
// Docs: https://playwright.dev/docs/api/class-testconfig#test-config-forbid-only
forbidOnly: !!process.env.CI,
// The maximum number of retry attempts given to failed tests
// Docs: https://playwright.dev/docs/api/class-testconfig#test-config-retries
retries: process.env.CI ? 2 : 0,
// Whether to run tests in parallel
// Docs: https://playwright.dev/docs/api/class-testconfig#test-config-fully-parallel
fullyParallel: process.env.TEST_MODE_PARALLEL === 'true' ? true : false,
// Number of parallel workers OR %age of logical CPUs to use
// Github Actions runners have 2 logical CPU cores
// Defaults to half of the logical CPU cores available
// Docs: https://playwright.dev/docs/api/class-testconfig#test-config-workers
workers: process.env.TEST_MODE_PARALLEL ? 4 : 1,
// Limit the numbers of failures to set a fail-fast strategy on CI
// Docs: https://playwright.dev/docs/api/class-testconfig#test-config-max-failures
maxFailures: process.env.CI ? 5 : undefined,
// Configure project specific settings
// Docs: https://playwright.dev/docs/test-projects
projects:
process.env.TEST_MODE_PARALLEL === 'true'
? [
{
name: 'Setup unauthenticated user',
testMatch: /no-auth\.setup\.ts/,
},
{
name: 'Setup authenticated user',
testMatch: /auth\.setup\.ts/,
},
{
name: 'Parallel Logged In User Tests',
...(process.env.RELEASE === 'true' ? {} : { testIgnore: /.*\.release\.spec\.ts/ }),
use: {
...devices['Desktop Chrome'],
// Use prepared auth state.
storageState: STORAGE_STATE_AUTHENTICATED,
extraHTTPHeaders: {
// Add x-api-key token to all authenticated requests.
'x-api-key': `${process.env.TEST_USER_API_KEY}`,
},
},
testDir: './tests/e2e/parallel',
dependencies: ['Setup authenticated user'],
},
{
name: 'Non-Logged In User Tests',
testMatch: /.*\.no-auth.spec.ts/,
use: {
...devices['Desktop Chrome'],
storageState: STORAGE_STATE_UNAUTHENTICATED,
},
testDir: './tests/e2e/parallel',
dependencies: ['Setup unauthenticated user'],
},
]
: [
{
name: 'Setup authenticated user',
testMatch: /auth\.setup\.ts/,
},
{
name: 'Logged In User Tests',
...(process.env.RELEASE === 'true' ? {} : { testIgnore: /.*\.release\.spec\.ts/ }),
use: {
...devices['Desktop Chrome'],
// Use prepared auth state.
storageState: STORAGE_STATE_AUTHENTICATED,
extraHTTPHeaders: {
// Add x-api-key token to all authenticated requests.
'x-api-key': `${process.env.TEST_USER_API_KEY}`,
},
},
testDir: './tests/e2e/sequential',
dependencies: ['Setup authenticated user'],
},
],
// Timeout for each test in milliseconds
// Docs: https://playwright.dev/docs/test-timeouts
timeout: 60 * 1000,
// Timeout for each expect/assertion in milliseconds
// Docs: https://playwright.dev/docs/test-timeouts
expect: {
timeout: 10 * 1000,
},
// Global timeout for overall test run in milliseconds
// By default, Playwright has no global timeout but suggests a "sensible limit" can be set if needed
// Docs: https://playwright.dev/docs/test-timeouts#global-timeout
globalTimeout: 30 * 60 * 1000,
});