-
Notifications
You must be signed in to change notification settings - Fork 466
/
Copy pathplaywright.config.ts
146 lines (128 loc) · 4.01 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
140
141
142
143
144
145
146
import os from 'node:os'
import {
defineConfig,
devices,
type PlaywrightTestConfig,
type PlaywrightTestProject,
} from '@playwright/test'
import {loadEnvFiles} from './scripts/utils/loadEnvFiles'
import {readBoolEnv, readEnv} from './test/e2e/helpers/envVars'
loadEnvFiles()
// Read environment variables
const CI = readBoolEnv('CI', false)
const HEADLESS = readBoolEnv('HEADLESS', true)
const BASE_URL = readEnv('SANITY_E2E_BASE_URL') || 'http://localhost:3333'
const PROJECT_ID = readEnv('SANITY_E2E_PROJECT_ID')
const TOKEN = readEnv('SANITY_E2E_SESSION_TOKEN')
const E2E_DEBUG = readBoolEnv('SANITY_E2E_DEBUG', false)
// Paths
const TESTS_PATH = './test/e2e/tests'
const ARTIFACT_OUTPUT_PATH = './test/e2e/results'
// OS-specific browsers to include
const OS_BROWSERS =
os.platform() === 'darwin' ? [{name: 'webkit', use: {...devices['Desktop Safari']}}] : []
/**
* Excludes the GitHub reporter until https://github.com/microsoft/playwright/issues/19817 is resolved, since it creates a lot of noise in our PRs.
* @param reporters - The reporters config to exclude the github reporter from
*/
function excludeGithub(reporters: PlaywrightTestConfig['reporter']) {
if (Array.isArray(reporters)) {
return reporters.filter((reporterDescription) => reporterDescription[0] !== 'github')
}
return reporters === 'github' ? undefined : reporters
}
const CHROMIUM_PROJECT: PlaywrightTestProject = {
name: 'chromium',
use: {
...devices['Desktop Chrome'],
baseURL: `${BASE_URL}/chromium`,
permissions: ['clipboard-read', 'clipboard-write'],
launchOptions: {
args: ['--disable-gpu', '--disable-software-rasterizer'],
},
contextOptions: {
// chromium-specific permissions
permissions: ['clipboard-read', 'clipboard-write'],
reducedMotion: 'reduce',
},
},
}
const FIREFOX_PROJECT: PlaywrightTestProject = {
name: 'firefox',
use: {
...devices['Desktop Firefox'],
baseURL: `${BASE_URL}/firefox`,
launchOptions: {
firefoxUserPrefs: {
'dom.events.asyncClipboard.readText': true,
'dom.events.testing.asyncClipboard': true,
},
},
contextOptions: {
reducedMotion: 'reduce',
},
},
}
/**
* See https://playwright.dev/docs/test-configuration.
*/
const playwrightConfig: PlaywrightTestConfig = {
globalSetup: './test/e2e/globalSetup',
testDir: TESTS_PATH,
/* Maximum time one test can run for. */
timeout: 30 * 1000,
fullyParallel: true,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 1000 * 60 * 5,
},
/* Folder for test artifacts such as screenshots, videos, traces, etc. */
outputDir: ARTIFACT_OUTPUT_PATH,
retries: 1,
reporter: excludeGithub([['list'], ['blob']]),
use: {
actionTimeout: 10000,
trace: 'on-first-retry',
viewport: {width: 1728, height: 1000},
storageState: {
cookies: [],
origins: [
{
origin: BASE_URL,
localStorage: [
{
name: `__studio_auth_token_${PROJECT_ID}`,
value: JSON.stringify({
token: TOKEN,
time: new Date().toISOString(),
}),
},
],
},
],
},
video: 'retain-on-failure',
baseURL: BASE_URL,
headless: HEADLESS,
contextOptions: {reducedMotion: 'reduce'},
},
/* Configure projects for major browsers */
projects: E2E_DEBUG ? [CHROMIUM_PROJECT] : [CHROMIUM_PROJECT, FIREFOX_PROJECT, ...OS_BROWSERS],
/* Run your local dev server before starting the tests */
webServer: BASE_URL.includes('.sanity.dev')
? undefined
: {
/**
* If it is running in CI just start the production build assuming that studio is already build
* Locally run the dev server
*/
command: CI ? 'pnpm e2e:start' : 'pnpm e2e:dev',
port: 3339,
reuseExistingServer: !CI,
stdout: 'pipe',
},
}
export default defineConfig(playwrightConfig)