-
-
Notifications
You must be signed in to change notification settings - Fork 751
Expand file tree
/
Copy pathevent.js
More file actions
192 lines (183 loc) · 4.55 KB
/
Copy pathevent.js
File metadata and controls
192 lines (183 loc) · 4.55 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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import debugModule from 'debug'
const debug = debugModule('codeceptjs:event')
import events from 'events'
import output from './output.js'
import { realmSingleton } from './realm.js'
const MAX_LISTENERS = 200
// Shared across realms so listeners registered from a test (CJS realm, via
// `import { event } from "codeceptjs"`) and events emitted by the runner (ESM realm)
// reach the same EventEmitter. Without this the test subscribes to a dead dispatcher.
const dispatcher = realmSingleton('__codeceptjs_dispatcher', () => {
const d = new events.EventEmitter()
d.setMaxListeners(MAX_LISTENERS)
return d
})
// Increase process max listeners to prevent warnings for beforeExit and other events
if (typeof process.setMaxListeners === 'function') {
process.setMaxListeners(MAX_LISTENERS)
}
/**
* @namespace
* @alias event
*/
export default {
/**
* @type {NodeJS.EventEmitter}
* @constant
* @inner
*/
dispatcher,
/**
* @type {object}
* @constant
* @inner
* @property {'test.start'} started
* @property {'test.before'} before
* @property {'test.after'} after
* @property {'test.passed'} passed
* @property {'test.failed'} failed
* @property {'test.finish'} finished
* @property {'test.skipped'} skipped
*/
test: {
started: 'test.start', // sync
before: 'test.before', // async
after: 'test.after', // async
passed: 'test.passed', // sync
failed: 'test.failed', // sync
finished: 'test.finish', // sync
skipped: 'test.skipped', // sync
},
/**
* @type {object}
* @constant
* @inner
* @property {'suite.before'} before
* @property {'suite.after'} after
*/
suite: {
before: 'suite.before',
after: 'suite.after',
},
/**
* @type {object}
* @constant
* @inner
* @property {'hook.start'} started
* @property {'hook.passed'} passed
* @property {'hook.failed'} failed
* @property {'hook.finished'} finished
*/
hook: {
started: 'hook.start',
passed: 'hook.passed',
failed: 'hook.failed',
finished: 'hook.finished',
},
/**
* @type {object}
* @constant
* @inner
* @property {'step.start'} started
* @property {'step.before'} before
* @property {'step.after'} after
* @property {'step.passed'} passed
* @property {'step.failed'} failed
* @property {'step.finish'} finished
* @property {'step.comment'} comment
*/
step: {
before: 'step.before', // async
after: 'step.after', // async
started: 'step.start', // sync
passed: 'step.passed', // sync
failed: 'step.failed', // sync
finished: 'step.finish', // sync
comment: 'step.comment',
},
/**
* @type {object}
* @constant
* @inner
* @property {'suite.before'} before
* @property {'suite.after'} after
*/
bddStep: {
before: 'bddStep.before',
after: 'bddStep.after',
started: 'bddStep.started',
finished: 'bddStep.finished',
},
/**
* @type {object}
* @constant
* @inner
* @property {'global.before'} before
* @property {'global.after'} after
* @property {'global.result'} result
* @property {'global.failures'} failures
*/
all: {
before: 'global.before',
after: 'global.after',
result: 'global.result',
failures: 'global.failures',
},
/**
* @type {object}
* @constant
* @inner
* @property {'multiple.before'} before
* @property {'multiple.after'} after
*/
multiple: {
before: 'multiple.before',
after: 'multiple.after',
},
/**
* @type {object}
* @constant
* @inner
* @property {'workers.before'} before
* @property {'workers.after'} after
* @property {'workers.result'} result
*/
workers: {
before: 'workers.before',
after: 'workers.after',
result: 'workers.result',
},
/**
* @param {string} event
* @param {*} [param]
*/
emit(event, param) {
let msg = `Emitted | ${event}`
if (param && param.toString()) {
msg += ` (${param.toString()})`
}
debug(msg)
try {
this.dispatcher.emit.apply(this.dispatcher, arguments)
} catch (err) {
output.error(`Error processing ${event} event:`)
output.error(err.stack)
}
},
/** for testing only! */
cleanDispatcher() {
let event
for (event in this.test) {
this.dispatcher.removeAllListeners(this.test[event])
}
for (event in this.suite) {
this.dispatcher.removeAllListeners(this.suite[event])
}
for (event in this.step) {
this.dispatcher.removeAllListeners(this.step[event])
}
for (event in this.all) {
this.dispatcher.removeAllListeners(this.all[event])
}
},
}