codeceptjs 3.7.6-beta.4 → 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 (191) hide show
  1. package/README.md +1 -3
  2. package/bin/codecept.js +51 -53
  3. package/bin/test-server.js +14 -3
  4. package/docs/webapi/click.mustache +5 -1
  5. package/lib/actor.js +15 -11
  6. package/lib/ai.js +72 -107
  7. package/lib/assert/empty.js +9 -8
  8. package/lib/assert/equal.js +15 -17
  9. package/lib/assert/error.js +2 -2
  10. package/lib/assert/include.js +9 -11
  11. package/lib/assert/throws.js +1 -1
  12. package/lib/assert/truth.js +8 -5
  13. package/lib/assert.js +18 -18
  14. package/lib/codecept.js +102 -75
  15. package/lib/colorUtils.js +48 -50
  16. package/lib/command/check.js +32 -27
  17. package/lib/command/configMigrate.js +11 -10
  18. package/lib/command/definitions.js +16 -10
  19. package/lib/command/dryRun.js +16 -16
  20. package/lib/command/generate.js +62 -27
  21. package/lib/command/gherkin/init.js +36 -38
  22. package/lib/command/gherkin/snippets.js +14 -14
  23. package/lib/command/gherkin/steps.js +21 -18
  24. package/lib/command/info.js +8 -8
  25. package/lib/command/init.js +36 -29
  26. package/lib/command/interactive.js +11 -10
  27. package/lib/command/list.js +10 -9
  28. package/lib/command/run-multiple/chunk.js +5 -5
  29. package/lib/command/run-multiple/collection.js +5 -5
  30. package/lib/command/run-multiple/run.js +3 -3
  31. package/lib/command/run-multiple.js +16 -13
  32. package/lib/command/run-rerun.js +6 -7
  33. package/lib/command/run-workers.js +24 -9
  34. package/lib/command/run.js +23 -8
  35. package/lib/command/utils.js +20 -18
  36. package/lib/command/workers/runTests.js +197 -114
  37. package/lib/config.js +124 -51
  38. package/lib/container.js +438 -87
  39. package/lib/data/context.js +6 -5
  40. package/lib/data/dataScenarioConfig.js +1 -1
  41. package/lib/data/dataTableArgument.js +1 -1
  42. package/lib/data/table.js +1 -1
  43. package/lib/effects.js +94 -10
  44. package/lib/element/WebElement.js +2 -2
  45. package/lib/els.js +11 -9
  46. package/lib/event.js +11 -10
  47. package/lib/globals.js +141 -0
  48. package/lib/heal.js +12 -12
  49. package/lib/helper/AI.js +11 -11
  50. package/lib/helper/ApiDataFactory.js +50 -19
  51. package/lib/helper/Appium.js +19 -27
  52. package/lib/helper/FileSystem.js +32 -12
  53. package/lib/helper/GraphQL.js +3 -3
  54. package/lib/helper/GraphQLDataFactory.js +4 -4
  55. package/lib/helper/JSONResponse.js +25 -29
  56. package/lib/helper/Mochawesome.js +7 -4
  57. package/lib/helper/Playwright.js +902 -164
  58. package/lib/helper/Puppeteer.js +383 -76
  59. package/lib/helper/REST.js +29 -12
  60. package/lib/helper/WebDriver.js +268 -61
  61. package/lib/helper/clientscripts/PollyWebDriverExt.js +1 -1
  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 +18 -9
  70. package/lib/helper/extras/PlaywrightRestartOpts.js +34 -23
  71. package/lib/helper/extras/Popup.js +1 -1
  72. package/lib/helper/extras/React.js +29 -30
  73. package/lib/helper/network/actions.js +29 -44
  74. package/lib/helper/network/utils.js +76 -83
  75. package/lib/helper/scripts/blurElement.js +6 -6
  76. package/lib/helper/scripts/focusElement.js +6 -6
  77. package/lib/helper/scripts/highlightElement.js +9 -9
  78. package/lib/helper/scripts/isElementClickable.js +34 -34
  79. package/lib/helper.js +2 -1
  80. package/lib/history.js +23 -20
  81. package/lib/hooks.js +10 -10
  82. package/lib/html.js +90 -100
  83. package/lib/index.js +48 -21
  84. package/lib/listener/config.js +19 -12
  85. package/lib/listener/emptyRun.js +6 -7
  86. package/lib/listener/enhancedGlobalRetry.js +6 -6
  87. package/lib/listener/exit.js +4 -3
  88. package/lib/listener/globalRetry.js +5 -5
  89. package/lib/listener/globalTimeout.js +30 -14
  90. package/lib/listener/helpers.js +39 -14
  91. package/lib/listener/mocha.js +3 -4
  92. package/lib/listener/result.js +4 -5
  93. package/lib/listener/retryEnhancer.js +3 -3
  94. package/lib/listener/steps.js +8 -7
  95. package/lib/listener/store.js +3 -3
  96. package/lib/locator.js +213 -192
  97. package/lib/mocha/asyncWrapper.js +105 -62
  98. package/lib/mocha/bdd.js +99 -13
  99. package/lib/mocha/cli.js +59 -26
  100. package/lib/mocha/factory.js +78 -19
  101. package/lib/mocha/featureConfig.js +1 -1
  102. package/lib/mocha/gherkin.js +56 -24
  103. package/lib/mocha/hooks.js +12 -3
  104. package/lib/mocha/index.js +13 -4
  105. package/lib/mocha/inject.js +22 -5
  106. package/lib/mocha/scenarioConfig.js +2 -2
  107. package/lib/mocha/suite.js +9 -2
  108. package/lib/mocha/test.js +10 -7
  109. package/lib/mocha/ui.js +28 -18
  110. package/lib/output.js +10 -8
  111. package/lib/parser.js +44 -44
  112. package/lib/pause.js +15 -16
  113. package/lib/plugin/analyze.js +19 -12
  114. package/lib/plugin/auth.js +20 -21
  115. package/lib/plugin/autoDelay.js +12 -8
  116. package/lib/plugin/coverage.js +28 -11
  117. package/lib/plugin/customLocator.js +3 -3
  118. package/lib/plugin/customReporter.js +3 -2
  119. package/lib/plugin/enhancedRetryFailedStep.js +6 -6
  120. package/lib/plugin/heal.js +14 -9
  121. package/lib/plugin/htmlReporter.js +724 -99
  122. package/lib/plugin/pageInfo.js +10 -10
  123. package/lib/plugin/pauseOnFail.js +4 -3
  124. package/lib/plugin/retryFailedStep.js +48 -5
  125. package/lib/plugin/screenshotOnFail.js +75 -37
  126. package/lib/plugin/stepByStepReport.js +14 -14
  127. package/lib/plugin/stepTimeout.js +4 -3
  128. package/lib/plugin/subtitles.js +6 -5
  129. package/lib/recorder.js +33 -14
  130. package/lib/rerun.js +69 -26
  131. package/lib/result.js +4 -4
  132. package/lib/retryCoordinator.js +2 -2
  133. package/lib/secret.js +18 -17
  134. package/lib/session.js +95 -89
  135. package/lib/step/base.js +7 -7
  136. package/lib/step/comment.js +2 -2
  137. package/lib/step/config.js +1 -1
  138. package/lib/step/func.js +3 -3
  139. package/lib/step/helper.js +3 -3
  140. package/lib/step/meta.js +5 -5
  141. package/lib/step/record.js +11 -11
  142. package/lib/step/retry.js +3 -3
  143. package/lib/step/section.js +3 -3
  144. package/lib/step.js +7 -10
  145. package/lib/steps.js +9 -5
  146. package/lib/store.js +1 -1
  147. package/lib/template/heal.js +1 -1
  148. package/lib/template/prompts/generatePageObject.js +31 -0
  149. package/lib/template/prompts/healStep.js +13 -0
  150. package/lib/template/prompts/writeStep.js +9 -0
  151. package/lib/test-server.js +17 -6
  152. package/lib/timeout.js +1 -7
  153. package/lib/transform.js +8 -8
  154. package/lib/translation.js +32 -18
  155. package/lib/utils/mask_data.js +4 -10
  156. package/lib/utils.js +66 -64
  157. package/lib/workerStorage.js +17 -17
  158. package/lib/workers.js +214 -84
  159. package/package.json +41 -37
  160. package/translations/de-DE.js +2 -2
  161. package/translations/fr-FR.js +2 -2
  162. package/translations/index.js +23 -10
  163. package/translations/it-IT.js +2 -2
  164. package/translations/ja-JP.js +2 -2
  165. package/translations/nl-NL.js +2 -2
  166. package/translations/pl-PL.js +2 -2
  167. package/translations/pt-BR.js +2 -2
  168. package/translations/ru-RU.js +2 -2
  169. package/translations/utils.js +4 -3
  170. package/translations/zh-CN.js +2 -2
  171. package/translations/zh-TW.js +2 -2
  172. package/typings/index.d.ts +5 -3
  173. package/typings/promiseBasedTypes.d.ts +4 -0
  174. package/typings/types.d.ts +4 -0
  175. package/lib/helper/Nightmare.js +0 -1486
  176. package/lib/helper/Protractor.js +0 -1840
  177. package/lib/helper/TestCafe.js +0 -1391
  178. package/lib/helper/clientscripts/nightmare.js +0 -213
  179. package/lib/helper/testcafe/testControllerHolder.js +0 -42
  180. package/lib/helper/testcafe/testcafe-utils.js +0 -61
  181. package/lib/plugin/allure.js +0 -15
  182. package/lib/plugin/autoLogin.js +0 -5
  183. package/lib/plugin/commentStep.js +0 -141
  184. package/lib/plugin/eachElement.js +0 -127
  185. package/lib/plugin/fakerTransform.js +0 -49
  186. package/lib/plugin/retryTo.js +0 -16
  187. package/lib/plugin/selenoid.js +0 -364
  188. package/lib/plugin/standardActingHelpers.js +0 -6
  189. package/lib/plugin/tryTo.js +0 -16
  190. package/lib/plugin/wdio.js +0 -247
  191. package/lib/within.js +0 -90
@@ -1,28 +1,31 @@
1
- const Gherkin = require('@cucumber/gherkin')
2
- const Messages = require('@cucumber/messages')
3
- const { Context, Suite } = require('mocha')
4
- const debug = require('debug')('codeceptjs:bdd')
5
-
6
- const { enhanceMochaSuite } = require('./suite')
7
- const { createTest } = require('./test')
8
- const { matchStep } = require('./bdd')
9
- const event = require('../event')
10
- const { injected, setup, teardown, suiteSetup, suiteTeardown } = require('./asyncWrapper')
11
- const Step = require('../step')
12
- const DataTableArgument = require('../data/dataTableArgument')
13
- const transform = require('../transform')
14
-
15
- const uuidFn = Messages.IdGenerator.uuid()
1
+ import Gherkin from '@cucumber/gherkin'
2
+ import { IdGenerator } from '@cucumber/messages'
3
+ import { Context, Suite } from 'mocha'
4
+ import debug from 'debug'
5
+ const debugBdd = debug('codeceptjs:bdd')
6
+
7
+ import event from '../event.js'
8
+ import { injected, setup, teardown, suiteSetup, suiteTeardown } from './asyncWrapper.js'
9
+ import step from '../step/base.js'
10
+ import MetaStep from '../step/meta.js'
11
+ import DataTableArgument from '../data/dataTableArgument.js'
12
+ import transform from '../transform.js'
13
+ import { enhanceMochaSuite } from './suite.js'
14
+ import { createTest } from './test.js'
15
+ import { matchStep } from './bdd.js'
16
+
17
+ const uuidFn = IdGenerator.uuid()
16
18
  const builder = new Gherkin.AstBuilder(uuidFn)
17
19
  const matcher = new Gherkin.GherkinClassicTokenMatcher()
18
20
  const parser = new Gherkin.Parser(builder, matcher)
19
21
  parser.stopAtFirstError = false
20
22
 
21
- module.exports = (text, file) => {
23
+ const gherkinParser = (text, file) => {
22
24
  const ast = parser.parse(text)
23
25
  let currentLanguage
24
26
 
25
27
  if (ast.feature) {
28
+ // Ensure translations are loaded before trying to access them
26
29
  currentLanguage = getTranslation(ast.feature.language)
27
30
  }
28
31
 
@@ -39,14 +42,20 @@ module.exports = (text, file) => {
39
42
  suite.file = file
40
43
  suite.timeout(0)
41
44
 
42
- suite.beforeEach('codeceptjs.before', () => setup(suite))
43
- suite.afterEach('codeceptjs.after', () => teardown(suite))
44
- suite.beforeAll('codeceptjs.beforeSuite', () => suiteSetup(suite))
45
- suite.afterAll('codeceptjs.afterSuite', () => suiteTeardown(suite))
45
+ suite.beforeEach('codeceptjs.before', function () {
46
+ // In Mocha, 'this' refers to the current test in beforeEach/afterEach hooks
47
+ setup(this)(() => {})
48
+ })
49
+ suite.afterEach('codeceptjs.after', function () {
50
+ // In Mocha, 'this' refers to the current test in beforeEach/afterEach hooks
51
+ teardown(this)(() => {})
52
+ })
53
+ suite.beforeAll('codeceptjs.beforeSuite', suiteSetup(suite))
54
+ suite.afterAll('codeceptjs.afterSuite', suiteTeardown(suite))
46
55
 
47
56
  const runSteps = async steps => {
48
57
  for (const step of steps) {
49
- const metaStep = new Step.MetaStep(null, step.text)
58
+ const metaStep = new MetaStep(null, step.text)
50
59
  metaStep.actor = step.keyword.trim()
51
60
  let helperStep
52
61
  const setMetaStep = step => {
@@ -184,16 +193,39 @@ function addExampleInTable(exampleSteps, placeholders) {
184
193
  return steps
185
194
  }
186
195
 
196
+ // Import translations at module level to avoid async in parser
197
+ let translations = null
198
+ async function loadTranslations() {
199
+ if (!translations) {
200
+ // Import container to ensure it's initialized
201
+ const Container = await import('../container.js')
202
+ await Container.default.started()
203
+
204
+ // Now load translations
205
+ const translationsModule = await import('../../translations/index.js')
206
+ translations = translationsModule.default || translationsModule
207
+ }
208
+ return translations
209
+ }
210
+
187
211
  function getTranslation(language) {
188
- const translations = Object.keys(require('../../translations'))
212
+ if (!translations) {
213
+ // Translations not loaded yet, return null (will use default)
214
+ return null
215
+ }
189
216
 
190
- for (const availableTranslation of translations) {
217
+ const translationKeys = Object.keys(translations)
218
+ for (const availableTranslation of translationKeys) {
191
219
  if (!language) {
192
220
  break
193
221
  }
194
222
 
195
223
  if (availableTranslation.includes(language)) {
196
- return require('../../translations')[availableTranslation]
224
+ return translations[availableTranslation]
197
225
  }
198
226
  }
227
+ return null
199
228
  }
229
+
230
+ export { loadTranslations }
231
+ export default gherkinParser
@@ -1,5 +1,5 @@
1
- const event = require('../event')
2
- const { serializeError } = require('../utils')
1
+ import event from '../event.js'
2
+ import { serializeError } from '../utils.js'
3
3
  // const { serializeTest } = require('./test')
4
4
 
5
5
  /**
@@ -102,7 +102,16 @@ class HookConfig {
102
102
  }
103
103
  }
104
104
 
105
- module.exports = {
105
+ export {
106
+ BeforeHook,
107
+ AfterHook,
108
+ BeforeSuiteHook,
109
+ AfterSuiteHook,
110
+ fireHook,
111
+ HookConfig,
112
+ }
113
+
114
+ export default {
106
115
  BeforeHook,
107
116
  AfterHook,
108
117
  BeforeSuiteHook,
@@ -1,8 +1,17 @@
1
- const Suite = require('mocha/lib/suite')
2
- const Test = require('mocha/lib/test')
3
- const { BeforeHook, AfterHook, BeforeSuiteHook, AfterSuiteHook } = require('./hooks')
1
+ import Suite from 'mocha/lib/suite.js'
2
+ import Test from 'mocha/lib/test.js'
3
+ import { BeforeHook, AfterHook, BeforeSuiteHook, AfterSuiteHook } from './hooks.js'
4
4
 
5
- module.exports = {
5
+ export {
6
+ Suite,
7
+ Test,
8
+ BeforeHook,
9
+ AfterHook,
10
+ BeforeSuiteHook,
11
+ AfterSuiteHook,
12
+ }
13
+
14
+ export default {
6
15
  Suite,
7
16
  Test,
8
17
  BeforeHook,
@@ -1,13 +1,30 @@
1
- const parser = require('../parser')
1
+ import { getParams } from '../parser.js'
2
+
3
+ const getInjectedArguments = async (fn, test, suite) => {
4
+ const containerModule = await import('../container.js')
5
+ const container = containerModule.default || containerModule
2
6
 
3
- const getInjectedArguments = (fn, test) => {
4
- const container = require('../container')
5
7
  const testArgs = {}
6
- const params = parser.getParams(fn) || []
8
+ const params = getParams(fn) || []
7
9
  const objects = container.support()
8
10
 
9
11
  for (const key of params) {
10
12
  testArgs[key] = {}
13
+
14
+ // Handle special built-in objects first
15
+ if (key === 'suite') {
16
+ if (test) {
17
+ testArgs[key] = test.parent || test
18
+ } else if (suite) {
19
+ testArgs[key] = suite
20
+ }
21
+ continue
22
+ }
23
+ if (key === 'test') {
24
+ testArgs[key] = test
25
+ continue
26
+ }
27
+
11
28
  if (test && test.inject && test.inject[key]) {
12
29
  // @FIX: need fix got inject
13
30
  testArgs[key] = test.inject[key]
@@ -26,4 +43,4 @@ const getInjectedArguments = (fn, test) => {
26
43
  return testArgs
27
44
  }
28
45
 
29
- module.exports.getInjectedArguments = getInjectedArguments
46
+ export { getInjectedArguments }
@@ -1,4 +1,4 @@
1
- const { isAsyncFunction } = require('../utils')
1
+ import { isAsyncFunction } from '../utils.js'
2
2
 
3
3
  /** @class */
4
4
  class ScenarioConfig {
@@ -135,4 +135,4 @@ class ScenarioConfig {
135
135
  }
136
136
  }
137
137
 
138
- module.exports = ScenarioConfig
138
+ export default ScenarioConfig
@@ -1,4 +1,4 @@
1
- const MochaSuite = require('mocha/lib/suite')
1
+ import MochaSuite from 'mocha/lib/suite.js'
2
2
  /**
3
3
  * @typedef {import('mocha')} Mocha
4
4
  */
@@ -74,7 +74,14 @@ function deserializeSuite(suite) {
74
74
  return suite
75
75
  }
76
76
 
77
- module.exports = {
77
+ export {
78
+ createSuite,
79
+ enhanceMochaSuite,
80
+ serializeSuite,
81
+ deserializeSuite,
82
+ }
83
+
84
+ export default {
78
85
  createSuite,
79
86
  enhanceMochaSuite,
80
87
  serializeSuite,
package/lib/mocha/test.js CHANGED
@@ -1,9 +1,9 @@
1
- const Test = require('mocha/lib/test')
2
- const Suite = require('mocha/lib/suite')
3
- const { test: testWrapper } = require('./asyncWrapper')
4
- const { enhanceMochaSuite, createSuite } = require('./suite')
5
- const { genTestId, serializeError, clearString, relativeDir } = require('../utils')
6
- const Step = require('../step/base')
1
+ import Test from 'mocha/lib/test.js'
2
+ import Suite from 'mocha/lib/suite.js'
3
+ import { genTestId, serializeError, clearString, relativeDir } from '../utils.js'
4
+ import Step from '../step/base.js'
5
+ import { enhanceMochaSuite } from './suite.js'
6
+ import { test as testWrapper } from './asyncWrapper.js'
7
7
  /**
8
8
  * Factory function to create enhanced tests
9
9
  * @param {string} title - Test title
@@ -47,6 +47,7 @@ function enhanceMochaTest(test) {
47
47
  */
48
48
  test.addToSuite = function (suite) {
49
49
  enhanceMochaSuite(suite)
50
+ // Get testWrapper from asyncWrapper module
50
51
  suite.addTest(testWrapper(this))
51
52
  if (test.file && !suite.file) suite.file = test.file
52
53
  test.tags = [...(test.tags || []), ...(suite.tags || [])]
@@ -171,7 +172,9 @@ function testToFileName(test, { suffix = '', unique = false } = {}) {
171
172
  return fileName
172
173
  }
173
174
 
174
- module.exports = {
175
+ export { createTest, testToFileName, enhanceMochaTest, serializeTest, deserializeTest, cloneTest }
176
+
177
+ export default {
175
178
  createTest,
176
179
  testToFileName,
177
180
  enhanceMochaTest,
package/lib/mocha/ui.js CHANGED
@@ -1,15 +1,22 @@
1
- const escapeRe = require('escape-string-regexp')
2
- const { test, setup, teardown, suiteSetup, suiteTeardown, injected } = require('./asyncWrapper')
3
- const ScenarioConfig = require('./scenarioConfig')
4
- const FeatureConfig = require('./featureConfig')
5
- const addDataContext = require('../data/context')
6
- const { createTest } = require('./test')
7
- const { createSuite } = require('./suite')
8
- const { HookConfig, AfterSuiteHook, AfterHook, BeforeSuiteHook, BeforeHook } = require('./hooks')
1
+ import escapeRe from 'escape-string-regexp'
2
+ import { test, setup, teardown, suiteSetup, suiteTeardown, injected } from './asyncWrapper.js'
3
+ import ScenarioConfig from './scenarioConfig.js'
4
+ import FeatureConfig from './featureConfig.js'
5
+ import addDataContext from '../data/context.js'
6
+ import { createTest } from './test.js'
7
+ import { createSuite } from './suite.js'
8
+ import { HookConfig, AfterSuiteHook, AfterHook, BeforeSuiteHook, BeforeHook } from './hooks.js'
9
+ import { initMochaGlobals } from '../globals.js'
10
+ import common from 'mocha/lib/interfaces/common.js'
11
+ import container from '../container.js'
9
12
 
10
13
  const setContextTranslation = context => {
11
- const container = require('../container')
12
- const contexts = container.translation().value('contexts')
14
+ // Try global container first, then local container instance
15
+ const containerToUse = global.container || container
16
+ if (!containerToUse) return
17
+
18
+ const translation = containerToUse.translation?.() || containerToUse.translation
19
+ const contexts = translation?.value?.('contexts')
13
20
 
14
21
  if (contexts) {
15
22
  for (const key of Object.keys(contexts)) {
@@ -34,7 +41,7 @@ const setContextTranslation = context => {
34
41
  * @param {Mocha.Suite} suite Root suite.
35
42
  * @ignore
36
43
  */
37
- module.exports = function (suite) {
44
+ export default function (suite) {
38
45
  const suites = [suite]
39
46
  suite.timeout(0)
40
47
  let afterAllHooks
@@ -43,7 +50,7 @@ module.exports = function (suite) {
43
50
  let afterEachHooksAreLoaded
44
51
 
45
52
  suite.on('pre-require', (context, file, mocha) => {
46
- const common = require('mocha/lib/interfaces/common')(suites, context, mocha)
53
+ const cmn = common(suites, context, mocha)
47
54
 
48
55
  const addScenario = function (title, opts = {}, fn) {
49
56
  const suite = suites[0]
@@ -65,8 +72,8 @@ module.exports = function (suite) {
65
72
 
66
73
  // create dispatcher
67
74
 
68
- context.BeforeAll = common.before
69
- context.AfterAll = common.after
75
+ context.BeforeAll = cmn.before
76
+ context.AfterAll = cmn.after
70
77
 
71
78
  context.run = mocha.options.delay && common.runWithSuite(suite)
72
79
  /**
@@ -94,11 +101,11 @@ module.exports = function (suite) {
94
101
 
95
102
  suite.file = file
96
103
  suites.unshift(suite)
97
- suite.beforeEach('codeceptjs.before', () => setup(suite))
98
- afterEachHooks.push(['finalize codeceptjs', () => teardown(suite)])
104
+ suite.beforeEach('codeceptjs.before', setup(suite))
105
+ afterEachHooks.push(['finalize codeceptjs', teardown(suite)])
99
106
 
100
- suite.beforeAll('codeceptjs.beforeSuite', () => suiteSetup(suite))
101
- afterAllHooks.push(['codeceptjs.afterSuite', () => suiteTeardown(suite)])
107
+ suite.beforeAll('codeceptjs.beforeSuite', suiteSetup(suite))
108
+ afterAllHooks.push(['codeceptjs.afterSuite', suiteTeardown(suite)])
102
109
 
103
110
  return new FeatureConfig(suite)
104
111
  }
@@ -208,6 +215,9 @@ module.exports = function (suite) {
208
215
 
209
216
  setContextTranslation(context)
210
217
 
218
+ // Initialize all globals
219
+ initMochaGlobals(context)
220
+
211
221
  addDataContext(context)
212
222
  })
213
223
 
package/lib/output.js CHANGED
@@ -1,6 +1,6 @@
1
- const colors = require('chalk')
2
- const figures = require('figures')
3
- const { maskData, shouldMaskData, getMaskConfig } = require('./utils/mask_data')
1
+ import colors from 'chalk'
2
+ import figures from 'figures'
3
+ import { maskData, shouldMaskData, getMaskConfig } from './utils/mask_data.js'
4
4
 
5
5
  const styles = {
6
6
  error: colors.bgRed.white.bold,
@@ -21,7 +21,7 @@ let newline = true
21
21
  * @alias output
22
22
  * @namespace
23
23
  */
24
- module.exports = {
24
+ const output = {
25
25
  colors,
26
26
  styles,
27
27
  print,
@@ -94,7 +94,7 @@ module.exports = {
94
94
  debug(msg) {
95
95
  const _msg = shouldMaskData() ? maskData(msg, getMaskConfig()) : msg
96
96
  if (outputLevel >= 2) {
97
- print(' '.repeat(this.stepShift), styles.debug(`${figures.pointerSmall} ${_msg}`))
97
+ print(' '.repeat(output.stepShift), styles.debug(`${figures.pointerSmall} ${_msg}`))
98
98
  }
99
99
  },
100
100
 
@@ -105,7 +105,7 @@ module.exports = {
105
105
  log(msg) {
106
106
  const _msg = shouldMaskData() ? maskData(msg, getMaskConfig()) : msg
107
107
  if (outputLevel >= 3) {
108
- print(' '.repeat(this.stepShift), styles.log(truncate(` ${_msg}`, this.spaceShift)))
108
+ print(' '.repeat(output.stepShift), styles.log(truncate(` ${_msg}`, output.stepShift)))
109
109
  }
110
110
  },
111
111
 
@@ -133,7 +133,7 @@ module.exports = {
133
133
  * @param {string} msg
134
134
  */
135
135
  plugin(pluginName, msg = '') {
136
- this.debug(`<${pluginName}> ${msg}`)
136
+ output.debug(`<${pluginName}> ${msg}`)
137
137
  },
138
138
 
139
139
  /**
@@ -153,7 +153,7 @@ module.exports = {
153
153
  let stepLine = step.toCliStyled ? step.toCliStyled() : step.toString()
154
154
  if (step.metaStep && outputLevel >= 1) {
155
155
  // this.stepShift += 2;
156
- stepLine = colors.dim(truncate(stepLine, this.spaceShift))
156
+ stepLine = colors.dim(truncate(stepLine, output.stepShift))
157
157
  }
158
158
  if (step.comment) {
159
159
  stepLine += colors.grey(step.comment.split('\n').join('\n' + ' '.repeat(4)))
@@ -304,6 +304,8 @@ module.exports = {
304
304
  },
305
305
  }
306
306
 
307
+ export default output
308
+
307
309
  function print(...msg) {
308
310
  if (outputProcess) {
309
311
  msg.unshift(outputProcess)
package/lib/parser.js CHANGED
@@ -1,74 +1,74 @@
1
- function _interopDefault(ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex.default : ex; }
2
- const acorn = require('acorn');
3
- const parser = _interopDefault(require('parse-function'))({ parse: acorn.parse, ecmaVersion: 11, plugins: ['objectRestSpread'] });
4
- const { error } = require('./output');
1
+ function _interopDefault(ex) {
2
+ return ex && typeof ex === 'object' && 'default' in ex ? ex.default : ex
3
+ }
4
+ import * as acorn from 'acorn'
5
+ import parseFunctionModule from 'parse-function'
6
+ const parseFunction = _interopDefault(parseFunctionModule)
7
+ const parser = parseFunction({ parse: acorn.parse, ecmaVersion: 11, plugins: ['objectRestSpread'] })
8
+ import output from './output.js'
5
9
 
6
- parser.use(destructuredArgs);
10
+ parser.use(destructuredArgs)
7
11
 
8
- module.exports.getParamsToString = function (fn) {
9
- const newFn = fn.toString().replace(/^async/, 'async function');
10
- return getParams(newFn).join(', ');
11
- };
12
+ export const getParamsToString = function (fn) {
13
+ const newFn = fn.toString().replace(/^async/, 'async function')
14
+ return getParams(newFn).join(', ')
15
+ }
12
16
 
13
17
  function getParams(fn) {
14
- if (fn.isSinonProxy) return [];
18
+ if (fn.isSinonProxy) return []
15
19
  try {
16
- const reflected = parser.parse(fn);
20
+ const reflected = parser.parse(fn)
17
21
  if (reflected.args.length > 1 || reflected.args[0] === 'I') {
18
- error('Error: old CodeceptJS v2 format detected. Upgrade your project to the new format -> https://bit.ly/codecept3Up');
22
+ output.error('Error: old CodeceptJS v2 format detected. Upgrade your project to the new format -> https://bit.ly/codecept3Up')
19
23
  }
20
- if (reflected.destructuredArgs.length > 0) reflected.args = [...reflected.destructuredArgs];
21
- const params = reflected.args.map((p) => {
22
- const def = reflected.defaults[p];
24
+ if (reflected.destructuredArgs.length > 0) reflected.args = [...reflected.destructuredArgs]
25
+ const params = reflected.args.map(p => {
26
+ const def = reflected.defaults[p]
23
27
  if (def) {
24
- return `${p}=${def}`;
28
+ return `${p}=${def}`
25
29
  }
26
- return p;
27
- });
28
- return params;
30
+ return p
31
+ })
32
+ return params
29
33
  } catch (err) {
30
- console.log(`Error in ${fn.toString()}`);
31
- error(err);
34
+ console.log(`Error in ${fn.toString()}`)
35
+ output.error(err)
32
36
  }
33
37
  }
34
38
 
35
- module.exports.getParams = getParams;
39
+ export { getParams }
36
40
 
37
41
  function destructuredArgs() {
38
42
  return (node, result) => {
39
- result.destructuredArgs = result.destructuredArgs || [];
43
+ result.destructuredArgs = result.destructuredArgs || []
40
44
 
41
45
  if (node.type === 'ObjectExpression' && node.properties.length > 0) {
42
- node.properties.forEach((prop) => {
46
+ node.properties.forEach(prop => {
43
47
  if (prop.value && prop.value.params.length > 0) {
44
- result.destructuredArgs = parseDestructuredArgs(prop.value);
48
+ result.destructuredArgs = parseDestructuredArgs(prop.value)
45
49
  }
46
- });
50
+ })
47
51
 
48
- return result;
52
+ return result
49
53
  }
50
54
 
51
- if (!Array.isArray(node.params)) return result;
52
- result.destructuredArgs = parseDestructuredArgs(node);
55
+ if (!Array.isArray(node.params)) return result
56
+ result.destructuredArgs = parseDestructuredArgs(node)
53
57
 
54
- return result;
55
- };
58
+ return result
59
+ }
56
60
  }
57
61
 
58
62
  function parseDestructuredArgs(node) {
59
- const destructuredArgs = [];
60
- node.params.forEach((param) => {
61
- if (
62
- param.type === 'ObjectPattern'
63
- && param.properties
64
- && param.properties.length > 0
65
- ) {
66
- param.properties.forEach((prop) => {
67
- const { name } = prop.value;
68
- destructuredArgs.push(name);
69
- });
63
+ const destructuredArgs = []
64
+ node.params.forEach(param => {
65
+ if (param.type === 'ObjectPattern' && param.properties && param.properties.length > 0) {
66
+ param.properties.forEach(prop => {
67
+ const { name } = prop.value
68
+ destructuredArgs.push(name)
69
+ })
70
70
  }
71
- });
71
+ })
72
72
 
73
- return destructuredArgs;
73
+ return destructuredArgs
74
74
  }
package/lib/pause.js CHANGED
@@ -1,16 +1,16 @@
1
- const colors = require('chalk')
2
- const readline = require('readline')
3
- const ora = require('ora-classic')
4
- const debug = require('debug')('codeceptjs:pause')
5
-
6
- const container = require('./container')
7
- const history = require('./history')
8
- const store = require('./store')
9
- const aiAssistant = require('./ai')
10
- const recorder = require('./recorder')
11
- const event = require('./event')
12
- const output = require('./output')
13
- const { methodsOfObject, searchWithFusejs } = require('./utils')
1
+ import colors from 'chalk'
2
+ import readline from 'readline'
3
+ import ora from 'ora-classic'
4
+ import debugModule from 'debug'
5
+ const debug = debugModule('codeceptjs:pause')
6
+ import container from './container.js'
7
+ import history from './history.js'
8
+ import store from './store.js'
9
+ import aiAssistant from './ai.js'
10
+ import recorder from './recorder.js'
11
+ import event from './event.js'
12
+ import output from './output.js'
13
+ import { methodsOfObject, searchWithFusejs } from './utils.js'
14
14
 
15
15
  // npm install colors
16
16
  let rl
@@ -234,6 +234,5 @@ function registerVariable(name, value) {
234
234
  registeredVariables[name] = value
235
235
  }
236
236
 
237
- module.exports = pause
238
-
239
- module.exports.registerVariable = registerVariable
237
+ export default pause
238
+ export { registerVariable }
@@ -1,14 +1,21 @@
1
- const debug = require('debug')('codeceptjs:analyze')
2
- const { isMainThread } = require('node:worker_threads')
3
- const { arrowRight } = require('figures')
4
- const container = require('../container')
5
- const store = require('../store')
6
- const ai = require('../ai')
7
- const colors = require('chalk')
8
- const ora = require('ora-classic')
9
- const event = require('../event')
10
- const output = require('../output')
11
- const { ansiRegExp, base64EncodeFile, markdownToAnsi } = require('../utils')
1
+ import debugFactory from 'debug'
2
+ const debug = debugFactory('codeceptjs:analyze')
3
+ import { isMainThread } from 'node:worker_threads'
4
+ import figures from 'figures'
5
+ const { arrowRight } = figures
6
+ import Container from '../container.js'
7
+ // Container already imported correctly above
8
+ import store from '../store.js'
9
+
10
+ import aiModule from '../ai.js'
11
+ const ai = aiModule.default || aiModule
12
+ import colors from 'chalk'
13
+ import ora from 'ora'
14
+ import event from '../event.js'
15
+
16
+ import output from '../output.js'
17
+
18
+ import { ansiRegExp, base64EncodeFile, markdownToAnsi } from '../utils.js'
12
19
 
13
20
  const MAX_DATA_LENGTH = 5000
14
21
 
@@ -212,7 +219,7 @@ const defaultConfig = {
212
219
  * @param {Object} config - Plugin configuration
213
220
  * @returns {void}
214
221
  */
215
- module.exports = function (config = {}) {
222
+ export default function (config = {}) {
216
223
  config = Object.assign(defaultConfig, config)
217
224
 
218
225
  event.dispatcher.on(event.workers.before, () => {