|
1 | | -const debug = require('debug')('codeceptjs:steps'); |
2 | | -const event = require('../event'); |
3 | | -const store = require('../store'); |
4 | | -const output = require('../output'); |
5 | | -const { BeforeHook, AfterHook, BeforeSuiteHook, AfterSuiteHook } = require('../mocha/hooks'); |
| 1 | +const debug = require('debug')('codeceptjs:steps') |
| 2 | +const event = require('../event') |
| 3 | +const store = require('../store') |
| 4 | +const output = require('../output') |
| 5 | +const { BeforeHook, AfterHook, BeforeSuiteHook, AfterSuiteHook } = require('../mocha/hooks') |
6 | 6 |
|
7 | | -let currentTest; |
8 | | -let currentHook; |
| 7 | +let currentTest |
| 8 | +let currentHook |
9 | 9 |
|
10 | 10 | /** |
11 | 11 | * Register steps inside tests |
12 | 12 | */ |
13 | 13 | module.exports = function () { |
14 | 14 | event.dispatcher.on(event.test.before, test => { |
15 | | - test.startedAt = +new Date(); |
16 | | - test.artifacts = {}; |
17 | | - }); |
| 15 | + test.startedAt = +new Date() |
| 16 | + test.artifacts = {} |
| 17 | + }) |
18 | 18 |
|
19 | 19 | event.dispatcher.on(event.test.started, test => { |
20 | | - currentTest = test; |
21 | | - currentTest.steps = []; |
22 | | - if (!('retryNum' in currentTest)) currentTest.retryNum = 0; |
23 | | - else currentTest.retryNum += 1; |
24 | | - output.scenario.started(test); |
25 | | - }); |
| 20 | + currentTest = test |
| 21 | + currentTest.steps = [] |
| 22 | + if (!('retryNum' in currentTest)) currentTest.retryNum = 0 |
| 23 | + else currentTest.retryNum += 1 |
| 24 | + output.scenario.started(test) |
| 25 | + }) |
26 | 26 |
|
27 | 27 | event.dispatcher.on(event.test.after, test => { |
28 | | - currentTest = null; |
29 | | - }); |
| 28 | + currentTest = null |
| 29 | + }) |
30 | 30 |
|
31 | | - event.dispatcher.on(event.test.finished, test => {}); |
| 31 | + event.dispatcher.on(event.test.finished, test => {}) |
32 | 32 |
|
33 | 33 | event.dispatcher.on(event.hook.started, hook => { |
34 | | - currentHook = hook.ctx.test; |
35 | | - currentHook.steps = []; |
| 34 | + currentHook = hook.ctx.test |
| 35 | + currentHook.steps = [] |
36 | 36 |
|
37 | | - output.hook.started(hook); |
| 37 | + output.hook.started(hook) |
38 | 38 |
|
39 | | - if (hook.ctx && hook.ctx.test) output.log(`--- STARTED ${hook.ctx.test.title} ---`); |
40 | | - }); |
| 39 | + if (hook.ctx && hook.ctx.test) debug(`--- STARTED ${hook.ctx.test.title} ---`) |
| 40 | + }) |
41 | 41 |
|
42 | 42 | event.dispatcher.on(event.hook.passed, hook => { |
43 | | - currentHook = null; |
44 | | - output.hook.passed(hook); |
45 | | - if (hook.ctx && hook.ctx.test) output.log(`--- ENDED ${hook.ctx.test.title} ---`); |
46 | | - }); |
| 43 | + currentHook = null |
| 44 | + output.hook.passed(hook) |
| 45 | + if (hook.ctx && hook.ctx.test) debug(`--- ENDED ${hook.ctx.test.title} ---`) |
| 46 | + }) |
47 | 47 |
|
48 | 48 | event.dispatcher.on(event.test.failed, () => { |
49 | 49 | const cutSteps = function (current) { |
50 | | - const failureIndex = current.steps.findIndex(el => el.status === 'failed'); |
| 50 | + const failureIndex = current.steps.findIndex(el => el.status === 'failed') |
51 | 51 | // To be sure that failed test will be failed in report |
52 | | - current.state = 'failed'; |
53 | | - current.steps.length = failureIndex + 1; |
54 | | - return current; |
55 | | - }; |
| 52 | + current.state = 'failed' |
| 53 | + current.steps.length = failureIndex + 1 |
| 54 | + return current |
| 55 | + } |
56 | 56 | if (currentHook && Array.isArray(currentHook.steps) && currentHook.steps.length) { |
57 | | - currentHook = cutSteps(currentHook); |
58 | | - return (currentHook = null); |
| 57 | + currentHook = cutSteps(currentHook) |
| 58 | + return (currentHook = null) |
59 | 59 | } |
60 | | - if (!currentTest) return; |
| 60 | + if (!currentTest) return |
61 | 61 | // last step is failing step |
62 | | - if (!currentTest.steps.length) return; |
63 | | - return (currentTest = cutSteps(currentTest)); |
64 | | - }); |
| 62 | + if (!currentTest.steps.length) return |
| 63 | + return (currentTest = cutSteps(currentTest)) |
| 64 | + }) |
65 | 65 |
|
66 | 66 | event.dispatcher.on(event.test.passed, () => { |
67 | | - if (!currentTest) return; |
| 67 | + if (!currentTest) return |
68 | 68 | // To be sure that passed test will be passed in report |
69 | | - delete currentTest.err; |
70 | | - currentTest.state = 'passed'; |
71 | | - }); |
| 69 | + delete currentTest.err |
| 70 | + currentTest.state = 'passed' |
| 71 | + }) |
72 | 72 |
|
73 | 73 | event.dispatcher.on(event.step.started, step => { |
74 | | - step.startedAt = +new Date(); |
75 | | - step.test = currentTest; |
| 74 | + step.startedAt = +new Date() |
| 75 | + step.test = currentTest |
76 | 76 | if (currentHook && Array.isArray(currentHook.steps)) { |
77 | | - return currentHook.steps.push(step); |
| 77 | + return currentHook.steps.push(step) |
78 | 78 | } |
79 | | - if (!currentTest || !currentTest.steps) return; |
80 | | - currentTest.steps.push(step); |
81 | | - }); |
| 79 | + if (!currentTest || !currentTest.steps) return |
| 80 | + currentTest.steps.push(step) |
| 81 | + }) |
82 | 82 |
|
83 | 83 | event.dispatcher.on(event.step.finished, step => { |
84 | | - step.finishedAt = +new Date(); |
85 | | - if (step.startedAt) step.duration = step.finishedAt - step.startedAt; |
86 | | - debug(`Step '${step}' finished; Duration: ${step.duration || 0}ms`); |
87 | | - }); |
88 | | -}; |
| 84 | + step.finishedAt = +new Date() |
| 85 | + if (step.startedAt) step.duration = step.finishedAt - step.startedAt |
| 86 | + debug(`Step '${step}' finished; Duration: ${step.duration || 0}ms`) |
| 87 | + }) |
| 88 | +} |
0 commit comments