codeceptjs 4.0.0-beta.5 → 4.0.0-beta.6.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 (179) hide show
  1. package/README.md +0 -45
  2. package/bin/codecept.js +46 -57
  3. package/lib/actor.js +15 -11
  4. package/lib/ai.js +6 -5
  5. package/lib/assert/empty.js +9 -8
  6. package/lib/assert/equal.js +15 -17
  7. package/lib/assert/error.js +2 -2
  8. package/lib/assert/include.js +9 -11
  9. package/lib/assert/throws.js +1 -1
  10. package/lib/assert/truth.js +8 -5
  11. package/lib/assert.js +18 -18
  12. package/lib/codecept.js +66 -107
  13. package/lib/colorUtils.js +48 -50
  14. package/lib/command/check.js +32 -27
  15. package/lib/command/configMigrate.js +11 -10
  16. package/lib/command/definitions.js +16 -10
  17. package/lib/command/dryRun.js +16 -16
  18. package/lib/command/generate.js +29 -26
  19. package/lib/command/gherkin/init.js +36 -38
  20. package/lib/command/gherkin/snippets.js +14 -14
  21. package/lib/command/gherkin/steps.js +21 -18
  22. package/lib/command/info.js +8 -8
  23. package/lib/command/init.js +34 -31
  24. package/lib/command/interactive.js +11 -10
  25. package/lib/command/list.js +10 -9
  26. package/lib/command/run-multiple/chunk.js +5 -5
  27. package/lib/command/run-multiple/collection.js +5 -5
  28. package/lib/command/run-multiple/run.js +3 -3
  29. package/lib/command/run-multiple.js +16 -13
  30. package/lib/command/run-rerun.js +6 -7
  31. package/lib/command/run-workers.js +10 -24
  32. package/lib/command/run.js +8 -8
  33. package/lib/command/utils.js +20 -18
  34. package/lib/command/workers/runTests.js +117 -269
  35. package/lib/config.js +111 -49
  36. package/lib/container.js +299 -102
  37. package/lib/data/context.js +6 -5
  38. package/lib/data/dataScenarioConfig.js +1 -1
  39. package/lib/data/dataTableArgument.js +1 -1
  40. package/lib/data/table.js +1 -1
  41. package/lib/effects.js +94 -10
  42. package/lib/els.js +11 -9
  43. package/lib/event.js +11 -10
  44. package/lib/globals.js +141 -0
  45. package/lib/heal.js +12 -12
  46. package/lib/helper/AI.js +1 -1
  47. package/lib/helper/ApiDataFactory.js +16 -13
  48. package/lib/helper/FileSystem.js +32 -12
  49. package/lib/helper/GraphQL.js +1 -1
  50. package/lib/helper/GraphQLDataFactory.js +1 -1
  51. package/lib/helper/JSONResponse.js +19 -30
  52. package/lib/helper/Mochawesome.js +9 -28
  53. package/lib/helper/Playwright.js +668 -265
  54. package/lib/helper/Puppeteer.js +284 -169
  55. package/lib/helper/REST.js +29 -12
  56. package/lib/helper/WebDriver.js +191 -71
  57. package/lib/helper/errors/ConnectionRefused.js +6 -6
  58. package/lib/helper/errors/ElementAssertion.js +11 -16
  59. package/lib/helper/errors/ElementNotFound.js +5 -9
  60. package/lib/helper/errors/RemoteBrowserConnectionRefused.js +5 -5
  61. package/lib/helper/extras/Console.js +11 -11
  62. package/lib/helper/extras/PlaywrightLocator.js +110 -0
  63. package/lib/helper/extras/PlaywrightPropEngine.js +18 -18
  64. package/lib/helper/extras/PlaywrightRestartOpts.js +23 -23
  65. package/lib/helper/extras/Popup.js +1 -1
  66. package/lib/helper/extras/React.js +29 -30
  67. package/lib/helper/network/actions.js +33 -48
  68. package/lib/helper/network/utils.js +76 -83
  69. package/lib/helper/scripts/blurElement.js +6 -6
  70. package/lib/helper/scripts/focusElement.js +6 -6
  71. package/lib/helper/scripts/highlightElement.js +9 -9
  72. package/lib/helper/scripts/isElementClickable.js +34 -34
  73. package/lib/helper.js +2 -1
  74. package/lib/history.js +23 -20
  75. package/lib/hooks.js +10 -10
  76. package/lib/html.js +90 -100
  77. package/lib/index.js +48 -21
  78. package/lib/listener/config.js +8 -9
  79. package/lib/listener/emptyRun.js +6 -7
  80. package/lib/listener/exit.js +4 -3
  81. package/lib/listener/globalRetry.js +5 -5
  82. package/lib/listener/globalTimeout.js +11 -10
  83. package/lib/listener/helpers.js +33 -14
  84. package/lib/listener/mocha.js +3 -4
  85. package/lib/listener/result.js +4 -5
  86. package/lib/listener/steps.js +7 -18
  87. package/lib/listener/store.js +3 -3
  88. package/lib/locator.js +213 -192
  89. package/lib/mocha/asyncWrapper.js +108 -75
  90. package/lib/mocha/bdd.js +99 -13
  91. package/lib/mocha/cli.js +60 -27
  92. package/lib/mocha/factory.js +75 -19
  93. package/lib/mocha/featureConfig.js +1 -1
  94. package/lib/mocha/gherkin.js +57 -25
  95. package/lib/mocha/hooks.js +12 -3
  96. package/lib/mocha/index.js +13 -4
  97. package/lib/mocha/inject.js +22 -5
  98. package/lib/mocha/scenarioConfig.js +2 -2
  99. package/lib/mocha/suite.js +9 -2
  100. package/lib/mocha/test.js +10 -13
  101. package/lib/mocha/ui.js +28 -31
  102. package/lib/output.js +11 -9
  103. package/lib/parser.js +44 -44
  104. package/lib/pause.js +15 -16
  105. package/lib/plugin/analyze.js +19 -12
  106. package/lib/plugin/auth.js +20 -21
  107. package/lib/plugin/autoDelay.js +12 -8
  108. package/lib/plugin/coverage.js +12 -8
  109. package/lib/plugin/customLocator.js +3 -3
  110. package/lib/plugin/customReporter.js +3 -2
  111. package/lib/plugin/heal.js +14 -9
  112. package/lib/plugin/pageInfo.js +10 -10
  113. package/lib/plugin/pauseOnFail.js +4 -3
  114. package/lib/plugin/retryFailedStep.js +47 -5
  115. package/lib/plugin/screenshotOnFail.js +75 -37
  116. package/lib/plugin/stepByStepReport.js +14 -14
  117. package/lib/plugin/stepTimeout.js +4 -3
  118. package/lib/plugin/subtitles.js +6 -5
  119. package/lib/recorder.js +33 -23
  120. package/lib/rerun.js +69 -26
  121. package/lib/result.js +4 -4
  122. package/lib/secret.js +18 -17
  123. package/lib/session.js +95 -89
  124. package/lib/step/base.js +6 -6
  125. package/lib/step/config.js +1 -1
  126. package/lib/step/func.js +3 -3
  127. package/lib/step/helper.js +3 -3
  128. package/lib/step/meta.js +4 -4
  129. package/lib/step/record.js +11 -11
  130. package/lib/step/retry.js +3 -3
  131. package/lib/step/section.js +3 -3
  132. package/lib/step.js +7 -10
  133. package/lib/steps.js +9 -5
  134. package/lib/store.js +1 -1
  135. package/lib/timeout.js +1 -7
  136. package/lib/transform.js +8 -8
  137. package/lib/translation.js +32 -18
  138. package/lib/utils.js +68 -97
  139. package/lib/workerStorage.js +16 -17
  140. package/lib/workers.js +145 -171
  141. package/package.json +63 -57
  142. package/translations/de-DE.js +2 -2
  143. package/translations/fr-FR.js +2 -2
  144. package/translations/index.js +23 -10
  145. package/translations/it-IT.js +2 -2
  146. package/translations/ja-JP.js +2 -2
  147. package/translations/nl-NL.js +2 -2
  148. package/translations/pl-PL.js +2 -2
  149. package/translations/pt-BR.js +2 -2
  150. package/translations/ru-RU.js +2 -2
  151. package/translations/utils.js +11 -2
  152. package/translations/zh-CN.js +2 -2
  153. package/translations/zh-TW.js +2 -2
  154. package/typings/index.d.ts +7 -18
  155. package/typings/promiseBasedTypes.d.ts +3769 -5450
  156. package/typings/types.d.ts +3953 -5778
  157. package/bin/test-server.js +0 -53
  158. package/lib/element/WebElement.js +0 -327
  159. package/lib/helper/Nightmare.js +0 -1486
  160. package/lib/helper/Protractor.js +0 -1840
  161. package/lib/helper/TestCafe.js +0 -1391
  162. package/lib/helper/clientscripts/nightmare.js +0 -213
  163. package/lib/helper/extras/PlaywrightReactVueLocator.js +0 -43
  164. package/lib/helper/testcafe/testControllerHolder.js +0 -42
  165. package/lib/helper/testcafe/testcafe-utils.js +0 -61
  166. package/lib/listener/retryEnhancer.js +0 -85
  167. package/lib/plugin/allure.js +0 -15
  168. package/lib/plugin/autoLogin.js +0 -5
  169. package/lib/plugin/commentStep.js +0 -141
  170. package/lib/plugin/eachElement.js +0 -127
  171. package/lib/plugin/fakerTransform.js +0 -49
  172. package/lib/plugin/htmlReporter.js +0 -1947
  173. package/lib/plugin/retryTo.js +0 -16
  174. package/lib/plugin/selenoid.js +0 -364
  175. package/lib/plugin/standardActingHelpers.js +0 -6
  176. package/lib/plugin/tryTo.js +0 -16
  177. package/lib/plugin/wdio.js +0 -247
  178. package/lib/test-server.js +0 -323
  179. package/lib/within.js +0 -90
package/lib/data/table.js CHANGED
@@ -40,4 +40,4 @@ class DataTable {
40
40
  }
41
41
  }
42
42
 
43
- module.exports = DataTable
43
+ export default DataTable
package/lib/effects.js CHANGED
@@ -1,8 +1,89 @@
1
- const recorder = require('./recorder')
2
- const { debug } = require('./output')
3
- const store = require('./store')
4
- const event = require('./event')
5
- const within = require('./within')
1
+ import recorder from './recorder.js'
2
+ import output from './output.js'
3
+ import store from './store.js'
4
+ import event from './event.js'
5
+ import container from './container.js'
6
+ import MetaStep from './step/meta.js'
7
+ import { isAsyncFunction } from './utils.js'
8
+
9
+ /**
10
+ * @param {CodeceptJS.LocatorOrString} context
11
+ * @param {Function} fn
12
+ * @return {Promise<*> | undefined}
13
+ */
14
+ function within(context, fn) {
15
+ const helpers = store.dryRun ? {} : container.helpers()
16
+ const locator = typeof context === 'object' ? JSON.stringify(context) : context
17
+
18
+ return recorder.add(
19
+ 'register within wrapper',
20
+ () => {
21
+ const metaStep = new WithinStep(locator, fn)
22
+ const defineMetaStep = step => (step.metaStep = metaStep)
23
+ recorder.session.start('within')
24
+
25
+ event.dispatcher.prependListener(event.step.before, defineMetaStep)
26
+
27
+ Object.keys(helpers).forEach(helper => {
28
+ if (helpers[helper]._withinBegin) recorder.add(`[${helper}] start within`, () => helpers[helper]._withinBegin(context))
29
+ })
30
+
31
+ const finalize = () => {
32
+ event.dispatcher.removeListener(event.step.before, defineMetaStep)
33
+ recorder.add('Finalize session within session', () => {
34
+ output.stepShift = 1
35
+ recorder.session.restore('within')
36
+ })
37
+ }
38
+ const finishHelpers = () => {
39
+ Object.keys(helpers).forEach(helper => {
40
+ if (helpers[helper]._withinEnd) recorder.add(`[${helper}] finish within`, () => helpers[helper]._withinEnd())
41
+ })
42
+ }
43
+
44
+ if (isAsyncFunction(fn)) {
45
+ return fn()
46
+ .then(res => {
47
+ finishHelpers()
48
+ finalize()
49
+ return recorder.promise().then(() => res)
50
+ })
51
+ .catch(e => {
52
+ finalize()
53
+ recorder.throw(e)
54
+ })
55
+ }
56
+
57
+ let res
58
+ try {
59
+ res = fn()
60
+ } catch (err) {
61
+ recorder.throw(err)
62
+ } finally {
63
+ finishHelpers()
64
+ recorder.catch(err => {
65
+ output.stepShift = 1
66
+ throw err
67
+ })
68
+ }
69
+ finalize()
70
+ return recorder.promise().then(() => res)
71
+ },
72
+ false,
73
+ false,
74
+ )
75
+ }
76
+
77
+ class WithinStep extends MetaStep {
78
+ constructor(locator, fn) {
79
+ super('Within')
80
+ this.args = [locator]
81
+ }
82
+
83
+ toString() {
84
+ return `${this.prefix}Within ${this.humanizeArgs()}${this.suffix}`
85
+ }
86
+ }
6
87
 
7
88
  /**
8
89
  * A utility function for CodeceptJS tests that acts as a soft assertion.
@@ -49,8 +130,9 @@ async function hopeThat(callback) {
49
130
  recorder.session.catch(err => {
50
131
  result = false
51
132
  const msg = err.inspect ? err.inspect() : err.toString()
52
- debug(`Unsuccessful assertion > ${msg}`)
133
+ output.debug(`Unsuccessful assertion > ${msg}`)
53
134
  event.dispatcher.once(event.test.finished, test => {
135
+ if (!test.notes) test.notes = []
54
136
  test.notes.push({ type: 'conditionalError', text: msg })
55
137
  })
56
138
  recorder.session.restore(sessionName)
@@ -130,7 +212,7 @@ async function retryTo(callback, maxTries, pollInterval = 200) {
130
212
  recorder.session.catch(err => {
131
213
  recorder.session.restore(`${sessionName} ${tries}`)
132
214
  if (tries <= maxTries) {
133
- debug(`Error ${err}... Retrying`)
215
+ output.debug(`Error ${err}... Retrying`)
134
216
  recorder.add(`${sessionName} ${tries}`, () => setTimeout(tryBlock, pollInterval))
135
217
  } else {
136
218
  // if maxTries reached
@@ -185,7 +267,7 @@ async function tryTo(callback) {
185
267
  () => {
186
268
  recorder.session.start(sessionName)
187
269
  isAutoRetriesEnabled = store.autoRetries
188
- if (isAutoRetriesEnabled) debug('Auto retries disabled inside tryTo effect')
270
+ if (isAutoRetriesEnabled) output.debug('Auto retries disabled inside tryTo effect')
189
271
  store.autoRetries = false
190
272
  callback()
191
273
  recorder.add(() => {
@@ -196,7 +278,7 @@ async function tryTo(callback) {
196
278
  recorder.session.catch(err => {
197
279
  result = false
198
280
  const msg = err.inspect ? err.inspect() : err.toString()
199
- debug(`Unsuccessful try > ${msg}`)
281
+ output.debug(`Unsuccessful try > ${msg}`)
200
282
  recorder.session.restore(sessionName)
201
283
  return result
202
284
  })
@@ -215,7 +297,9 @@ async function tryTo(callback) {
215
297
  )
216
298
  }
217
299
 
218
- module.exports = {
300
+ export { hopeThat, retryTo, tryTo, within }
301
+
302
+ export default {
219
303
  hopeThat,
220
304
  retryTo,
221
305
  tryTo,
package/lib/els.js CHANGED
@@ -1,11 +1,11 @@
1
- const output = require('./output')
2
- const store = require('./store')
3
- const container = require('./container')
4
- const StepConfig = require('./step/config')
5
- const recordStep = require('./step/record')
6
- const FuncStep = require('./step/func')
7
- const { truth } = require('./assert/truth')
8
- const { isAsyncFunction, humanizeFunction } = require('./utils')
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
9
 
10
10
  function element(purpose, locator, fn) {
11
11
  let stepConfig
@@ -121,7 +121,9 @@ function expectAllElements(locator, fn) {
121
121
  })
122
122
  }
123
123
 
124
- module.exports = {
124
+ export { element, eachElement, expectElement, expectAnyElement, expectAllElements }
125
+
126
+ export default {
125
127
  element,
126
128
  eachElement,
127
129
  expectElement,
package/lib/event.js CHANGED
@@ -1,6 +1,7 @@
1
- const debug = require('debug')('codeceptjs:event')
2
- const events = require('events')
3
- const { error } = require('./output')
1
+ import debugModule from 'debug'
2
+ const debug = debugModule('codeceptjs:event')
3
+ import events from 'events'
4
+ import output from './output.js'
4
5
 
5
6
  const dispatcher = new events.EventEmitter()
6
7
 
@@ -9,7 +10,7 @@ dispatcher.setMaxListeners(50)
9
10
  * @namespace
10
11
  * @alias event
11
12
  */
12
- module.exports = {
13
+ export default {
13
14
  /**
14
15
  * @type {NodeJS.EventEmitter}
15
16
  * @constant
@@ -152,25 +153,25 @@ module.exports = {
152
153
  try {
153
154
  this.dispatcher.emit.apply(this.dispatcher, arguments)
154
155
  } catch (err) {
155
- error(`Error processing ${event} event:`)
156
- error(err.stack)
156
+ output.error(`Error processing ${event} event:`)
157
+ output.error(err.stack)
157
158
  }
158
159
  },
159
160
 
160
161
  /** for testing only! */
161
- cleanDispatcher: () => {
162
+ cleanDispatcher() {
162
163
  let event
163
164
  for (event in this.test) {
164
165
  this.dispatcher.removeAllListeners(this.test[event])
165
166
  }
166
167
  for (event in this.suite) {
167
- this.dispatcher.removeAllListeners(this.test[event])
168
+ this.dispatcher.removeAllListeners(this.suite[event])
168
169
  }
169
170
  for (event in this.step) {
170
- this.dispatcher.removeAllListeners(this.test[event])
171
+ this.dispatcher.removeAllListeners(this.step[event])
171
172
  }
172
173
  for (event in this.all) {
173
- this.dispatcher.removeAllListeners(this.test[event])
174
+ this.dispatcher.removeAllListeners(this.all[event])
174
175
  }
175
176
  },
176
177
  }
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
+ }
package/lib/heal.js CHANGED
@@ -1,9 +1,9 @@
1
- const debug = require('debug')('codeceptjs:heal')
2
- const colors = require('chalk')
3
- const Container = require('./container')
4
- const recorder = require('./recorder')
5
- const output = require('./output')
6
- const event = require('./event')
1
+ import debugModule from 'debug'
2
+ const debug = debugModule('codeceptjs:heal')
3
+ import colors from 'chalk'
4
+ import recorder from './recorder.js'
5
+ import output from './output.js'
6
+ import event from './event.js'
7
7
 
8
8
  /**
9
9
  * @class
@@ -69,7 +69,7 @@ class Heal {
69
69
  if (!prepareFn) continue
70
70
 
71
71
  if (context[property]) continue
72
- context[property] = await prepareFn(Container.support())
72
+ context[property] = await prepareFn(global.inject())
73
73
  }
74
74
 
75
75
  output.level(currentOutputLevel)
@@ -116,10 +116,10 @@ class Heal {
116
116
  })
117
117
 
118
118
  if (typeof codeSnippet === 'string') {
119
- const I = Container.support('I')
119
+ const I = global.container.support('I')
120
120
  await eval(codeSnippet)
121
121
  } else if (typeof codeSnippet === 'function') {
122
- await codeSnippet(Container.support())
122
+ await codeSnippet(global.container.support())
123
123
  }
124
124
 
125
125
  this.fixes.push({
@@ -155,14 +155,14 @@ class Heal {
155
155
  recorder.throw(error)
156
156
  }
157
157
 
158
- static setDefaultHealers() {
159
- require('./template/heal')
158
+ static async setDefaultHealers() {
159
+ await import('./template/heal.js')
160
160
  }
161
161
  }
162
162
 
163
163
  const heal = new Heal()
164
164
 
165
- module.exports = heal
165
+ export default heal
166
166
 
167
167
  function matchRecipes(recipes, contextName) {
168
168
  return Object.entries(recipes)
package/lib/helper/AI.js CHANGED
@@ -1,4 +1,4 @@
1
- const Helper = require('@codeceptjs/helper')
1
+ const HelperModule = require('@codeceptjs/helper')
2
2
  const ora = require('ora-classic')
3
3
  const fs = require('fs')
4
4
  const path = require('path')
@@ -1,7 +1,6 @@
1
- const path = require('path')
2
-
3
- const Helper = require('@codeceptjs/helper')
4
- const REST = require('./REST')
1
+ import path from 'path'
2
+ import Helper from '@codeceptjs/helper'
3
+ import REST from './REST.js'
5
4
 
6
5
  /**
7
6
  * Helper for managing remote data using REST API.
@@ -222,10 +221,11 @@ class ApiDataFactory extends Helper {
222
221
 
223
222
  static _checkRequirements() {
224
223
  try {
225
- require('axios')
226
- require('rosie')
224
+ // In ESM, dependencies are already imported at the top
225
+ // The import will fail at module load time if dependencies are missing
226
+ return null
227
227
  } catch (e) {
228
- return ['axios', 'rosie']
228
+ return ['axios']
229
229
  }
230
230
  }
231
231
 
@@ -265,8 +265,8 @@ class ApiDataFactory extends Helper {
265
265
  * @param {*} [options] options for programmatically generate the attributes
266
266
  * @returns {Promise<*>}
267
267
  */
268
- have(factory, params, options) {
269
- const item = this._createItem(factory, params, options)
268
+ async have(factory, params, options) {
269
+ const item = await this._createItem(factory, params, options)
270
270
  this.debug(`Creating ${factory} ${JSON.stringify(item)}`)
271
271
  return this._requestCreate(factory, item)
272
272
  }
@@ -298,19 +298,22 @@ class ApiDataFactory extends Helper {
298
298
  return Promise.all(promises)
299
299
  }
300
300
 
301
- _createItem(model, data, options) {
301
+ async _createItem(model, data, options) {
302
302
  if (!this.factories[model]) {
303
303
  throw new Error(`Factory ${model} is not defined in config`)
304
304
  }
305
305
  let modulePath = this.factories[model].factory
306
306
  try {
307
307
  try {
308
- require.resolve(modulePath)
308
+ // Try to resolve the path as-is first
309
+ await import.meta.resolve(modulePath)
309
310
  } catch (e) {
311
+ // If not found, try relative to codecept_dir
310
312
  modulePath = path.join(global.codecept_dir, modulePath)
311
313
  }
312
314
  // check if the new syntax `export default new Factory()` is used and loads the builder, otherwise loads the module that used old syntax `module.exports = new Factory()`.
313
- const builder = require(modulePath).default || require(modulePath)
315
+ const module = await import(modulePath)
316
+ const builder = module.default || module
314
317
  return builder.build(data, options)
315
318
  } catch (err) {
316
319
  throw new Error(`Couldn't load factory file from ${modulePath}, check that
@@ -402,7 +405,7 @@ Current file error: ${err.message}`)
402
405
  }
403
406
  }
404
407
 
405
- module.exports = ApiDataFactory
408
+ export { ApiDataFactory as default }
406
409
 
407
410
  function createRequestFromFunction(param, data) {
408
411
  if (typeof param !== 'function') return
@@ -1,11 +1,11 @@
1
- const assert = require('assert')
2
- const path = require('path')
3
- const fs = require('fs')
1
+ import assert from 'assert'
2
+ import path from 'path'
3
+ import fs from 'fs'
4
4
 
5
- const Helper = require('@codeceptjs/helper')
6
- const { fileExists } = require('../utils')
7
- const { fileIncludes } = require('../assert/include')
8
- const { fileEquals } = require('../assert/equal')
5
+ import Helper from '@codeceptjs/helper'
6
+ import { fileExists } from '../utils.js'
7
+ import { fileIncludes } from '../assert/include.js'
8
+ import { fileEquals } from '../assert/equal.js'
9
9
 
10
10
  /**
11
11
  * Helper for testing filesystem.
@@ -38,7 +38,12 @@ class FileSystem extends Helper {
38
38
  }
39
39
 
40
40
  _before() {
41
- this.debugSection('Dir', this.dir)
41
+ try {
42
+ this.debugSection('Dir', this.dir)
43
+ } catch (e) {
44
+ // Fallback debug for ESM transition
45
+ console.log(`[Dir] ${this.dir}`)
46
+ }
42
47
  }
43
48
 
44
49
  /**
@@ -48,7 +53,12 @@ class FileSystem extends Helper {
48
53
  */
49
54
  amInPath(openPath) {
50
55
  this.dir = path.join(global.codecept_dir, openPath)
51
- this.debugSection('Dir', this.dir)
56
+ try {
57
+ this.debugSection('Dir', this.dir)
58
+ } catch (e) {
59
+ // Fallback debug for ESM transition
60
+ console.log(`[Dir] ${this.dir}`)
61
+ }
52
62
  }
53
63
 
54
64
  /**
@@ -66,7 +76,12 @@ class FileSystem extends Helper {
66
76
  */
67
77
  seeFile(name) {
68
78
  this.file = path.join(this.dir, name)
69
- this.debugSection('File', this.file)
79
+ try {
80
+ this.debugSection('File', this.file)
81
+ } catch (e) {
82
+ // Fallback debug for ESM transition
83
+ console.log(`[File] ${this.file}`)
84
+ }
70
85
  assert.ok(fileExists(this.file), `File ${name} not found in ${this.dir}`)
71
86
  }
72
87
 
@@ -86,7 +101,12 @@ class FileSystem extends Helper {
86
101
  if (sec === 0) assert.fail('Use `seeFile` instead of waiting 0 seconds!')
87
102
  const waitTimeout = sec * 1000
88
103
  this.file = path.join(this.dir, name)
89
- this.debugSection('File', this.file)
104
+ try {
105
+ this.debugSection('File', this.file)
106
+ } catch (e) {
107
+ // Fallback debug for ESM transition
108
+ console.log(`[File] ${this.file}`)
109
+ }
90
110
  return isFileExists(this.file, waitTimeout).catch(() => {
91
111
  throw new Error(`file (${name}) still not present in directory ${this.dir} after ${waitTimeout / 1000} sec`)
92
112
  })
@@ -179,7 +199,7 @@ class FileSystem extends Helper {
179
199
  }
180
200
  }
181
201
 
182
- module.exports = FileSystem
202
+ export { FileSystem as default }
183
203
 
184
204
  /**
185
205
  * @param {string} file
@@ -1,5 +1,5 @@
1
1
  const axios = require('axios').default
2
- const Helper = require('@codeceptjs/helper')
2
+ const HelperModule = require('@codeceptjs/helper')
3
3
 
4
4
  /**
5
5
  * GraphQL helper allows to send additional requests to a GraphQl endpoint during acceptance tests.
@@ -1,6 +1,6 @@
1
1
  const path = require('path')
2
2
 
3
- const Helper = require('@codeceptjs/helper')
3
+ const HelperModule = require('@codeceptjs/helper')
4
4
  const GraphQL = require('./GraphQL')
5
5
 
6
6
  /**