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,12 +1,12 @@
1
- const colors = require('chalk')
2
- const fs = require('fs')
3
- const inquirer = require('inquirer')
4
- const mkdirp = require('mkdirp')
5
- const path = require('path')
6
- const { fileExists, ucfirst, lcfirst, beautify } = require('../utils')
7
- const output = require('../output')
8
- const generateDefinitions = require('./definitions')
9
- const { getConfig, getTestRoot, safeFileWrite, readConfig } = require('./utils')
1
+ import colors from 'chalk'
2
+ import fs from 'fs'
3
+ import inquirer from 'inquirer'
4
+ import { mkdirp } from 'mkdirp'
5
+ import path from 'path'
6
+ import { fileExists, ucfirst, lcfirst, beautify } from '../utils.js'
7
+ import output from '../output.js'
8
+ import generateDefinitions from './definitions.js'
9
+ import { getConfig, getTestRoot, safeFileWrite, readConfig } from './utils.js'
10
10
 
11
11
  let extension = 'js'
12
12
 
@@ -18,10 +18,10 @@ Scenario('test something', async ({ {{actor}} }) => {
18
18
  `
19
19
 
20
20
  // generates empty test
21
- module.exports.test = function (genPath) {
21
+ export async function test(genPath) {
22
22
  const testsPath = getTestRoot(genPath)
23
23
  global.codecept_dir = testsPath
24
- const config = getConfig(testsPath)
24
+ const config = await getConfig(testsPath)
25
25
  if (!config) return
26
26
 
27
27
  output.print('Creating a new test...')
@@ -46,7 +46,7 @@ module.exports.test = function (genPath) {
46
46
  },
47
47
  },
48
48
  ])
49
- .then(result => {
49
+ .then(async result => {
50
50
  const testFilePath = path.dirname(path.join(testsPath, config.tests)).replace(/\*\*$/, '')
51
51
  let testFile = path.join(testFilePath, result.filename)
52
52
  const ext = path.extname(testFile)
@@ -55,8 +55,9 @@ module.exports.test = function (genPath) {
55
55
  if (!fileExists(dir)) mkdirp.sync(dir)
56
56
  let testContent = testTemplate.replace('{{feature}}', result.feature)
57
57
 
58
- const container = require('../container')
59
- container.create(config, {})
58
+ const containerModule = await import('../container.js')
59
+ const container = containerModule.default || containerModule
60
+ await container.create(config, {})
60
61
  // translate scenario test
61
62
  if (container.translation().loaded) {
62
63
  const vocabulary = container.translation().vocabulary
@@ -76,7 +77,7 @@ module.exports.test = function (genPath) {
76
77
 
77
78
  const pageObjectTemplate = `const { I } = inject();
78
79
 
79
- module.exports = {
80
+ export default {
80
81
 
81
82
  // insert your locators and methods here
82
83
  }
@@ -101,13 +102,13 @@ class {{name}} {
101
102
  }
102
103
 
103
104
  // For inheritance
104
- module.exports = new {{name}}();
105
- export = {{name}};
105
+ export default new {{name}}();
106
+ export { {{name}} };
106
107
  `
107
108
 
108
- module.exports.pageObject = function (genPath, opts) {
109
+ export async function pageObject(genPath, opts) {
109
110
  const testsPath = getTestRoot(genPath)
110
- const config = getConfig(testsPath)
111
+ const config = await getConfig(testsPath)
111
112
  const kind = opts.T || 'page'
112
113
  if (!config) return
113
114
 
@@ -155,7 +156,7 @@ module.exports.pageObject = function (genPath, opts) {
155
156
  // relative path
156
157
  actorPath = path.relative(dir, path.dirname(path.join(testsPath, actorPath))) + actorPath.substring(1) // get an upper level
157
158
  }
158
- actor = `require('${actorPath}')`
159
+ actor = `import('${actorPath}')`
159
160
  }
160
161
 
161
162
  const name = lcfirst(result.name) + ucfirst(kind)
@@ -197,7 +198,7 @@ module.exports.pageObject = function (genPath, opts) {
197
198
  })
198
199
  }
199
200
 
200
- const helperTemplate = `const Helper = require('@codeceptjs/helper');
201
+ const helperTemplate = `import Helper from '@codeceptjs/helper';
201
202
 
202
203
  class {{name}} extends Helper {
203
204
 
@@ -222,10 +223,10 @@ class {{name}} extends Helper {
222
223
 
223
224
  }
224
225
 
225
- module.exports = {{name}};
226
+ export default {{name}};
226
227
  `
227
228
 
228
- module.exports.helper = function (genPath) {
229
+ export async function helper(genPath) {
229
230
  const testsPath = getTestRoot(genPath)
230
231
 
231
232
  output.print('Creating a new helper')
@@ -265,9 +266,11 @@ helpers: {
265
266
  })
266
267
  }
267
268
 
269
+ import { fileURLToPath } from 'url'
270
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
268
271
  const healTemplate = fs.readFileSync(path.join(__dirname, '../template/heal.js'), 'utf8').toString()
269
272
 
270
- module.exports.heal = function (genPath) {
273
+ export async function heal(genPath) {
271
274
  const testsPath = getTestRoot(genPath)
272
275
 
273
276
  let configFile = path.join(testsPath, `codecept.conf.${extension}`)
@@ -282,9 +285,9 @@ module.exports.heal = function (genPath) {
282
285
  output.print('Require this file in the config file and enable heal plugin:')
283
286
  output.print('--------------------------')
284
287
  output.print(`
285
- require('./heal')
288
+ import './heal.js'
286
289
 
287
- exports.config = {
290
+ export const config = {
288
291
  // ...
289
292
  plugins: {
290
293
  heal: {
@@ -1,11 +1,9 @@
1
- const path = require('path');
2
- const mkdirp = require('mkdirp');
1
+ import path from 'path'
2
+ import { mkdirp } from 'mkdirp'
3
3
 
4
- const output = require('../../output');
5
- const { fileExists } = require('../../utils');
6
- const {
7
- getConfig, getTestRoot, updateConfig, safeFileWrite, findConfigFile,
8
- } = require('../utils');
4
+ import output from '../../output.js'
5
+ import { fileExists } from '../../utils.js'
6
+ import { getConfig, getTestRoot, updateConfig, safeFileWrite, findConfigFile } from '../utils.js'
9
7
 
10
8
  const featureFile = `Feature: Business rules
11
9
  In order to achieve my goals
@@ -14,7 +12,7 @@ const featureFile = `Feature: Business rules
14
12
 
15
13
  Scenario: do something
16
14
  Given I have a defined step
17
- `;
15
+ `
18
16
 
19
17
  const stepsFile = `const { I } = inject();
20
18
  // Add in your custom step files
@@ -22,60 +20,60 @@ const stepsFile = `const { I } = inject();
22
20
  Given('I have a defined step', () => {
23
21
  // TODO: replace with your own step
24
22
  });
25
- `;
23
+ `
26
24
 
27
- module.exports = function (genPath) {
28
- const testsPath = getTestRoot(genPath);
29
- const configFile = findConfigFile(testsPath);
25
+ export default async function (genPath) {
26
+ const testsPath = getTestRoot(genPath)
27
+ const configFile = findConfigFile(testsPath)
30
28
 
31
29
  if (!configFile) {
32
- output.error(
33
- "Can't initialize Gherkin. This command must be run in an already initialized project.",
34
- );
35
- process.exit(1);
30
+ output.error("Can't initialize Gherkin. This command must be run in an already initialized project.")
31
+ process.exit(1)
36
32
  }
37
33
 
38
- const config = getConfig(testsPath);
39
- const extension = path.extname(configFile).substring(1);
34
+ const config = await getConfig(testsPath)
35
+ const extension = path.extname(configFile).substring(1)
40
36
 
41
- output.print('Initializing Gherkin (Cucumber BDD) for CodeceptJS');
42
- output.print('--------------------------');
37
+ output.print('Initializing Gherkin (Cucumber BDD) for CodeceptJS')
38
+ output.print('--------------------------')
43
39
 
44
40
  if (config.gherkin && config.gherkin.steps) {
45
- output.error('Gherkin is already initialized in this project. See `gherkin` section in the config');
46
- process.exit(1);
41
+ output.error('Gherkin is already initialized in this project. See `gherkin` section in the config')
42
+ process.exit(1)
47
43
  }
48
44
 
49
- let dir;
50
- dir = path.join(testsPath, 'features');
45
+ let dir
46
+ dir = path.join(testsPath, 'features')
51
47
  if (!fileExists(dir)) {
52
- mkdirp.sync(dir);
53
- output.success(`Created ${dir}, place your *.feature files in it`);
48
+ mkdirp.sync(dir)
49
+ // Use relative path for output
50
+ const relativeDir = path.relative(process.cwd(), dir)
51
+ output.success(`Created ${relativeDir}, place your *.feature files in it`)
54
52
  }
55
53
 
56
54
  if (safeFileWrite(path.join(dir, 'basic.feature'), featureFile)) {
57
- output.success('Created sample feature file: features/basic.feature');
55
+ output.success('Created sample feature file: features/basic.feature')
58
56
  }
59
57
 
60
- dir = path.join(testsPath, 'step_definitions');
58
+ dir = path.join(testsPath, 'step_definitions')
61
59
  if (!fileExists(dir)) {
62
- mkdirp.sync(dir);
63
- output.success(`Created ${dir}, place step definitions into it`);
60
+ mkdirp.sync(dir)
61
+ // Use relative path for output
62
+ const relativeDir = path.relative(process.cwd(), dir)
63
+ output.success(`Created ${relativeDir}, place step definitions into it`)
64
64
  }
65
65
 
66
66
  if (safeFileWrite(path.join(dir, `steps.${extension}`), stepsFile)) {
67
- output.success(
68
- `Created sample steps file: step_definitions/steps.${extension}`,
69
- );
67
+ output.success(`Created sample steps file: step_definitions/steps.${extension}`)
70
68
  }
71
69
 
72
70
  config.gherkin = {
73
71
  features: './features/*.feature',
74
72
  steps: [`./step_definitions/steps.${extension}`],
75
- };
73
+ }
76
74
 
77
- updateConfig(testsPath, config, extension);
75
+ updateConfig(testsPath, config, extension)
78
76
 
79
- output.success('Gherkin setup is done.');
80
- output.success('Start writing feature files and implement corresponding steps.');
81
- };
77
+ output.success('Gherkin setup is done.')
78
+ output.success('Start writing feature files and implement corresponding steps.')
79
+ }
@@ -1,29 +1,29 @@
1
- const escapeStringRegexp = require('escape-string-regexp')
2
- const fs = require('fs')
3
- const Gherkin = require('@cucumber/gherkin')
4
- const Messages = require('@cucumber/messages')
5
- const { globSync } = require('glob')
6
- const fsPath = require('path')
1
+ import escapeStringRegexp from 'escape-string-regexp'
2
+ import fs from 'fs'
3
+ import Gherkin from '@cucumber/gherkin'
4
+ import { IdGenerator } from '@cucumber/messages'
5
+ import { globSync } from 'glob'
6
+ import fsPath from 'path'
7
7
 
8
- const { getConfig, getTestRoot } = require('../utils')
9
- const Codecept = require('../../codecept')
10
- const output = require('../../output')
11
- const { matchStep } = require('../../mocha/bdd')
8
+ import { getConfig, getTestRoot } from '../utils.js'
9
+ import Codecept from '../../codecept.js'
10
+ import output from '../../output.js'
11
+ import { matchStep } from '../../mocha/bdd.js'
12
12
 
13
- const uuidFn = Messages.IdGenerator.uuid()
13
+ const uuidFn = IdGenerator.uuid()
14
14
  const builder = new Gherkin.AstBuilder(uuidFn)
15
15
  const matcher = new Gherkin.GherkinClassicTokenMatcher()
16
16
  const parser = new Gherkin.Parser(builder, matcher)
17
17
  parser.stopAtFirstError = false
18
18
 
19
- module.exports = function (genPath, options) {
19
+ export default async function (genPath, options) {
20
20
  const configFile = options.config || genPath
21
21
  const testsPath = getTestRoot(configFile)
22
- const config = getConfig(configFile)
22
+ const config = await getConfig(configFile)
23
23
  if (!config) return
24
24
 
25
25
  const codecept = new Codecept(config, {})
26
- codecept.init(testsPath)
26
+ await codecept.init(testsPath)
27
27
 
28
28
  if (!config.gherkin) {
29
29
  output.error('Gherkin is not enabled in config. Run `codecept gherkin:init` to enable it')
@@ -1,25 +1,28 @@
1
- const { getConfig, getTestRoot } = require('../utils');
2
- const Codecept = require('../../codecept');
3
- const output = require('../../output');
4
- const { getSteps } = require('../../mocha/bdd');
1
+ import { getConfig, getTestRoot } from '../utils.js'
2
+ import Codecept from '../../codecept.js'
3
+ import output from '../../output.js'
4
+ import { getSteps, clearSteps } from '../../mocha/bdd.js'
5
5
 
6
- module.exports = function (genPath, options) {
7
- const configFile = options.config || genPath;
8
- const testsPath = getTestRoot(configFile);
9
- const config = getConfig(configFile);
10
- if (!config) return;
6
+ export default async function (genPath, options) {
7
+ const configFile = options.config || genPath
8
+ const testsPath = getTestRoot(configFile)
9
+ const config = await getConfig(configFile)
10
+ if (!config) return
11
11
 
12
- const codecept = new Codecept(config, {});
13
- codecept.init(testsPath);
12
+ // Clear any previously loaded steps
13
+ clearSteps()
14
+
15
+ const codecept = new Codecept(config, {})
16
+ await codecept.init(testsPath)
14
17
 
15
- output.print('Gherkin Step Definitions:');
16
- output.print();
17
- const steps = getSteps();
18
+ output.print('Gherkin Step Definitions:')
19
+ output.print()
20
+ const steps = getSteps()
18
21
  for (const step of Object.keys(steps)) {
19
- output.print(` ${output.colors.bold(step)} ${output.colors.green(steps[step].line || '')}`);
22
+ output.print(` ${output.colors.bold(step)} ${output.colors.green(steps[step].line || '')}`)
20
23
  }
21
- output.print();
24
+ output.print()
22
25
  if (!Object.keys(steps).length) {
23
- output.error('No Gherkin steps defined');
26
+ output.error('No Gherkin steps defined')
24
27
  }
25
- };
28
+ }
@@ -1,9 +1,9 @@
1
- const envinfo = require('envinfo')
1
+ import envinfo from 'envinfo'
2
2
 
3
- const { getConfig, getTestRoot } = require('./utils')
4
- const Codecept = require('../codecept')
5
- const output = require('../output')
6
- const { execSync } = require('child_process')
3
+ import { getConfig, getTestRoot } from './utils.js'
4
+ import Codecept from '../codecept.js'
5
+ import output from '../output.js'
6
+ import { execSync } from 'child_process'
7
7
 
8
8
  async function getPlaywrightBrowsers() {
9
9
  try {
@@ -40,9 +40,9 @@ async function getOsBrowsers() {
40
40
  ].join(', ')
41
41
  }
42
42
 
43
- module.exports = async function (path) {
43
+ export default async function (path) {
44
44
  const testsPath = getTestRoot(path)
45
- const config = getConfig(testsPath)
45
+ const config = await getConfig(testsPath)
46
46
  const codecept = new Codecept(config, {})
47
47
  codecept.init(testsPath)
48
48
 
@@ -73,7 +73,7 @@ module.exports = async function (path) {
73
73
  output.print('***************************************')
74
74
  }
75
75
 
76
- module.exports.getMachineInfo = async () => {
76
+ export const getMachineInfo = async () => {
77
77
  const info = {
78
78
  nodeInfo: await envinfo.helpers.getNodeInfo(),
79
79
  osInfo: await envinfo.helpers.getOSInfo(),
@@ -1,35 +1,35 @@
1
- const colors = require('chalk')
2
- const fs = require('fs')
3
- const inquirer = require('inquirer')
4
- const mkdirp = require('mkdirp')
5
- const path = require('path')
6
- const { inspect } = require('util')
7
- const spawn = require('cross-spawn')
8
-
9
- const { print, success, error } = require('../output')
10
- const { fileExists, beautify, installedLocally } = require('../utils')
11
- const { getTestRoot } = require('./utils')
12
- const generateDefinitions = require('./definitions')
13
- const { test: generateTest } = require('./generate')
14
- const isLocal = require('../utils').installedLocally()
1
+ import colors from 'chalk'
2
+ import fs from 'fs'
3
+ import inquirer from 'inquirer'
4
+ import { mkdirp } from 'mkdirp'
5
+ import path from 'path'
6
+ import { inspect } from 'util'
7
+ import spawn from 'cross-spawn'
8
+
9
+ import output from '../output.js'
10
+ const { print, success, error } = output
11
+ import { fileExists, beautify, installedLocally } from '../utils.js'
12
+ import { getTestRoot } from './utils.js'
13
+ import generateDefinitions from './definitions.js'
14
+ import { test as generateTest } from './generate.js'
15
+ const isLocal = installedLocally()
15
16
 
16
17
  const defaultConfig = {
17
18
  tests: './*_test.js',
18
19
  output: '',
19
20
  helpers: {},
20
21
  include: {},
21
- plugins: {
22
- htmlReporter: {
23
- enabled: true,
24
- },
25
- },
26
22
  }
27
23
 
28
- const helpers = ['Playwright', 'WebDriver', 'Puppeteer', 'REST', 'GraphQL', 'Appium', 'TestCafe']
29
- const translations = Object.keys(require('../../translations'))
30
-
24
+ const helpers = ['Playwright', 'WebDriver', 'Puppeteer', 'REST', 'GraphQL', 'Appium']
31
25
  const noTranslation = 'English (no localization)'
32
- translations.unshift(noTranslation)
26
+
27
+ async function getTranslations() {
28
+ const translationsModule = await import('../../translations/index.js')
29
+ const translations = Object.keys(translationsModule.default || translationsModule)
30
+ translations.unshift(noTranslation)
31
+ return translations
32
+ }
33
33
 
34
34
  const packages = []
35
35
  let isTypeScript = false
@@ -50,7 +50,7 @@ setCommonPlugins();
50
50
 
51
51
  const defaultActor = `// in this file you can append custom step methods to 'I' object
52
52
 
53
- module.exports = function() {
53
+ export default function() {
54
54
  return actor({
55
55
 
56
56
  // Define custom steps here, use 'this' to access default methods of I.
@@ -72,8 +72,9 @@ export = function() {
72
72
  }
73
73
  `
74
74
 
75
- module.exports = function (initPath) {
75
+ export default async function (initPath) {
76
76
  const testsPath = getTestRoot(initPath)
77
+ const translations = await getTranslations()
77
78
 
78
79
  print()
79
80
  print(` Welcome to ${colors.magenta.bold('CodeceptJS')} initialization tool`)
@@ -151,7 +152,7 @@ module.exports = function (initPath) {
151
152
  choices: translations,
152
153
  },
153
154
  ])
154
- .then(result => {
155
+ .then(async result => {
155
156
  if (result.typescript === true) {
156
157
  isTypeScript = true
157
158
  extension = isTypeScript === true ? 'ts' : 'js'
@@ -187,7 +188,8 @@ module.exports = function (initPath) {
187
188
  let helperConfigs = []
188
189
 
189
190
  try {
190
- const Helper = require(`../helper/${helperName}`)
191
+ const HelperModule = await import(`../helper/${helperName}.js`)
192
+ const Helper = HelperModule.default || HelperModule
191
193
  if (Helper._checkRequirements) {
192
194
  packages.concat(Helper._checkRequirements())
193
195
  }
@@ -212,9 +214,9 @@ module.exports = function (initPath) {
212
214
  fs.writeFileSync(path.join(testsPath, stepFile), extension === 'ts' ? defaultActorTs : defaultActor)
213
215
 
214
216
  if (isTypeScript) {
215
- config.include = _actorTranslation('./steps_file', config.translation)
217
+ config.include = await _actorTranslation('./steps_file', config.translation, translations)
216
218
  } else {
217
- config.include = _actorTranslation(stepFile, config.translation)
219
+ config.include = await _actorTranslation(stepFile, config.translation, translations)
218
220
  }
219
221
 
220
222
  print(`Steps file created at ${stepFile}`)
@@ -395,7 +397,7 @@ function install(dependencies) {
395
397
  return true
396
398
  }
397
399
 
398
- function _actorTranslation(stepFile, translationSelected) {
400
+ async function _actorTranslation(stepFile, translationSelected, translations) {
399
401
  let actor
400
402
 
401
403
  for (const translationAvailable of translations) {
@@ -404,7 +406,8 @@ function _actorTranslation(stepFile, translationSelected) {
404
406
  }
405
407
 
406
408
  if (translationSelected === translationAvailable) {
407
- const nameOfActor = require('../../translations')[translationAvailable].I
409
+ const translationsModule = await import('../../translations/index.js')
410
+ const nameOfActor = (translationsModule.default || translationsModule)[translationAvailable].I
408
411
 
409
412
  actor = {
410
413
  [nameOfActor]: stepFile,
@@ -1,18 +1,19 @@
1
- const { getConfig, getTestRoot } = require('./utils')
2
- const recorder = require('../recorder')
3
- const Codecept = require('../codecept')
4
- const Container = require('../container')
5
- const event = require('../event')
6
- const output = require('../output')
1
+ import { getConfig, getTestRoot } from './utils.js'
2
+ import recorder from '../recorder.js'
3
+ import Codecept from '../codecept.js'
4
+ import Container from '../container.js'
5
+ import event from '../event.js'
6
+ import pause from '../pause.js'
7
+ import output from '../output.js'
7
8
  const webHelpers = Container.STANDARD_ACTING_HELPERS
8
9
 
9
- module.exports = async function (path, options) {
10
+ export default async function (path, options) {
10
11
  // Backward compatibility for --profile
11
12
  process.profile = options.profile
12
13
  process.env.profile = options.profile
13
14
  const configFile = options.config
14
15
 
15
- const config = getConfig(configFile)
16
+ const config = await getConfig(configFile)
16
17
  const testsPath = getTestRoot(configFile)
17
18
 
18
19
  const codecept = new Codecept(config, options)
@@ -20,6 +21,7 @@ module.exports = async function (path, options) {
20
21
 
21
22
  try {
22
23
  await codecept.bootstrap()
24
+ await Container.started()
23
25
 
24
26
  if (options.verbose) output.level(3)
25
27
 
@@ -51,8 +53,7 @@ module.exports = async function (path, options) {
51
53
  break
52
54
  }
53
55
  }
54
- require('../pause')()
55
- // recorder.catchWithoutStop((err) => console.log(err.stack));
56
+ pause()
56
57
  recorder.add(() => event.emit(event.test.after, {}))
57
58
  recorder.add(() => event.emit(event.suite.after, {}))
58
59
  recorder.add(() => event.emit(event.all.result, {}))
@@ -1,15 +1,16 @@
1
- const { getConfig, getTestRoot } = require('./utils')
2
- const Codecept = require('../codecept')
3
- const container = require('../container')
4
- const { getParamsToString } = require('../parser')
5
- const { methodsOfObject } = require('../utils')
6
- const output = require('../output')
1
+ import { getConfig, getTestRoot } from './utils.js'
2
+ import Codecept from '../codecept.js'
3
+ import container from '../container.js'
4
+ import { getParamsToString } from '../parser.js'
5
+ import { methodsOfObject } from '../utils.js'
6
+ import output from '../output.js'
7
7
 
8
- module.exports = function (path) {
8
+ export default async function (path) {
9
9
  const testsPath = getTestRoot(path)
10
- const config = getConfig(testsPath)
10
+ const config = await getConfig(testsPath)
11
11
  const codecept = new Codecept(config, {})
12
- codecept.init(testsPath)
12
+ await codecept.init(testsPath)
13
+ await container.started()
13
14
 
14
15
  output.print('List of test actions: -- ')
15
16
  const helpers = container.helpers()
@@ -1,6 +1,6 @@
1
- const { globSync } = require('glob')
2
- const path = require('path')
3
- const fs = require('fs')
1
+ import { globSync } from 'glob'
2
+ import path from 'path'
3
+ import fs from 'fs'
4
4
 
5
5
  /**
6
6
  * Splits a list to (n) parts, defined via the size argument.
@@ -89,6 +89,6 @@ const createChunks = (config, patterns = []) => {
89
89
  })
90
90
  }
91
91
 
92
- module.exports = {
93
- createChunks,
92
+ export {
93
+ createChunks
94
94
  }
@@ -1,5 +1,5 @@
1
- const { createChunks } = require('./chunk');
2
- const { createRun } = require('./run');
1
+ import { createChunks } from './chunk.js'
2
+ import { createRun } from './run.js'
3
3
 
4
4
  /**
5
5
  * Bootstraps a collection of runs, it combines user defined selection of runs
@@ -190,6 +190,6 @@ function guessBrowser(config) {
190
190
  return [config.helpers[firstHelper].browser];
191
191
  }
192
192
 
193
- module.exports = {
194
- createRuns,
195
- };
193
+ export {
194
+ createRuns
195
+ }
@@ -25,6 +25,6 @@ const createRun = (name, config) => {
25
25
  return new Run(name, config);
26
26
  };
27
27
 
28
- module.exports = {
29
- createRun,
30
- };
28
+ export {
29
+ createRun
30
+ }