forked from cypress-io/cypress-example-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
54 lines (44 loc) · 1.39 KB
/
Copy pathindex.js
File metadata and controls
54 lines (44 loc) · 1.39 KB
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
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************
/* eslint-disable no-console */
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
const items = {}
// cy.task() requires returning a Promise
// or anything BUT undefined to signal that
// the task is finished
// see https://on.cypress.io/task
on('task', {
setItem ({ name, value }) {
console.log('setting %s', name)
if (typeof value === 'undefined') {
// since we cannot return undefined from the cy.task
// let's not allow storing undefined
throw new Error(`Cannot store undefined value for item "${name}"`)
}
items[name] = value
return null
},
getItem (name) {
if (name in items) {
console.log('returning item %s', name)
return items[name]
}
const msg = `Missing item "${name}"`
console.error(msg)
throw new Error(msg)
},
})
}