codeceptjs 4.0.0-beta.5 → 4.0.0-beta.7.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 +192 -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 +58 -55
  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 +4 -3
  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
@@ -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 => {
@@ -107,7 +116,7 @@ module.exports = (text, file) => {
107
116
  )
108
117
  continue
109
118
  }
110
- if (child.scenario && (currentLanguage ? currentLanguage.contexts.ScenarioOutline === child.scenario.keyword : child.scenario.keyword === 'Scenario Outline')) {
119
+ if (child.scenario && (currentLanguage ? currentLanguage.contexts.ScenarioOutline.includes(child.scenario.keyword) : child.scenario.keyword === 'Scenario Outline')) {
111
120
  for (const examples of child.scenario.examples) {
112
121
  const fields = examples.tableHeader.cells.map(c => c.value)
113
122
  for (const example of examples.tableBody) {
@@ -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 || [])]
@@ -77,12 +78,6 @@ function deserializeTest(test) {
77
78
  test.parent = Object.assign(new Suite(test.parent?.title || 'Suite'), test.parent)
78
79
  enhanceMochaSuite(test.parent)
79
80
  if (test.steps) test.steps = test.steps.map(step => Object.assign(new Step(step.title), step))
80
-
81
- // Restore the custom fullTitle function to maintain consistency with original test
82
- if (test.parent) {
83
- test.fullTitle = () => `${test.parent.title}: ${test.title}`
84
- }
85
-
86
81
  return test
87
82
  }
88
83
 
@@ -171,7 +166,9 @@ function testToFileName(test, { suffix = '', unique = false } = {}) {
171
166
  return fileName
172
167
  }
173
168
 
174
- module.exports = {
169
+ export { createTest, testToFileName, enhanceMochaTest, serializeTest, deserializeTest, cloneTest }
170
+
171
+ export default {
175
172
  createTest,
176
173
  testToFileName,
177
174
  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,28 +101,15 @@ 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
  }
105
112
 
106
- /**
107
- * Exclusive test suite - runs only this feature.
108
- * @global
109
- * @kind constant
110
- * @type {CodeceptJS.IFeature}
111
- */
112
- context.Feature.only = function (title, opts) {
113
- const reString = `^${escapeRe(`${title}:`)}`
114
- mocha.grep(new RegExp(reString))
115
- process.env.FEATURE_ONLY = true
116
- return context.Feature(title, opts)
117
- }
118
-
119
113
  /**
120
114
  * Pending test suite.
121
115
  * @global
@@ -208,6 +202,9 @@ module.exports = function (suite) {
208
202
 
209
203
  setContextTranslation(context)
210
204
 
205
+ // Initialize all globals
206
+ initMochaGlobals(context)
207
+
211
208
  addDataContext(context)
212
209
  })
213
210
 
package/lib/output.js CHANGED
@@ -1,6 +1,6 @@
1
- const colors = require('chalk')
2
- const figures = require('figures')
3
- const { maskSensitiveData } = require('invisi-data')
1
+ import colors from 'chalk'
2
+ import figures from 'figures'
3
+ import { maskSensitiveData } from 'invisi-data'
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,
@@ -61,7 +61,7 @@ module.exports = {
61
61
  debug(msg) {
62
62
  const _msg = isMaskedData() ? maskSensitiveData(msg) : msg
63
63
  if (outputLevel >= 2) {
64
- print(' '.repeat(this.stepShift), styles.debug(`${figures.pointerSmall} ${_msg}`))
64
+ print(' '.repeat(output.stepShift), styles.debug(`${figures.pointerSmall} ${_msg}`))
65
65
  }
66
66
  },
67
67
 
@@ -72,7 +72,7 @@ module.exports = {
72
72
  log(msg) {
73
73
  const _msg = isMaskedData() ? maskSensitiveData(msg) : msg
74
74
  if (outputLevel >= 3) {
75
- print(' '.repeat(this.stepShift), styles.log(truncate(` ${_msg}`, this.spaceShift)))
75
+ print(' '.repeat(output.stepShift), styles.log(truncate(` ${_msg}`, output.stepShift)))
76
76
  }
77
77
  },
78
78
 
@@ -98,7 +98,7 @@ module.exports = {
98
98
  * @param {string} msg
99
99
  */
100
100
  plugin(pluginName, msg = '') {
101
- this.debug(`<${pluginName}> ${msg}`)
101
+ output.debug(`<${pluginName}> ${msg}`)
102
102
  },
103
103
 
104
104
  /**
@@ -118,14 +118,14 @@ module.exports = {
118
118
  let stepLine = step.toCliStyled ? step.toCliStyled() : step.toString()
119
119
  if (step.metaStep && outputLevel >= 1) {
120
120
  // this.stepShift += 2;
121
- stepLine = colors.dim(truncate(stepLine, this.spaceShift))
121
+ stepLine = colors.dim(truncate(stepLine, output.stepShift))
122
122
  }
123
123
  if (step.comment) {
124
124
  stepLine += colors.grey(step.comment.split('\n').join('\n' + ' '.repeat(4)))
125
125
  }
126
126
 
127
127
  const _stepLine = isMaskedData() ? maskSensitiveData(stepLine) : stepLine
128
- print(' '.repeat(this.stepShift), truncate(_stepLine, this.spaceShift))
128
+ print(' '.repeat(output.stepShift), truncate(_stepLine, output.stepShift))
129
129
  },
130
130
 
131
131
  /** @namespace */
@@ -282,3 +282,5 @@ function truncate(msg, gap = 0) {
282
282
  function isMaskedData() {
283
283
  return global.maskSensitiveData === true || false
284
284
  }
285
+
286
+ export default output
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 }