-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcypress.config.js
79 lines (66 loc) · 1.86 KB
/
cypress.config.js
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
import { defineConfig } from 'cypress'
import { lighthouse, prepareAudit } from 'cypress-audit'
import dotenvFlowPlugin from 'cypress-dotenv-flow'
import fs from 'fs'
import path from 'path'
const storeData = async (data, filepath) => {
try {
const dirpath = path.dirname(filepath)
await fs.promises.mkdir(dirpath, { recursive: true })
// Paste JSON file into https://googlechrome.github.io/lighthouse/viewer/
// for Lighthouse Report
fs.writeFile(filepath, JSON.stringify(data), (err) => {
if (err) throw err
})
} catch (error) {
console.error(error)
}
}
export default defineConfig({
reporter: 'cypress-multi-reporters',
reporterOptions: {
configFile: 'cypress-reporter-config.json',
},
e2e: {
setupNodeEvents(on, config) {
let testTitle
on('before:browser:launch', (browser = {}, launchOptions) => {
prepareAudit(launchOptions)
return launchOptions
})
on('task', {
getTestTitle(message) {
testTitle = message
return null
},
})
on('task', {
lighthouse: lighthouse((report) => {
const requestedUrl = report.lhr.requestedUrl.replace(
config.baseUrl,
''
)
const filepath = path.resolve(
'cypress',
`reports/lighthouse/${
requestedUrl || 'home-page'
} (${testTitle}).json`
)
storeData(report, filepath)
}),
})
config = dotenvFlowPlugin(config)
// Assign some vars so we can access them via Cypress.env
config.env.GSSO_TOKEN_NAME = process.env.GSSO_TOKEN_NAME
return config
},
baseUrl: 'http://localhost:5001/',
defaultCommandTimeout: 10000,
video: false,
lighthouse: {
accessibility: 90,
},
viewportHeight: 1536,
viewportWidth: 960,
},
})