-
-
Notifications
You must be signed in to change notification settings - Fork 736
/
Copy pathhelper.js
50 lines (45 loc) · 1.14 KB
/
helper.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
const Step = require('./base')
const store = require('../store')
class HelperStep extends Step {
constructor(helper, name) {
super(name)
/** @member {CodeceptJS.Helper} helper corresponding helper */
this.helper = helper
/** @member {string} helperMethod name of method to be executed */
this.helperMethod = name
}
/**
* @param {...any} args
* @return {*}
*/
run() {
this.args = Array.prototype.slice.call(arguments)
this.startTime = +Date.now()
if (store.dryRun) {
this.setStatus('success')
return Promise.resolve(new Proxy({}, dryRunResolver()))
}
let result
try {
if (this.helperMethod !== 'say') {
result = this.helper[this.helperMethod].apply(this.helper, this.args)
}
this.setStatus('success')
this.endTime = +Date.now()
} catch (err) {
this.endTime = +Date.now()
this.setStatus('failed')
throw err
}
return result
}
}
module.exports = HelperStep
function dryRunResolver() {
return {
get(target, prop) {
if (prop === 'toString') return () => '<VALUE>'
return new Proxy({}, dryRunResolver())
},
}
}