-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplugin.js
35 lines (28 loc) · 1.03 KB
/
plugin.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
const path = require('path')
function cypressRoutinesPlugin(on, config, ...routineArgs) {
on('task', {
routine({ testFile, routineName, isGlobalRoutine, args }) {
const testFileName = path.basename(testFile)
const routinesFile = isGlobalRoutine
? path.resolve(process.cwd(), 'cypress/global-routines.js')
: path.resolve(testFile, `../${testFileName.replace('.spec.js', '.routines.js')}`)
let createRoutinesObject
try {
if (require.cache[require.resolve(routinesFile)]) {
delete require.cache[require.resolve(routinesFile)]
}
createRoutinesObject = require(routinesFile)
} catch (err) {
console.error(err.stack || err)
throw new Error(`Could not require routines file: ${routinesFile}`)
}
const routines = createRoutinesObject(...[].concat(routineArgs))
const routine = routines[routineName]
if (!routine) {
throw new Error(`Routine ${routineName} not defined in routines file ${routinesFile}`)
}
return routine(...args) || null
},
})
}
module.exports = cypressRoutinesPlugin