codeceptjs 4.0.0-beta.4 → 4.0.0-beta.6.esm-aria

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/README.md +89 -119
  2. package/bin/codecept.js +53 -54
  3. package/docs/webapi/clearCookie.mustache +1 -1
  4. package/lib/actor.js +70 -102
  5. package/lib/ai.js +131 -121
  6. package/lib/assert/empty.js +11 -12
  7. package/lib/assert/equal.js +16 -21
  8. package/lib/assert/error.js +2 -2
  9. package/lib/assert/include.js +11 -15
  10. package/lib/assert/throws.js +3 -5
  11. package/lib/assert/truth.js +10 -7
  12. package/lib/assert.js +18 -18
  13. package/lib/codecept.js +112 -101
  14. package/lib/colorUtils.js +48 -50
  15. package/lib/command/check.js +206 -0
  16. package/lib/command/configMigrate.js +13 -14
  17. package/lib/command/definitions.js +24 -36
  18. package/lib/command/dryRun.js +16 -16
  19. package/lib/command/generate.js +38 -39
  20. package/lib/command/gherkin/init.js +36 -38
  21. package/lib/command/gherkin/snippets.js +76 -74
  22. package/lib/command/gherkin/steps.js +21 -18
  23. package/lib/command/info.js +49 -15
  24. package/lib/command/init.js +41 -37
  25. package/lib/command/interactive.js +22 -13
  26. package/lib/command/list.js +11 -10
  27. package/lib/command/run-multiple/chunk.js +50 -47
  28. package/lib/command/run-multiple/collection.js +5 -5
  29. package/lib/command/run-multiple/run.js +3 -3
  30. package/lib/command/run-multiple.js +27 -47
  31. package/lib/command/run-rerun.js +6 -7
  32. package/lib/command/run-workers.js +15 -66
  33. package/lib/command/run.js +8 -8
  34. package/lib/command/utils.js +22 -21
  35. package/lib/command/workers/runTests.js +131 -241
  36. package/lib/config.js +111 -49
  37. package/lib/container.js +589 -244
  38. package/lib/data/context.js +16 -18
  39. package/lib/data/dataScenarioConfig.js +9 -9
  40. package/lib/data/dataTableArgument.js +7 -7
  41. package/lib/data/table.js +6 -12
  42. package/lib/effects.js +307 -0
  43. package/lib/els.js +160 -0
  44. package/lib/event.js +24 -19
  45. package/lib/globals.js +141 -0
  46. package/lib/heal.js +89 -81
  47. package/lib/helper/AI.js +3 -2
  48. package/lib/helper/ApiDataFactory.js +19 -19
  49. package/lib/helper/Appium.js +47 -51
  50. package/lib/helper/FileSystem.js +35 -15
  51. package/lib/helper/GraphQL.js +1 -1
  52. package/lib/helper/GraphQLDataFactory.js +4 -4
  53. package/lib/helper/JSONResponse.js +72 -45
  54. package/lib/helper/Mochawesome.js +14 -11
  55. package/lib/helper/Playwright.js +832 -434
  56. package/lib/helper/Puppeteer.js +393 -292
  57. package/lib/helper/REST.js +32 -27
  58. package/lib/helper/WebDriver.js +320 -219
  59. package/lib/helper/errors/ConnectionRefused.js +6 -6
  60. package/lib/helper/errors/ElementAssertion.js +11 -16
  61. package/lib/helper/errors/ElementNotFound.js +5 -9
  62. package/lib/helper/errors/RemoteBrowserConnectionRefused.js +5 -5
  63. package/lib/helper/extras/Console.js +11 -11
  64. package/lib/helper/extras/PlaywrightLocator.js +110 -0
  65. package/lib/helper/extras/PlaywrightPropEngine.js +18 -18
  66. package/lib/helper/extras/PlaywrightRestartOpts.js +23 -23
  67. package/lib/helper/extras/Popup.js +22 -22
  68. package/lib/helper/extras/React.js +29 -30
  69. package/lib/helper/network/actions.js +33 -48
  70. package/lib/helper/network/utils.js +76 -83
  71. package/lib/helper/scripts/blurElement.js +6 -6
  72. package/lib/helper/scripts/focusElement.js +6 -6
  73. package/lib/helper/scripts/highlightElement.js +9 -9
  74. package/lib/helper/scripts/isElementClickable.js +34 -34
  75. package/lib/helper.js +2 -1
  76. package/lib/history.js +23 -20
  77. package/lib/hooks.js +10 -10
  78. package/lib/html.js +90 -100
  79. package/lib/index.js +48 -21
  80. package/lib/listener/config.js +8 -9
  81. package/lib/listener/emptyRun.js +54 -0
  82. package/lib/listener/exit.js +10 -12
  83. package/lib/listener/{retry.js → globalRetry.js} +10 -10
  84. package/lib/listener/globalTimeout.js +166 -0
  85. package/lib/listener/helpers.js +43 -24
  86. package/lib/listener/mocha.js +4 -5
  87. package/lib/listener/result.js +11 -0
  88. package/lib/listener/steps.js +26 -23
  89. package/lib/listener/store.js +20 -0
  90. package/lib/locator.js +213 -192
  91. package/lib/mocha/asyncWrapper.js +264 -0
  92. package/lib/mocha/bdd.js +167 -0
  93. package/lib/mocha/cli.js +341 -0
  94. package/lib/mocha/factory.js +160 -0
  95. package/lib/{interfaces → mocha}/featureConfig.js +33 -13
  96. package/lib/{interfaces → mocha}/gherkin.js +75 -45
  97. package/lib/mocha/hooks.js +121 -0
  98. package/lib/mocha/index.js +21 -0
  99. package/lib/mocha/inject.js +46 -0
  100. package/lib/{interfaces → mocha}/scenarioConfig.js +32 -8
  101. package/lib/mocha/suite.js +89 -0
  102. package/lib/mocha/test.js +178 -0
  103. package/lib/mocha/types.d.ts +42 -0
  104. package/lib/mocha/ui.js +229 -0
  105. package/lib/output.js +86 -64
  106. package/lib/parser.js +44 -44
  107. package/lib/pause.js +160 -139
  108. package/lib/plugin/analyze.js +403 -0
  109. package/lib/plugin/{autoLogin.js → auth.js} +137 -43
  110. package/lib/plugin/autoDelay.js +19 -15
  111. package/lib/plugin/coverage.js +22 -27
  112. package/lib/plugin/customLocator.js +5 -5
  113. package/lib/plugin/customReporter.js +53 -0
  114. package/lib/plugin/heal.js +49 -17
  115. package/lib/plugin/pageInfo.js +140 -0
  116. package/lib/plugin/pauseOnFail.js +4 -3
  117. package/lib/plugin/retryFailedStep.js +60 -19
  118. package/lib/plugin/screenshotOnFail.js +80 -83
  119. package/lib/plugin/stepByStepReport.js +70 -31
  120. package/lib/plugin/stepTimeout.js +7 -13
  121. package/lib/plugin/subtitles.js +10 -9
  122. package/lib/recorder.js +167 -126
  123. package/lib/rerun.js +94 -50
  124. package/lib/result.js +161 -0
  125. package/lib/secret.js +18 -17
  126. package/lib/session.js +95 -89
  127. package/lib/step/base.js +239 -0
  128. package/lib/step/comment.js +10 -0
  129. package/lib/step/config.js +50 -0
  130. package/lib/step/func.js +46 -0
  131. package/lib/step/helper.js +50 -0
  132. package/lib/step/meta.js +99 -0
  133. package/lib/step/record.js +74 -0
  134. package/lib/step/retry.js +11 -0
  135. package/lib/step/section.js +55 -0
  136. package/lib/step.js +18 -332
  137. package/lib/steps.js +54 -0
  138. package/lib/store.js +37 -5
  139. package/lib/template/heal.js +2 -11
  140. package/lib/timeout.js +60 -0
  141. package/lib/transform.js +8 -8
  142. package/lib/translation.js +32 -18
  143. package/lib/utils.js +354 -250
  144. package/lib/workerStorage.js +16 -16
  145. package/lib/workers.js +366 -282
  146. package/package.json +107 -95
  147. package/translations/de-DE.js +5 -4
  148. package/translations/fr-FR.js +5 -4
  149. package/translations/index.js +23 -9
  150. package/translations/it-IT.js +5 -4
  151. package/translations/ja-JP.js +5 -4
  152. package/translations/nl-NL.js +76 -0
  153. package/translations/pl-PL.js +5 -4
  154. package/translations/pt-BR.js +5 -4
  155. package/translations/ru-RU.js +5 -4
  156. package/translations/utils.js +18 -0
  157. package/translations/zh-CN.js +5 -4
  158. package/translations/zh-TW.js +5 -4
  159. package/typings/index.d.ts +177 -186
  160. package/typings/promiseBasedTypes.d.ts +3573 -5941
  161. package/typings/types.d.ts +4042 -6370
  162. package/lib/cli.js +0 -256
  163. package/lib/helper/ExpectHelper.js +0 -391
  164. package/lib/helper/Nightmare.js +0 -1504
  165. package/lib/helper/Protractor.js +0 -1863
  166. package/lib/helper/SoftExpectHelper.js +0 -381
  167. package/lib/helper/TestCafe.js +0 -1414
  168. package/lib/helper/clientscripts/nightmare.js +0 -213
  169. package/lib/helper/extras/PlaywrightReactVueLocator.js +0 -43
  170. package/lib/helper/testcafe/testControllerHolder.js +0 -42
  171. package/lib/helper/testcafe/testcafe-utils.js +0 -62
  172. package/lib/interfaces/bdd.js +0 -81
  173. package/lib/listener/artifacts.js +0 -19
  174. package/lib/listener/timeout.js +0 -109
  175. package/lib/mochaFactory.js +0 -113
  176. package/lib/plugin/allure.js +0 -15
  177. package/lib/plugin/commentStep.js +0 -136
  178. package/lib/plugin/debugErrors.js +0 -67
  179. package/lib/plugin/eachElement.js +0 -127
  180. package/lib/plugin/fakerTransform.js +0 -49
  181. package/lib/plugin/retryTo.js +0 -127
  182. package/lib/plugin/selenoid.js +0 -384
  183. package/lib/plugin/standardActingHelpers.js +0 -3
  184. package/lib/plugin/tryTo.js +0 -115
  185. package/lib/plugin/wdio.js +0 -249
  186. package/lib/scenario.js +0 -224
  187. package/lib/ui.js +0 -236
  188. package/lib/within.js +0 -70
@@ -1,25 +1,60 @@
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')
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'
6
7
 
7
- module.exports = async function (path) {
8
+ async function getPlaywrightBrowsers() {
9
+ try {
10
+ const regex = /(chromium|firefox|webkit)\s+version\s+([\d.]+)/gi
11
+ let versions = []
12
+
13
+ const info = execSync('npx playwright install --dry-run').toString().trim()
14
+
15
+ const matches = [...info.matchAll(regex)]
16
+
17
+ matches.forEach(match => {
18
+ const browser = match[1]
19
+ const version = match[2]
20
+ versions.push(`${browser}: ${version}`)
21
+ })
22
+
23
+ return versions.join(', ')
24
+ } catch (err) {
25
+ return 'Playwright not installed'
26
+ }
27
+ }
28
+
29
+ async function getOsBrowsers() {
30
+ const chromeInfo = await envinfo.helpers.getChromeInfo()
31
+ const edgeInfo = await envinfo.helpers.getEdgeInfo()
32
+ const firefoxInfo = await envinfo.helpers.getFirefoxInfo()
33
+ const safariInfo = await envinfo.helpers.getSafariInfo()
34
+
35
+ return [
36
+ `chrome: ${chromeInfo ? chromeInfo[1] : 'not installed'}`,
37
+ `edge: ${edgeInfo ? edgeInfo[1] : 'not installed'}`,
38
+ `firefox: ${firefoxInfo ? firefoxInfo[1] : 'not installed'}`,
39
+ `safari: ${safariInfo ? safariInfo[1] : 'not installed'}`,
40
+ ].join(', ')
41
+ }
42
+
43
+ export default async function (path) {
8
44
  const testsPath = getTestRoot(path)
9
- const config = getConfig(testsPath)
45
+ const config = await getConfig(testsPath)
10
46
  const codecept = new Codecept(config, {})
11
47
  codecept.init(testsPath)
12
48
 
13
- output.print('\n Environment information:-\n')
49
+ output.print('\n Environment information: \n')
14
50
  const info = {}
15
51
  info.codeceptVersion = Codecept.version()
16
52
  info.nodeInfo = await envinfo.helpers.getNodeInfo()
17
53
  info.osInfo = await envinfo.helpers.getOSInfo()
18
54
  info.cpuInfo = await envinfo.helpers.getCPUInfo()
19
- info.chromeInfo = await envinfo.helpers.getChromeInfo()
20
- info.edgeInfo = await envinfo.helpers.getEdgeInfo()
21
- info.firefoxInfo = await envinfo.helpers.getFirefoxInfo()
22
- info.safariInfo = await envinfo.helpers.getSafariInfo()
55
+ info.osBrowsers = await getOsBrowsers()
56
+ info.playwrightBrowsers = await getPlaywrightBrowsers()
57
+
23
58
  const { helpers, plugins } = config
24
59
  info.helpers = helpers || "You don't use any helpers"
25
60
  info.plugins = plugins || "You don't have any enabled plugins"
@@ -34,13 +69,11 @@ module.exports = async function (path) {
34
69
  output.print('***************************************')
35
70
  output.print('If you have questions ask them in our Slack: http://bit.ly/chat-codeceptjs')
36
71
  output.print('Or ask them on our discussion board: https://codecept.discourse.group/')
37
- output.print(
38
- 'Please copy environment info when you report issues on GitHub: https://github.com/Codeception/CodeceptJS/issues',
39
- )
72
+ output.print('Please copy environment info when you report issues on GitHub: https://github.com/Codeception/CodeceptJS/issues')
40
73
  output.print('***************************************')
41
74
  }
42
75
 
43
- module.exports.getMachineInfo = async () => {
76
+ export const getMachineInfo = async () => {
44
77
  const info = {
45
78
  nodeInfo: await envinfo.helpers.getNodeInfo(),
46
79
  osInfo: await envinfo.helpers.getOSInfo(),
@@ -49,6 +82,7 @@ module.exports.getMachineInfo = async () => {
49
82
  edgeInfo: await envinfo.helpers.getEdgeInfo(),
50
83
  firefoxInfo: await envinfo.helpers.getFirefoxInfo(),
51
84
  safariInfo: await envinfo.helpers.getSafariInfo(),
85
+ playwrightBrowsers: await getPlaywrightBrowsers(),
52
86
  }
53
87
 
54
88
  output.print('***************************************')
@@ -1,17 +1,18 @@
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',
@@ -20,11 +21,15 @@ const defaultConfig = {
20
21
  include: {},
21
22
  }
22
23
 
23
- const helpers = ['Playwright', 'WebDriver', 'Puppeteer', 'REST', 'GraphQL', 'Appium', 'TestCafe']
24
- const translations = Object.keys(require('../../translations'))
25
-
24
+ const helpers = ['Playwright', 'WebDriver', 'Puppeteer', 'REST', 'GraphQL', 'Appium']
26
25
  const noTranslation = 'English (no localization)'
27
- 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
+ }
28
33
 
29
34
  const packages = []
30
35
  let isTypeScript = false
@@ -45,7 +50,7 @@ setCommonPlugins();
45
50
 
46
51
  const defaultActor = `// in this file you can append custom step methods to 'I' object
47
52
 
48
- module.exports = function() {
53
+ export default function() {
49
54
  return actor({
50
55
 
51
56
  // Define custom steps here, use 'this' to access default methods of I.
@@ -67,8 +72,9 @@ export = function() {
67
72
  }
68
73
  `
69
74
 
70
- module.exports = function (initPath) {
75
+ export default async function (initPath) {
71
76
  const testsPath = getTestRoot(initPath)
77
+ const translations = await getTranslations()
72
78
 
73
79
  print()
74
80
  print(` Welcome to ${colors.magenta.bold('CodeceptJS')} initialization tool`)
@@ -117,7 +123,7 @@ module.exports = function (initPath) {
117
123
  {
118
124
  name: 'tests',
119
125
  type: 'input',
120
- default: (answers) => `./*_test.${answers.typescript ? 'ts' : 'js'}`,
126
+ default: answers => `./*_test.${answers.typescript ? 'ts' : 'js'}`,
121
127
  message: 'Where are your tests located?',
122
128
  },
123
129
  {
@@ -132,7 +138,7 @@ module.exports = function (initPath) {
132
138
  type: 'confirm',
133
139
  default: true,
134
140
  message: 'Do you want to use JSONResponse helper for assertions on JSON responses? http://bit.ly/3ASVPy9',
135
- when: (answers) => ['GraphQL', 'REST'].includes(answers.helper) === true,
141
+ when: answers => ['GraphQL', 'REST'].includes(answers.helper) === true,
136
142
  },
137
143
  {
138
144
  name: 'output',
@@ -146,7 +152,7 @@ module.exports = function (initPath) {
146
152
  choices: translations,
147
153
  },
148
154
  ])
149
- .then((result) => {
155
+ .then(async result => {
150
156
  if (result.typescript === true) {
151
157
  isTypeScript = true
152
158
  extension = isTypeScript === true ? 'ts' : 'js'
@@ -182,14 +188,15 @@ module.exports = function (initPath) {
182
188
  let helperConfigs = []
183
189
 
184
190
  try {
185
- const Helper = require(`../helper/${helperName}`)
191
+ const HelperModule = await import(`../helper/${helperName}.js`)
192
+ const Helper = HelperModule.default || HelperModule
186
193
  if (Helper._checkRequirements) {
187
194
  packages.concat(Helper._checkRequirements())
188
195
  }
189
196
 
190
197
  if (!Helper._config()) return
191
198
  helperConfigs = helperConfigs.concat(
192
- Helper._config().map((config) => {
199
+ Helper._config().map(config => {
193
200
  config.message = `[${helperName}] ${config.message}`
194
201
  config.name = `${helperName}_${config.name}`
195
202
  config.type = config.type || 'input'
@@ -207,9 +214,9 @@ module.exports = function (initPath) {
207
214
  fs.writeFileSync(path.join(testsPath, stepFile), extension === 'ts' ? defaultActorTs : defaultActor)
208
215
 
209
216
  if (isTypeScript) {
210
- config.include = _actorTranslation('./steps_file', config.translation)
217
+ config.include = await _actorTranslation('./steps_file', config.translation, translations)
211
218
  } else {
212
- config.include = _actorTranslation(stepFile, config.translation)
219
+ config.include = await _actorTranslation(stepFile, config.translation, translations)
213
220
  }
214
221
 
215
222
  print(`Steps file created at ${stepFile}`)
@@ -225,9 +232,7 @@ module.exports = function (initPath) {
225
232
  fs.writeFileSync(typeScriptconfigFile, configSource, 'utf-8')
226
233
  print(`Config created at ${typeScriptconfigFile}`)
227
234
  } else {
228
- configSource = beautify(
229
- `/** @type {CodeceptJS.MainConfig} */\nexports.config = ${inspect(config, false, 4, false)}`,
230
- )
235
+ configSource = beautify(`/** @type {CodeceptJS.MainConfig} */\nexports.config = ${inspect(config, false, 4, false)}`)
231
236
 
232
237
  if (hasConfigure) configSource = requireCodeceptConfigure + configHeader + configSource
233
238
 
@@ -286,9 +291,7 @@ module.exports = function (initPath) {
286
291
  }
287
292
  }
288
293
 
289
- const generateDefinitionsManually = colors.bold(
290
- `To get auto-completion support, please generate type definitions: ${colors.green('npx codeceptjs def')}`,
291
- )
294
+ const generateDefinitionsManually = colors.bold(`To get auto-completion support, please generate type definitions: ${colors.green('npx codeceptjs def')}`)
292
295
 
293
296
  if (packages) {
294
297
  try {
@@ -330,7 +333,7 @@ module.exports = function (initPath) {
330
333
  }
331
334
 
332
335
  print('Configure helpers...')
333
- inquirer.prompt(helperConfigs).then(async (helperResult) => {
336
+ inquirer.prompt(helperConfigs).then(async helperResult => {
334
337
  if (helperResult.Playwright_browser === 'electron') {
335
338
  delete helperResult.Playwright_url
336
339
  delete helperResult.Playwright_show
@@ -341,7 +344,7 @@ module.exports = function (initPath) {
341
344
  }
342
345
  }
343
346
 
344
- Object.keys(helperResult).forEach((key) => {
347
+ Object.keys(helperResult).forEach(key => {
345
348
  const parts = key.split('_')
346
349
  const helperName = parts[0]
347
350
  const configName = parts[1]
@@ -394,7 +397,7 @@ function install(dependencies) {
394
397
  return true
395
398
  }
396
399
 
397
- function _actorTranslation(stepFile, translationSelected) {
400
+ async function _actorTranslation(stepFile, translationSelected, translations) {
398
401
  let actor
399
402
 
400
403
  for (const translationAvailable of translations) {
@@ -403,7 +406,8 @@ function _actorTranslation(stepFile, translationSelected) {
403
406
  }
404
407
 
405
408
  if (translationSelected === translationAvailable) {
406
- const nameOfActor = require('../../translations')[translationAvailable].I
409
+ const translationsModule = await import('../../translations/index.js')
410
+ const nameOfActor = (translationsModule.default || translationsModule)[translationAvailable].I
407
411
 
408
412
  actor = {
409
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')
7
- const webHelpers = require('../plugin/standardActingHelpers')
8
-
9
- module.exports = async function (path, options) {
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'
8
+ const webHelpers = Container.STANDARD_ACTING_HELPERS
9
+
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,18 +21,27 @@ 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
 
28
+ let addGlobalRetries
29
+
30
+ if (config.retry) {
31
+ addGlobalRetries = function retries() {}
32
+ }
33
+
26
34
  output.print('Starting interactive shell for current suite...')
27
35
  recorder.start()
28
36
  event.emit(event.suite.before, {
29
37
  fullTitle: () => 'Interactive Shell',
30
38
  tests: [],
39
+ retries: addGlobalRetries,
31
40
  })
32
41
  event.emit(event.test.before, {
33
42
  title: '',
34
43
  artifacts: {},
44
+ retries: addGlobalRetries,
35
45
  })
36
46
 
37
47
  const enabledHelpers = Container.helpers()
@@ -39,12 +49,11 @@ module.exports = async function (path, options) {
39
49
  if (webHelpers.includes(helperName)) {
40
50
  const I = enabledHelpers[helperName]
41
51
  recorder.add(() => I.amOnPage('/'))
42
- recorder.catchWithoutStop((e) => output.print(`Error while loading home page: ${e.message}}`))
52
+ recorder.catchWithoutStop(e => output.print(`Error while loading home page: ${e.message}}`))
43
53
  break
44
54
  }
45
55
  }
46
- require('../pause')()
47
- // recorder.catchWithoutStop((err) => console.log(err.stack));
56
+ pause()
48
57
  recorder.add(() => event.emit(event.test.after, {}))
49
58
  recorder.add(() => event.emit(event.suite.after, {}))
50
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()
@@ -17,7 +18,7 @@ module.exports = function (path) {
17
18
  const actions = []
18
19
  for (const name in helpers) {
19
20
  const helper = helpers[name]
20
- methodsOfObject(helper).forEach((action) => {
21
+ methodsOfObject(helper).forEach(action => {
21
22
  const params = getParamsToString(helper[action])
22
23
  actions[action] = 1
23
24
  output.print(` ${output.colors.grey(name)} I.${output.colors.bold(action)}(${params})`)
@@ -1,60 +1,60 @@
1
- const glob = 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.
7
7
  */
8
8
  const splitFiles = (list, size) => {
9
- const sets = [];
10
- const chunks = list.length / size;
11
- let i = 0;
9
+ const sets = []
10
+ const chunks = list.length / size
11
+ let i = 0
12
12
 
13
13
  while (i < chunks) {
14
- sets[i] = list.splice(0, size);
15
- i++;
14
+ sets[i] = list.splice(0, size)
15
+ i++
16
16
  }
17
17
 
18
- return sets;
19
- };
18
+ return sets
19
+ }
20
20
 
21
21
  /**
22
22
  * Executes a glob pattern and pushes the results to a list.
23
23
  */
24
- const findFiles = (pattern) => {
25
- const files = [];
24
+ const findFiles = pattern => {
25
+ const files = []
26
26
 
27
- glob.sync(pattern).forEach((file) => {
28
- files.push(path.resolve(file));
29
- });
27
+ globSync(pattern).forEach(file => {
28
+ files.push(path.resolve(file))
29
+ })
30
30
 
31
- return files;
32
- };
31
+ return files
32
+ }
33
33
 
34
34
  /**
35
35
  * Joins a list of files to a valid glob pattern
36
36
  */
37
- const flattenFiles = (list) => {
38
- const pattern = list.join(',');
39
- return pattern.indexOf(',') > -1 ? `{${pattern}}` : pattern;
40
- };
37
+ const flattenFiles = list => {
38
+ const pattern = list.join(',')
39
+ return pattern.indexOf(',') > -1 ? `{${pattern}}` : pattern
40
+ }
41
41
 
42
42
  /**
43
43
  * Greps a file by its content, checks if Scenario or Feature text'
44
44
  * matches the grep text.
45
45
  */
46
46
  const grepFile = (file, grep) => {
47
- const contents = fs.readFileSync(file, 'utf8');
48
- const pattern = new RegExp(`((Scenario|Feature)\(.*${grep}.*\))`, 'g'); // <- How future proof/solid is this?
49
- return !!pattern.exec(contents);
50
- };
47
+ const contents = fs.readFileSync(file, 'utf8')
48
+ const pattern = new RegExp(`((Scenario|Feature)\(.*${grep}.*\))`, 'g') // <- How future proof/solid is this?
49
+ return !!pattern.exec(contents)
50
+ }
51
51
 
52
- const mapFileFormats = (files) => {
52
+ const mapFileFormats = files => {
53
53
  return {
54
54
  gherkin: files.filter(file => file.match(/\.feature$/)),
55
55
  js: files.filter(file => file.match(/\.t|js$/)),
56
- };
57
- };
56
+ }
57
+ }
58
58
 
59
59
  /**
60
60
  * Creates a list of chunks incl. configuration by either dividing a list of scenario
@@ -62,30 +62,33 @@ const mapFileFormats = (files) => {
62
62
  * the splitting.
63
63
  */
64
64
  const createChunks = (config, patterns = []) => {
65
- const files = patterns.filter(pattern => !!pattern).map((pattern) => {
66
- return findFiles(pattern).filter((file) => {
67
- return config.grep ? grepFile(file, config.grep) : true;
68
- });
69
- }).reduce((acc, val) => acc.concat(val), []);
65
+ const files = patterns
66
+ .filter(pattern => !!pattern)
67
+ .map(pattern => {
68
+ return findFiles(pattern).filter(file => {
69
+ return config.grep ? grepFile(file, config.grep) : true
70
+ })
71
+ })
72
+ .reduce((acc, val) => acc.concat(val), [])
70
73
 
71
- let chunks = [];
74
+ let chunks = []
72
75
  if (typeof config.chunks === 'function') {
73
- chunks = config.chunks.call(this, files);
76
+ chunks = config.chunks.call(this, files)
74
77
  } else if (typeof config.chunks === 'number' || typeof config.chunks === 'string') {
75
- chunks = splitFiles(files, Math.ceil(files.length / config.chunks));
78
+ chunks = splitFiles(files, Math.ceil(files.length / config.chunks))
76
79
  } else {
77
- throw new Error('chunks is neither a finite number or a valid function');
80
+ throw new Error('chunks is neither a finite number or a valid function')
78
81
  }
79
82
 
80
- const chunkConfig = { ...config };
81
- delete chunkConfig.chunks;
83
+ const chunkConfig = { ...config }
84
+ delete chunkConfig.chunks
82
85
 
83
- return chunks.map((chunkFiles) => {
84
- const { js, gherkin } = mapFileFormats(chunkFiles);
85
- return { ...chunkConfig, tests: flattenFiles(js), gherkin: { features: flattenFiles(gherkin) } };
86
- });
87
- };
86
+ return chunks.map(chunkFiles => {
87
+ const { js, gherkin } = mapFileFormats(chunkFiles)
88
+ return { ...chunkConfig, tests: flattenFiles(js), gherkin: { features: flattenFiles(gherkin) } }
89
+ })
90
+ }
88
91
 
89
- module.exports = {
90
- createChunks,
91
- };
92
+ export {
93
+ createChunks
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
+ }