codeceptjs 4.0.0-beta.1 → 4.0.0-beta.10.esm-aria

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +133 -120
  2. package/bin/codecept.js +107 -96
  3. package/bin/test-server.js +64 -0
  4. package/docs/webapi/clearCookie.mustache +1 -1
  5. package/docs/webapi/click.mustache +5 -1
  6. package/lib/actor.js +71 -103
  7. package/lib/ai.js +159 -188
  8. package/lib/assert/empty.js +22 -24
  9. package/lib/assert/equal.js +30 -37
  10. package/lib/assert/error.js +14 -14
  11. package/lib/assert/include.js +43 -48
  12. package/lib/assert/throws.js +11 -11
  13. package/lib/assert/truth.js +22 -22
  14. package/lib/assert.js +20 -18
  15. package/lib/codecept.js +238 -162
  16. package/lib/colorUtils.js +50 -52
  17. package/lib/command/check.js +206 -0
  18. package/lib/command/configMigrate.js +56 -51
  19. package/lib/command/definitions.js +96 -109
  20. package/lib/command/dryRun.js +77 -79
  21. package/lib/command/generate.js +234 -194
  22. package/lib/command/gherkin/init.js +42 -33
  23. package/lib/command/gherkin/snippets.js +76 -74
  24. package/lib/command/gherkin/steps.js +20 -17
  25. package/lib/command/info.js +74 -38
  26. package/lib/command/init.js +300 -290
  27. package/lib/command/interactive.js +41 -32
  28. package/lib/command/list.js +28 -27
  29. package/lib/command/run-multiple/chunk.js +51 -48
  30. package/lib/command/run-multiple/collection.js +5 -5
  31. package/lib/command/run-multiple/run.js +5 -1
  32. package/lib/command/run-multiple.js +97 -97
  33. package/lib/command/run-rerun.js +19 -25
  34. package/lib/command/run-workers.js +68 -92
  35. package/lib/command/run.js +39 -27
  36. package/lib/command/utils.js +80 -64
  37. package/lib/command/workers/runTests.js +388 -226
  38. package/lib/config.js +124 -50
  39. package/lib/container.js +751 -260
  40. package/lib/data/context.js +60 -61
  41. package/lib/data/dataScenarioConfig.js +47 -47
  42. package/lib/data/dataTableArgument.js +32 -32
  43. package/lib/data/table.js +22 -22
  44. package/lib/effects.js +307 -0
  45. package/lib/element/WebElement.js +327 -0
  46. package/lib/els.js +160 -0
  47. package/lib/event.js +173 -163
  48. package/lib/globals.js +141 -0
  49. package/lib/heal.js +89 -85
  50. package/lib/helper/AI.js +131 -41
  51. package/lib/helper/ApiDataFactory.js +107 -75
  52. package/lib/helper/Appium.js +542 -404
  53. package/lib/helper/FileSystem.js +100 -79
  54. package/lib/helper/GraphQL.js +44 -43
  55. package/lib/helper/GraphQLDataFactory.js +52 -52
  56. package/lib/helper/JSONResponse.js +126 -88
  57. package/lib/helper/Mochawesome.js +54 -29
  58. package/lib/helper/Playwright.js +2547 -1316
  59. package/lib/helper/Puppeteer.js +1578 -1181
  60. package/lib/helper/REST.js +209 -68
  61. package/lib/helper/WebDriver.js +1482 -1342
  62. package/lib/helper/errors/ConnectionRefused.js +6 -6
  63. package/lib/helper/errors/ElementAssertion.js +11 -16
  64. package/lib/helper/errors/ElementNotFound.js +5 -9
  65. package/lib/helper/errors/RemoteBrowserConnectionRefused.js +5 -5
  66. package/lib/helper/extras/Console.js +11 -11
  67. package/lib/helper/extras/PlaywrightLocator.js +110 -0
  68. package/lib/helper/extras/PlaywrightPropEngine.js +18 -18
  69. package/lib/helper/extras/PlaywrightReactVueLocator.js +17 -8
  70. package/lib/helper/extras/PlaywrightRestartOpts.js +25 -11
  71. package/lib/helper/extras/Popup.js +22 -22
  72. package/lib/helper/extras/React.js +27 -28
  73. package/lib/helper/network/actions.js +36 -42
  74. package/lib/helper/network/utils.js +78 -84
  75. package/lib/helper/scripts/blurElement.js +5 -5
  76. package/lib/helper/scripts/focusElement.js +5 -5
  77. package/lib/helper/scripts/highlightElement.js +8 -8
  78. package/lib/helper/scripts/isElementClickable.js +34 -34
  79. package/lib/helper.js +2 -3
  80. package/lib/history.js +23 -19
  81. package/lib/hooks.js +8 -8
  82. package/lib/html.js +94 -104
  83. package/lib/index.js +38 -27
  84. package/lib/listener/config.js +30 -23
  85. package/lib/listener/emptyRun.js +54 -0
  86. package/lib/listener/enhancedGlobalRetry.js +110 -0
  87. package/lib/listener/exit.js +16 -18
  88. package/lib/listener/globalRetry.js +70 -0
  89. package/lib/listener/globalTimeout.js +181 -0
  90. package/lib/listener/helpers.js +76 -51
  91. package/lib/listener/mocha.js +10 -11
  92. package/lib/listener/result.js +11 -0
  93. package/lib/listener/retryEnhancer.js +85 -0
  94. package/lib/listener/steps.js +71 -59
  95. package/lib/listener/store.js +20 -0
  96. package/lib/locator.js +214 -197
  97. package/lib/mocha/asyncWrapper.js +274 -0
  98. package/lib/mocha/bdd.js +167 -0
  99. package/lib/mocha/cli.js +341 -0
  100. package/lib/mocha/factory.js +163 -0
  101. package/lib/mocha/featureConfig.js +89 -0
  102. package/lib/mocha/gherkin.js +231 -0
  103. package/lib/mocha/hooks.js +121 -0
  104. package/lib/mocha/index.js +21 -0
  105. package/lib/mocha/inject.js +46 -0
  106. package/lib/{interfaces → mocha}/scenarioConfig.js +58 -34
  107. package/lib/mocha/suite.js +89 -0
  108. package/lib/mocha/test.js +184 -0
  109. package/lib/mocha/types.d.ts +42 -0
  110. package/lib/mocha/ui.js +242 -0
  111. package/lib/output.js +141 -71
  112. package/lib/parser.js +47 -44
  113. package/lib/pause.js +173 -145
  114. package/lib/plugin/analyze.js +403 -0
  115. package/lib/plugin/{autoLogin.js → auth.js} +178 -79
  116. package/lib/plugin/autoDelay.js +36 -40
  117. package/lib/plugin/coverage.js +131 -78
  118. package/lib/plugin/customLocator.js +22 -21
  119. package/lib/plugin/customReporter.js +53 -0
  120. package/lib/plugin/enhancedRetryFailedStep.js +99 -0
  121. package/lib/plugin/heal.js +101 -110
  122. package/lib/plugin/htmlReporter.js +3648 -0
  123. package/lib/plugin/pageInfo.js +140 -0
  124. package/lib/plugin/pauseOnFail.js +12 -11
  125. package/lib/plugin/retryFailedStep.js +82 -47
  126. package/lib/plugin/screenshotOnFail.js +111 -92
  127. package/lib/plugin/stepByStepReport.js +159 -101
  128. package/lib/plugin/stepTimeout.js +20 -25
  129. package/lib/plugin/subtitles.js +38 -38
  130. package/lib/recorder.js +193 -130
  131. package/lib/rerun.js +94 -49
  132. package/lib/result.js +238 -0
  133. package/lib/retryCoordinator.js +207 -0
  134. package/lib/secret.js +20 -18
  135. package/lib/session.js +95 -89
  136. package/lib/step/base.js +239 -0
  137. package/lib/step/comment.js +10 -0
  138. package/lib/step/config.js +50 -0
  139. package/lib/step/func.js +46 -0
  140. package/lib/step/helper.js +50 -0
  141. package/lib/step/meta.js +99 -0
  142. package/lib/step/record.js +74 -0
  143. package/lib/step/retry.js +11 -0
  144. package/lib/step/section.js +55 -0
  145. package/lib/step.js +18 -329
  146. package/lib/steps.js +54 -0
  147. package/lib/store.js +38 -7
  148. package/lib/template/heal.js +3 -12
  149. package/lib/template/prompts/generatePageObject.js +31 -0
  150. package/lib/template/prompts/healStep.js +13 -0
  151. package/lib/template/prompts/writeStep.js +9 -0
  152. package/lib/test-server.js +334 -0
  153. package/lib/timeout.js +60 -0
  154. package/lib/transform.js +8 -8
  155. package/lib/translation.js +34 -21
  156. package/lib/utils/mask_data.js +47 -0
  157. package/lib/utils.js +411 -228
  158. package/lib/workerStorage.js +37 -34
  159. package/lib/workers.js +532 -296
  160. package/package.json +115 -95
  161. package/translations/de-DE.js +5 -3
  162. package/translations/fr-FR.js +5 -4
  163. package/translations/index.js +22 -12
  164. package/translations/it-IT.js +4 -3
  165. package/translations/ja-JP.js +4 -3
  166. package/translations/nl-NL.js +76 -0
  167. package/translations/pl-PL.js +4 -3
  168. package/translations/pt-BR.js +4 -3
  169. package/translations/ru-RU.js +4 -3
  170. package/translations/utils.js +10 -0
  171. package/translations/zh-CN.js +4 -3
  172. package/translations/zh-TW.js +4 -3
  173. package/typings/index.d.ts +546 -185
  174. package/typings/promiseBasedTypes.d.ts +150 -879
  175. package/typings/types.d.ts +547 -996
  176. package/lib/cli.js +0 -249
  177. package/lib/dirname.js +0 -5
  178. package/lib/helper/Expect.js +0 -425
  179. package/lib/helper/ExpectHelper.js +0 -399
  180. package/lib/helper/MockServer.js +0 -223
  181. package/lib/helper/Nightmare.js +0 -1411
  182. package/lib/helper/Protractor.js +0 -1835
  183. package/lib/helper/SoftExpectHelper.js +0 -381
  184. package/lib/helper/TestCafe.js +0 -1410
  185. package/lib/helper/clientscripts/nightmare.js +0 -213
  186. package/lib/helper/testcafe/testControllerHolder.js +0 -42
  187. package/lib/helper/testcafe/testcafe-utils.js +0 -63
  188. package/lib/interfaces/bdd.js +0 -98
  189. package/lib/interfaces/featureConfig.js +0 -69
  190. package/lib/interfaces/gherkin.js +0 -195
  191. package/lib/listener/artifacts.js +0 -19
  192. package/lib/listener/retry.js +0 -68
  193. package/lib/listener/timeout.js +0 -109
  194. package/lib/mochaFactory.js +0 -110
  195. package/lib/plugin/allure.js +0 -15
  196. package/lib/plugin/commentStep.js +0 -136
  197. package/lib/plugin/debugErrors.js +0 -67
  198. package/lib/plugin/eachElement.js +0 -127
  199. package/lib/plugin/fakerTransform.js +0 -49
  200. package/lib/plugin/retryTo.js +0 -121
  201. package/lib/plugin/selenoid.js +0 -371
  202. package/lib/plugin/standardActingHelpers.js +0 -9
  203. package/lib/plugin/tryTo.js +0 -105
  204. package/lib/plugin/wdio.js +0 -246
  205. package/lib/scenario.js +0 -222
  206. package/lib/ui.js +0 -238
  207. package/lib/within.js +0 -70
package/lib/els.js ADDED
@@ -0,0 +1,160 @@
1
+ import output from './output.js'
2
+ import store from './store.js'
3
+ import container from './container.js'
4
+ import StepConfig from './step/config.js'
5
+ import recordStep from './step/record.js'
6
+ import FuncStep from './step/func.js'
7
+ import { truth } from './assert/truth.js'
8
+ import { isAsyncFunction, humanizeFunction } from './utils.js'
9
+
10
+ function element(purpose, locator, fn) {
11
+ let stepConfig
12
+ if (arguments[arguments.length - 1] instanceof StepConfig) {
13
+ stepConfig = arguments[arguments.length - 1]
14
+ }
15
+
16
+ if (!fn || fn === stepConfig) {
17
+ fn = locator
18
+ locator = purpose
19
+ purpose = 'first element'
20
+ }
21
+
22
+ const step = prepareStep(purpose, locator, fn)
23
+ if (!step) return
24
+
25
+ return executeStep(
26
+ step,
27
+ async () => {
28
+ const els = await step.helper._locate(locator)
29
+ output.debug(`Found ${els.length} elements, using first element`)
30
+
31
+ return fn(els[0])
32
+ },
33
+ stepConfig,
34
+ )
35
+ }
36
+
37
+ function eachElement(purpose, locator, fn) {
38
+ if (!fn) {
39
+ fn = locator
40
+ locator = purpose
41
+ purpose = 'for each element'
42
+ }
43
+
44
+ const step = prepareStep(purpose, locator, fn)
45
+ if (!step) return
46
+
47
+ return executeStep(step, async () => {
48
+ const els = await step.helper._locate(locator)
49
+ output.debug(`Found ${els.length} elements for each elements to iterate`)
50
+
51
+ const errs = []
52
+ let i = 0
53
+ for (const el of els) {
54
+ try {
55
+ await fn(el, i)
56
+ } catch (err) {
57
+ output.error(`eachElement: failed operation on element #${i} ${el}`)
58
+ errs.push(err)
59
+ }
60
+ i++
61
+ }
62
+
63
+ if (errs.length) {
64
+ throw errs[0]
65
+ }
66
+ })
67
+ }
68
+
69
+ function expectElement(locator, fn) {
70
+ const step = prepareStep('expect element to be', locator, fn)
71
+ if (!step) return
72
+
73
+ return executeStep(step, async () => {
74
+ const els = await step.helper._locate(locator)
75
+ output.debug(`Found ${els.length} elements, first will be used for assertion`)
76
+
77
+ const result = await fn(els[0])
78
+ const assertion = truth(`element (${locator})`, fn.toString())
79
+ assertion.assert(result)
80
+ })
81
+ }
82
+
83
+ function expectAnyElement(locator, fn) {
84
+ const step = prepareStep('expect any element to be', locator, fn)
85
+ if (!step) return
86
+
87
+ return executeStep(step, async () => {
88
+ const els = await step.helper._locate(locator)
89
+ output.debug(`Found ${els.length} elements, at least one should pass the assertion`)
90
+
91
+ const assertion = truth(`any element of (${locator})`, fn.toString())
92
+
93
+ let found = false
94
+ for (const el of els) {
95
+ const result = await fn(el)
96
+ if (result) {
97
+ found = true
98
+ break
99
+ }
100
+ }
101
+ if (!found) throw assertion.getException()
102
+ })
103
+ }
104
+
105
+ function expectAllElements(locator, fn) {
106
+ const step = prepareStep('expect all elements', locator, fn)
107
+ if (!step) return
108
+
109
+ return executeStep(step, async () => {
110
+ const els = await step.helper._locate(locator)
111
+ output.debug(`Found ${els.length} elements, all should pass the assertion`)
112
+
113
+ let i = 1
114
+ for (const el of els) {
115
+ output.debug(`checking element #${i}: ${el}`)
116
+ const result = await fn(el)
117
+ const assertion = truth(`element #${i} of (${locator})`, humanizeFunction(fn))
118
+ assertion.assert(result)
119
+ i++
120
+ }
121
+ })
122
+ }
123
+
124
+ export { element, eachElement, expectElement, expectAnyElement, expectAllElements }
125
+
126
+ export default {
127
+ element,
128
+ eachElement,
129
+ expectElement,
130
+ expectAnyElement,
131
+ expectAllElements,
132
+ }
133
+
134
+ function prepareStep(purpose, locator, fn) {
135
+ if (store.dryRun) return
136
+ const helpers = Object.values(container.helpers())
137
+
138
+ const helper = helpers.filter(h => !!h._locate)[0]
139
+
140
+ if (!helper) {
141
+ throw new Error('No helper enabled with _locate method with returns a list of elements.')
142
+ }
143
+
144
+ if (!isAsyncFunction(fn)) {
145
+ throw new Error('Async function should be passed into each element')
146
+ }
147
+
148
+ const isAssertion = purpose.startsWith('expect')
149
+
150
+ const step = new FuncStep(`${purpose} within "${locator}" ${isAssertion ? 'to be' : 'to'}`)
151
+ step.setHelper(helper)
152
+ step.setArguments([humanizeFunction(fn)]) // user defined function is a passed argument
153
+
154
+ return step
155
+ }
156
+
157
+ async function executeStep(step, action, stepConfig = {}) {
158
+ step.setCallable(action)
159
+ return recordStep(step, [stepConfig])
160
+ }
package/lib/event.js CHANGED
@@ -1,176 +1,186 @@
1
- import debug from 'debug';
1
+ import debugModule from 'debug'
2
+ const debug = debugModule('codeceptjs:event')
3
+ import events from 'events'
4
+ import output from './output.js'
2
5
 
3
- import events from 'events';
4
- import * as output from './output.js';
6
+ const MAX_LISTENERS = 200
5
7
 
6
- debug('codeceptjs:event');
8
+ const dispatcher = new events.EventEmitter()
7
9
 
8
- const dispatcher = new events.EventEmitter();
10
+ dispatcher.setMaxListeners(MAX_LISTENERS)
9
11
 
10
- dispatcher.setMaxListeners(50);
12
+ // Increase process max listeners to prevent warnings for beforeExit and other events
13
+ if (typeof process.setMaxListeners === 'function') {
14
+ process.setMaxListeners(MAX_LISTENERS)
15
+ }
11
16
 
12
17
  /**
13
- * @type {object}
14
- * @constant
15
- * @inner
16
- * @property {'test.start'} started
17
- * @property {'test.before'} before
18
- * @property {'test.after'} after
19
- * @property {'test.passed'} passed
20
- * @property {'test.failed'} failed
21
- * @property {'test.finish'} finished
22
- * @property {'test.skipped'} skipped
18
+ * @namespace
19
+ * @alias event
23
20
  */
24
- export const test = {
25
- started: 'test.start', // sync
26
- before: 'test.before', // async
27
- after: 'test.after', // async
28
- passed: 'test.passed', // sync
29
- failed: 'test.failed', // sync
30
- finished: 'test.finish', // sync
31
- skipped: 'test.skipped', // sync
32
- };
33
21
 
34
- /**
35
- * @type {object}
36
- * @constant
37
- * @inner
38
- * @property {'suite.before'} before
39
- * @property {'suite.after'} after
40
- */
41
- export const suite = {
42
- before: 'suite.before',
43
- after: 'suite.after',
44
- };
45
- /**
46
- * @type {object}
47
- * @constant
48
- * @inner
49
- * @property {'hook.start'} started
50
- * @property {'hook.passed'} passed
51
- */
52
- export const hook = {
53
- started: 'hook.start',
54
- passed: 'hook.passed',
55
- failed: 'hook.failed',
56
- };
57
- /**
58
- * @type {object}
59
- * @constant
60
- * @inner
61
- * @property {'step.start'} started
62
- * @property {'step.before'} before
63
- * @property {'step.after'} after
64
- * @property {'step.passed'} passed
65
- * @property {'step.failed'} failed
66
- * @property {'step.finish'} finished
67
- * @property {'step.comment'} comment
68
- */
69
- export const step = {
70
- before: 'step.before', // async
71
- after: 'step.after', // async
72
- started: 'step.start', // sync
73
- passed: 'step.passed', // sync
74
- failed: 'step.failed', // sync
75
- finished: 'step.finish', // sync
76
- comment: 'step.comment',
77
- };
78
- /**
79
- * @type {object}
80
- * @constant
81
- * @inner
82
- * @property {'suite.before'} before
83
- * @property {'suite.after'} after
84
- */
85
- export const bddStep = {
86
- before: 'bddStep.before',
87
- after: 'bddStep.after',
88
- started: 'bddStep.started',
89
- finished: 'bddStep.finished',
90
- };
91
- /**
92
- * @type {object}
93
- * @constant
94
- * @inner
95
- * @property {'global.before'} before
96
- * @property {'global.after'} after
97
- * @property {'global.result'} result
98
- * @property {'global.failures'} failures
99
- */
100
- export const all = {
101
- before: 'global.before',
102
- after: 'global.after',
103
- result: 'global.result',
104
- failures: 'global.failures',
105
- };
106
- /**
107
- * @type {object}
108
- * @constant
109
- * @inner
110
- * @property {'multiple.before'} before
111
- * @property {'multiple.after'} after
112
- */
113
- export const multiple = {
114
- before: 'multiple.before',
115
- after: 'multiple.after',
116
- };
22
+ export default {
23
+ /**
24
+ * @type {NodeJS.EventEmitter}
25
+ * @constant
26
+ * @inner
27
+ */
28
+ dispatcher,
29
+ /**
30
+ * @type {object}
31
+ * @constant
32
+ * @inner
33
+ * @property {'test.start'} started
34
+ * @property {'test.before'} before
35
+ * @property {'test.after'} after
36
+ * @property {'test.passed'} passed
37
+ * @property {'test.failed'} failed
38
+ * @property {'test.finish'} finished
39
+ * @property {'test.skipped'} skipped
40
+ */
41
+ test: {
42
+ started: 'test.start', // sync
43
+ before: 'test.before', // async
44
+ after: 'test.after', // async
45
+ passed: 'test.passed', // sync
46
+ failed: 'test.failed', // sync
47
+ finished: 'test.finish', // sync
48
+ skipped: 'test.skipped', // sync
49
+ },
50
+ /**
51
+ * @type {object}
52
+ * @constant
53
+ * @inner
54
+ * @property {'suite.before'} before
55
+ * @property {'suite.after'} after
56
+ */
57
+ suite: {
58
+ before: 'suite.before',
59
+ after: 'suite.after',
60
+ },
61
+ /**
62
+ * @type {object}
63
+ * @constant
64
+ * @inner
65
+ * @property {'hook.start'} started
66
+ * @property {'hook.passed'} passed
67
+ * @property {'hook.failed'} failed
68
+ * @property {'hook.finished'} finished
69
+ */
70
+ hook: {
71
+ started: 'hook.start',
72
+ passed: 'hook.passed',
73
+ failed: 'hook.failed',
74
+ finished: 'hook.finished',
75
+ },
117
76
 
118
- /**
119
- * @type {object}
120
- * @constant
121
- * @inner
122
- * @property {'workers.before'} before
123
- * @property {'workers.after'} after
124
- * @property {'workers.result'} result
125
- */
126
- export const workers = {
127
- before: 'workers.before',
128
- after: 'workers.after',
129
- result: 'workers.result',
130
- };
77
+ /**
78
+ * @type {object}
79
+ * @constant
80
+ * @inner
81
+ * @property {'step.start'} started
82
+ * @property {'step.before'} before
83
+ * @property {'step.after'} after
84
+ * @property {'step.passed'} passed
85
+ * @property {'step.failed'} failed
86
+ * @property {'step.finish'} finished
87
+ * @property {'step.comment'} comment
88
+ */
89
+ step: {
90
+ before: 'step.before', // async
91
+ after: 'step.after', // async
92
+ started: 'step.start', // sync
93
+ passed: 'step.passed', // sync
94
+ failed: 'step.failed', // sync
95
+ finished: 'step.finish', // sync
96
+ comment: 'step.comment',
97
+ },
98
+ /**
99
+ * @type {object}
100
+ * @constant
101
+ * @inner
102
+ * @property {'suite.before'} before
103
+ * @property {'suite.after'} after
104
+ */
105
+ bddStep: {
106
+ before: 'bddStep.before',
107
+ after: 'bddStep.after',
108
+ started: 'bddStep.started',
109
+ finished: 'bddStep.finished',
110
+ },
111
+ /**
112
+ * @type {object}
113
+ * @constant
114
+ * @inner
115
+ * @property {'global.before'} before
116
+ * @property {'global.after'} after
117
+ * @property {'global.result'} result
118
+ * @property {'global.failures'} failures
119
+ */
120
+ all: {
121
+ before: 'global.before',
122
+ after: 'global.after',
123
+ result: 'global.result',
124
+ failures: 'global.failures',
125
+ },
126
+ /**
127
+ * @type {object}
128
+ * @constant
129
+ * @inner
130
+ * @property {'multiple.before'} before
131
+ * @property {'multiple.after'} after
132
+ */
133
+ multiple: {
134
+ before: 'multiple.before',
135
+ after: 'multiple.after',
136
+ },
131
137
 
132
- /** for testing only! */
133
- export function cleanDispatcher() {
134
- let event;
135
- for (event in test) {
136
- dispatcher.removeAllListeners(test[event]);
137
- }
138
- for (event in suite) {
139
- dispatcher.removeAllListeners(test[event]);
140
- }
141
- for (event in step) {
142
- dispatcher.removeAllListeners(test[event]);
143
- }
144
- for (event in all) {
145
- dispatcher.removeAllListeners(test[event]);
146
- }
147
- }
138
+ /**
139
+ * @type {object}
140
+ * @constant
141
+ * @inner
142
+ * @property {'workers.before'} before
143
+ * @property {'workers.after'} after
144
+ * @property {'workers.result'} result
145
+ */
146
+ workers: {
147
+ before: 'workers.before',
148
+ after: 'workers.after',
149
+ result: 'workers.result',
150
+ },
148
151
 
149
- /**
150
- * @namespace
151
- * @alias event
152
- */
153
- /**
154
- * @type {NodeJS.EventEmitter}
155
- * @constant
156
- * @inner
157
- */
158
- export { dispatcher };
152
+ /**
153
+ * @param {string} event
154
+ * @param {*} [param]
155
+ */
156
+ emit(event, param) {
157
+ let msg = `Emitted | ${event}`
158
+ if (param && param.toString()) {
159
+ msg += ` (${param.toString()})`
160
+ }
161
+ debug(msg)
162
+ try {
163
+ this.dispatcher.emit.apply(this.dispatcher, arguments)
164
+ } catch (err) {
165
+ output.error(`Error processing ${event} event:`)
166
+ output.error(err.stack)
167
+ }
168
+ },
159
169
 
160
- /**
161
- * @param {string} event
162
- * @param {*} [param]
163
- */
164
- export function emit(event, param) {
165
- let msg = `Emitted | ${event}`;
166
- if (param && param.toString()) {
167
- msg += ` (${param.toString()})`;
168
- }
169
- output.output.debug(msg);
170
- try {
171
- dispatcher.emit.apply(dispatcher, arguments);
172
- } catch (err) {
173
- output.output.error(`Error processing ${event} event:`);
174
- output.output.error(err.stack);
175
- }
170
+ /** for testing only! */
171
+ cleanDispatcher() {
172
+ let event
173
+ for (event in this.test) {
174
+ this.dispatcher.removeAllListeners(this.test[event])
175
+ }
176
+ for (event in this.suite) {
177
+ this.dispatcher.removeAllListeners(this.suite[event])
178
+ }
179
+ for (event in this.step) {
180
+ this.dispatcher.removeAllListeners(this.step[event])
181
+ }
182
+ for (event in this.all) {
183
+ this.dispatcher.removeAllListeners(this.all[event])
184
+ }
185
+ },
176
186
  }
package/lib/globals.js ADDED
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Global variables initialization module
3
+ *
4
+ * Centralizes all global variable setup for CodeceptJS from codecept.js and mocha/ui.js
5
+ */
6
+
7
+ import fsPath from 'path'
8
+ import ActorFactory from './actor.js'
9
+ import output from './output.js'
10
+ import locator from './locator.js'
11
+
12
+ /**
13
+ * Initialize CodeceptJS core globals
14
+ * Called from Codecept.initGlobals()
15
+ */
16
+ export async function initCodeceptGlobals(dir, config, container) {
17
+ global.codecept_dir = dir
18
+ global.output_dir = fsPath.resolve(dir, config.output)
19
+
20
+ if (config.noGlobals) return;
21
+ // Set up actor global - will use container when available
22
+ global.actor = global.codecept_actor = (obj) => {
23
+ return ActorFactory(obj, global.container || container)
24
+ }
25
+ global.Actor = global.actor
26
+
27
+ // Use dynamic imports for modules to avoid circular dependencies
28
+ global.pause = async (...args) => {
29
+ const pauseModule = await import('./pause.js')
30
+ return (pauseModule.default || pauseModule)(...args)
31
+ }
32
+
33
+ global.within = async (...args) => {
34
+ return (await import('./effects.js')).within(...args)
35
+ }
36
+
37
+ global.session = async (...args) => {
38
+ const sessionModule = await import('./session.js')
39
+ return (sessionModule.default || sessionModule)(...args)
40
+ }
41
+
42
+ const dataTableModule = await import('./data/table.js')
43
+ global.DataTable = dataTableModule.default || dataTableModule
44
+
45
+ global.locate = locatorQuery => {
46
+ return locator.build(locatorQuery)
47
+ }
48
+
49
+ global.inject = () => container.support()
50
+ global.share = container.share
51
+
52
+ const secretModule = await import('./secret.js')
53
+ global.secret = secretModule.secret || (secretModule.default && secretModule.default.secret)
54
+
55
+ global.codecept_debug = output.debug
56
+
57
+ const codeceptjsModule = await import('./index.js') // load all objects
58
+ global.codeceptjs = codeceptjsModule.default || codeceptjsModule
59
+
60
+ // BDD step definitions
61
+ const stepDefinitionsModule = await import('./mocha/bdd.js')
62
+ const stepDefinitions = stepDefinitionsModule.default || stepDefinitionsModule
63
+ global.Given = stepDefinitions.Given
64
+ global.When = stepDefinitions.When
65
+ global.Then = stepDefinitions.Then
66
+ global.DefineParameterType = stepDefinitions.defineParameterType
67
+
68
+ // debug mode
69
+ global.debugMode = false
70
+
71
+ // mask sensitive data
72
+ global.maskSensitiveData = config.maskSensitiveData || false
73
+
74
+ }
75
+
76
+ /**
77
+ * Initialize Mocha test framework globals (Feature, Scenario, etc.)
78
+ * Called from mocha/ui.js pre-require event
79
+ */
80
+ export function initMochaGlobals(context) {
81
+ // Mocha test framework globals
82
+ global.BeforeAll = context.BeforeAll
83
+ global.AfterAll = context.AfterAll
84
+ global.Feature = context.Feature
85
+ global.xFeature = context.xFeature
86
+ global.BeforeSuite = context.BeforeSuite
87
+ global.AfterSuite = context.AfterSuite
88
+ global.Background = context.Background
89
+ global.Before = context.Before
90
+ global.After = context.After
91
+ global.Scenario = context.Scenario
92
+ global.xScenario = context.xScenario
93
+ }
94
+
95
+ /**
96
+ * Clear all CodeceptJS globals (useful for testing/cleanup)
97
+ */
98
+ export function clearGlobals() {
99
+ getGlobalNames().forEach(name => delete global[name]);
100
+ }
101
+
102
+ /**
103
+ * Get list of all CodeceptJS global variable names
104
+ */
105
+ export function getGlobalNames() {
106
+ return [
107
+ 'codecept_dir',
108
+ 'output_dir',
109
+ 'actor',
110
+ 'codecept_actor',
111
+ 'Actor',
112
+ 'pause',
113
+ 'within',
114
+ 'session',
115
+ 'DataTable',
116
+ 'locate',
117
+ 'inject',
118
+ 'share',
119
+ 'secret',
120
+ 'codecept_debug',
121
+ 'codeceptjs',
122
+ 'Given',
123
+ 'When',
124
+ 'Then',
125
+ 'DefineParameterType',
126
+ 'debugMode',
127
+ 'maskSensitiveData',
128
+ 'BeforeAll',
129
+ 'AfterAll',
130
+ 'Feature',
131
+ 'xFeature',
132
+ 'BeforeSuite',
133
+ 'AfterSuite',
134
+ 'Background',
135
+ 'Before',
136
+ 'After',
137
+ 'Scenario',
138
+ 'xScenario',
139
+ 'container'
140
+ ]
141
+ }