-
Notifications
You must be signed in to change notification settings - Fork 426
/
playwright.config.ts
78 lines (68 loc) · 2.24 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
import {defineConfig, type PlaywrightTestConfig} from '@playwright/test'
import {createPlaywrightConfig} from '@sanity/test'
import {loadEnvFiles} from './scripts/utils/loadEnvFiles'
import {readBoolEnv, readEnv} from './test/e2e/helpers/envVars'
loadEnvFiles()
const CI = readBoolEnv('CI', false)
const HEADLESS = readBoolEnv('HEADLESS', true)
/**
* 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 playwrightConfig = createPlaywrightConfig({
projectId: readEnv('SANITY_E2E_PROJECT_ID'),
token: readEnv('SANITY_E2E_SESSION_TOKEN'),
playwrightOptions(config): PlaywrightTestConfig {
const projects = [
...(config?.projects?.map((project) => {
const projectConfig = {
...project,
}
if (project.name === 'chromium') {
return {
...projectConfig,
permissions: ['clipboard-read', 'clipboard-write'],
contextOptions: {
// chromium-specific permissions
permissions: ['clipboard-read', 'clipboard-write'],
},
}
}
if (project.name === 'firefox') {
return {
...projectConfig,
launchOptions: {
firefoxUserPrefs: {
'dom.events.asyncClipboard.readText': true,
'dom.events.testing.asyncClipboard': true,
},
},
}
}
return projectConfig
}) || []),
]
return {
...config,
reporter: excludeGithub(config.reporter),
use: {
...config.use,
baseURL: 'http://localhost:3339',
headless: HEADLESS,
},
projects,
webServer: {
...config.webServer,
command: CI ? 'pnpm e2e:start' : 'pnpm e2e:dev',
port: 3339,
},
}
},
})
export default defineConfig(playwrightConfig)