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,7 +1,7 @@
1
- const Assertion = require('../assert')
2
- const AssertionFailedError = require('./error')
3
- const { template } = require('../utils')
4
- const output = require('../output')
1
+ import Assertion from '../assert.js'
2
+ import AssertionFailedError from './error.js'
3
+ import { template } from '../utils.js'
4
+ import output from '../output.js'
5
5
 
6
6
  class EqualityAssertion extends Assertion {
7
7
  constructor(params) {
@@ -18,10 +18,7 @@ class EqualityAssertion extends Assertion {
18
18
  getException() {
19
19
  const params = this.params
20
20
  params.jar = template(params.jar, params)
21
- const err = new AssertionFailedError(
22
- params,
23
- '{{customMessage}}expected {{jar}} "{{expected}}" {{type}} "{{actual}}"',
24
- )
21
+ const err = new AssertionFailedError(params, '{{customMessage}}expected {{jar}} "{{expected}}" {{type}} "{{actual}}"')
25
22
  err.showDiff = false
26
23
  if (typeof err.cliMessage === 'function') {
27
24
  err.message = err.cliMessage()
@@ -40,18 +37,16 @@ class EqualityAssertion extends Assertion {
40
37
  }
41
38
  }
42
39
 
43
- module.exports = {
44
- Assertion: EqualityAssertion,
45
- equals: (jar) => new EqualityAssertion({ jar }),
46
- urlEquals: (baseUrl) => {
47
- const assert = new EqualityAssertion({ jar: 'url of current page' })
48
- assert.comparator = function (expected, actual) {
49
- if (expected.indexOf('http') !== 0) {
50
- actual = actual.slice(actual.indexOf(baseUrl) + baseUrl.length)
51
- }
52
- return actual === expected
40
+ export { EqualityAssertion as Assertion }
41
+ export const equals = jar => new EqualityAssertion({ jar })
42
+ export const urlEquals = baseUrl => {
43
+ const assert = new EqualityAssertion({ jar: 'url of current page' })
44
+ assert.comparator = function (expected, actual) {
45
+ if (expected.indexOf('http') !== 0) {
46
+ actual = actual.slice(actual.indexOf(baseUrl) + baseUrl.length)
53
47
  }
54
- return assert
55
- },
56
- fileEquals: (file) => new EqualityAssertion({ file, jar: 'contents of {{file}}' }),
48
+ return actual === expected
49
+ }
50
+ return assert
57
51
  }
52
+ export const fileEquals = file => new EqualityAssertion({ file, jar: 'contents of {{file}}' })
@@ -1,4 +1,4 @@
1
- const subs = require('../utils').template
1
+ import { template as subs } from '../utils.js'
2
2
 
3
3
  /**
4
4
  * Assertion errors, can provide a detailed error messages.
@@ -29,4 +29,4 @@ function AssertionFailedError(params, template) {
29
29
  AssertionFailedError.prototype = Object.create(Error.prototype)
30
30
  AssertionFailedError.constructor = AssertionFailedError
31
31
 
32
- module.exports = AssertionFailedError
32
+ export default AssertionFailedError
@@ -1,7 +1,7 @@
1
- const Assertion = require('../assert')
2
- const AssertionFailedError = require('./error')
3
- const { template } = require('../utils')
4
- const output = require('../output')
1
+ import Assertion from '../assert.js'
2
+ import AssertionFailedError from './error.js'
3
+ import { template } from '../utils.js'
4
+ import output from '../output.js'
5
5
 
6
6
  const MAX_LINES = 10
7
7
 
@@ -10,7 +10,7 @@ class InclusionAssertion extends Assertion {
10
10
  params.jar = params.jar || 'string'
11
11
  const comparator = function (needle, haystack) {
12
12
  if (Array.isArray(haystack)) {
13
- return haystack.filter((part) => part.indexOf(needle) >= 0).length > 0
13
+ return haystack.filter(part => part.indexOf(needle) >= 0).length > 0
14
14
  }
15
15
  return haystack.indexOf(needle) >= 0
16
16
  }
@@ -28,9 +28,7 @@ class InclusionAssertion extends Assertion {
28
28
  this.params.haystack = this.params.haystack.join('\n___(next element)___\n')
29
29
  }
30
30
  err.cliMessage = function () {
31
- const msg = this.template
32
- .replace('{{jar}}', output.colors.bold('{{jar}}'))
33
- .replace('{{needle}}', output.colors.bold('{{needle}}'))
31
+ const msg = this.template.replace('{{jar}}', output.colors.bold('{{jar}}')).replace('{{needle}}', output.colors.bold('{{needle}}'))
34
32
  return template(msg, this.params)
35
33
  }
36
34
  return err
@@ -64,14 +62,12 @@ class InclusionAssertion extends Assertion {
64
62
  }
65
63
  }
66
64
 
67
- module.exports = {
68
- Assertion: InclusionAssertion,
69
- includes: (needleType) => {
70
- needleType = needleType || 'string'
71
- return new InclusionAssertion({ jar: needleType })
72
- },
73
- fileIncludes: (file) => new InclusionAssertion({ file, jar: 'file {{file}}' }),
65
+ export { InclusionAssertion as Assertion }
66
+ export const includes = needleType => {
67
+ needleType = needleType || 'string'
68
+ return new InclusionAssertion({ jar: needleType })
74
69
  }
70
+ export const fileIncludes = file => new InclusionAssertion({ file, jar: 'file {{file}}' })
75
71
 
76
72
  function escapeRegExp(str) {
77
73
  return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')
@@ -11,12 +11,10 @@ function errorThrown(actual, expected) {
11
11
  throw new Error(`Expected error to be thrown with message ${expected} while '${msg}' caught`)
12
12
  }
13
13
  if (typeof expected === 'object') {
14
- if (actual.constructor.name !== expected.constructor.name)
15
- throw new Error(`Expected ${expected} error to be thrown but ${actual} was caught`)
16
- if (expected.message && expected.message !== msg)
17
- throw new Error(`Expected error to be thrown with message ${expected.message} while '${msg}' caught`)
14
+ if (actual.constructor.name !== expected.constructor.name) throw new Error(`Expected ${expected} error to be thrown but ${actual} was caught`)
15
+ if (expected.message && expected.message !== msg) throw new Error(`Expected error to be thrown with message ${expected.message} while '${msg}' caught`)
18
16
  }
19
17
  return null
20
18
  }
21
19
 
22
- module.exports = errorThrown
20
+ export default errorThrown
@@ -1,13 +1,13 @@
1
- const Assertion = require('../assert')
2
- const AssertionFailedError = require('./error')
3
- const { template } = require('../utils')
4
- const output = require('../output')
1
+ import Assertion from '../assert.js'
2
+ import AssertionFailedError from './error.js'
3
+ import { template } from '../utils.js'
4
+ import output from '../output.js'
5
5
 
6
6
  class TruthAssertion extends Assertion {
7
7
  constructor(params) {
8
- super((value) => {
8
+ super(value => {
9
9
  if (Array.isArray(value)) {
10
- return value.filter((val) => !!val).length > 0
10
+ return value.filter(val => !!val).length > 0
11
11
  }
12
12
  return !!value
13
13
  }, params)
@@ -30,7 +30,10 @@ class TruthAssertion extends Assertion {
30
30
  }
31
31
  }
32
32
 
33
- module.exports = {
33
+ export { TruthAssertion as Assertion }
34
+ export const truth = (subject, type) => new TruthAssertion({ subject, type })
35
+
36
+ export default {
34
37
  Assertion: TruthAssertion,
35
38
  truth: (subject, type) => new TruthAssertion({ subject, type }),
36
39
  }
package/lib/assert.js CHANGED
@@ -1,4 +1,4 @@
1
- const AssertionFailedError = require('./assert/error');
1
+ import AssertionFailedError from './assert/error.js'
2
2
 
3
3
  /**
4
4
  * Abstract assertion class introduced for more verbose and customizable messages.
@@ -22,9 +22,9 @@ const AssertionFailedError = require('./assert/error');
22
22
  */
23
23
  class Assertion {
24
24
  constructor(comparator, params) {
25
- this.comparator = comparator;
26
- this.params = params || {};
27
- this.params.customMessage = '';
25
+ this.comparator = comparator
26
+ this.params = params || {}
27
+ this.params.customMessage = ''
28
28
  }
29
29
 
30
30
  /**
@@ -32,10 +32,10 @@ class Assertion {
32
32
  * Fails if comparator function with provided arguments returns false
33
33
  */
34
34
  assert() {
35
- this.addAssertParams.apply(this, arguments);
36
- const result = this.comparator.apply(this.params, arguments);
37
- if (result) return; // should increase global assertion counter
38
- throw this.getFailedAssertion();
35
+ this.addAssertParams.apply(this, arguments)
36
+ const result = this.comparator.apply(this.params, arguments)
37
+ if (result) return // should increase global assertion counter
38
+ throw this.getFailedAssertion()
39
39
  }
40
40
 
41
41
  /**
@@ -43,10 +43,10 @@ class Assertion {
43
43
  * Fails if comparator function with provided arguments returns true
44
44
  */
45
45
  negate() {
46
- this.addAssertParams.apply(this, arguments);
47
- const result = this.comparator.apply(this.params, arguments);
48
- if (!result) return; // should increase global assertion counter
49
- throw this.getFailedNegation();
46
+ this.addAssertParams.apply(this, arguments)
47
+ const result = this.comparator.apply(this.params, arguments)
48
+ if (!result) return // should increase global assertion counter
49
+ throw this.getFailedNegation()
50
50
  }
51
51
 
52
52
  /**
@@ -55,18 +55,18 @@ class Assertion {
55
55
  addAssertParams() {}
56
56
 
57
57
  getException() {
58
- return new AssertionFailedError(this.params, '');
58
+ return new AssertionFailedError(this.params, '')
59
59
  }
60
60
 
61
61
  getFailedNegation() {
62
- const err = this.getException();
63
- err.params.type = `not ${err.params.type}`;
64
- return err;
62
+ const err = this.getException()
63
+ err.params.type = `not ${err.params.type}`
64
+ return err
65
65
  }
66
66
 
67
67
  getFailedAssertion() {
68
- return this.getException();
68
+ return this.getException()
69
69
  }
70
70
  }
71
71
 
72
- module.exports = Assertion;
72
+ export default Assertion
package/lib/codecept.js CHANGED
@@ -1,14 +1,34 @@
1
- const { existsSync, readFileSync } = require('fs');
2
- const glob = require('glob');
3
- const fsPath = require('path');
4
- const { resolve } = require('path');
5
-
6
- const container = require('./container');
7
- const Config = require('./config');
8
- const event = require('./event');
9
- const runHook = require('./hooks');
10
- const output = require('./output');
11
- const { emptyFolder } = require('./utils');
1
+ import { existsSync, readFileSync } from 'fs'
2
+ import { globSync } from 'glob'
3
+ import fsPath from 'path'
4
+ import { resolve } from 'path'
5
+ import { fileURLToPath } from 'url'
6
+ import { dirname } from 'path'
7
+ import { createRequire } from 'module'
8
+
9
+ const __filename = fileURLToPath(import.meta.url)
10
+ const __dirname = dirname(__filename)
11
+ const require = createRequire(import.meta.url)
12
+
13
+ import Helper from '@codeceptjs/helper'
14
+ import container from './container.js'
15
+ import Config from './config.js'
16
+ import event from './event.js'
17
+ import runHook from './hooks.js'
18
+ import ActorFactory from './actor.js'
19
+ import output from './output.js'
20
+ import { emptyFolder } from './utils.js'
21
+ import { initCodeceptGlobals } from './globals.js'
22
+
23
+ import storeListener from './listener/store.js'
24
+ import stepsListener from './listener/steps.js'
25
+ import configListener from './listener/config.js'
26
+ import resultListener from './listener/result.js'
27
+ import helpersListener from './listener/helpers.js'
28
+ import globalTimeoutListener from './listener/globalTimeout.js'
29
+ import globalRetryListener from './listener/globalRetry.js'
30
+ import exitListener from './listener/exit.js'
31
+ import emptyRunListener from './listener/emptyRun.js'
12
32
 
13
33
  /**
14
34
  * CodeceptJS runner
@@ -22,10 +42,10 @@ class Codecept {
22
42
  * @param {*} opts
23
43
  */
24
44
  constructor(config, opts) {
25
- this.config = Config.create(config);
26
- this.opts = opts;
27
- this.testFiles = new Array(0);
28
- this.requireModules(config.require);
45
+ this.config = Config.create(config)
46
+ this.opts = opts
47
+ this.testFiles = new Array(0)
48
+ this.requireModules(config.require)
29
49
  }
30
50
 
31
51
  /**
@@ -35,13 +55,13 @@ class Codecept {
35
55
  */
36
56
  requireModules(requiringModules) {
37
57
  if (requiringModules) {
38
- requiringModules.forEach((requiredModule) => {
39
- const isLocalFile = existsSync(requiredModule) || existsSync(`${requiredModule}.js`);
58
+ requiringModules.forEach(requiredModule => {
59
+ const isLocalFile = existsSync(requiredModule) || existsSync(`${requiredModule}.js`)
40
60
  if (isLocalFile) {
41
- requiredModule = resolve(requiredModule);
61
+ requiredModule = resolve(requiredModule)
42
62
  }
43
- require(requiredModule);
44
- });
63
+ require(requiredModule)
64
+ })
45
65
  }
46
66
  }
47
67
 
@@ -51,11 +71,13 @@ class Codecept {
51
71
  *
52
72
  * @param {string} dir
53
73
  */
54
- init(dir) {
55
- this.initGlobals(dir);
74
+ async init(dir) {
75
+ await this.initGlobals(dir)
56
76
  // initializing listeners
57
- container.create(this.config, this.opts);
58
- this.runHooks();
77
+ await container.create(this.config, this.opts)
78
+ // Store container globally for easy access
79
+ global.container = container
80
+ await this.runHooks()
59
81
  }
60
82
 
61
83
  /**
@@ -63,56 +85,27 @@ class Codecept {
63
85
  *
64
86
  * @param {string} dir
65
87
  */
66
- initGlobals(dir) {
67
- global.codecept_dir = dir;
68
- global.output_dir = fsPath.resolve(dir, this.config.output);
69
-
70
- if (this.config.emptyOutputFolder) emptyFolder(global.output_dir);
71
-
72
- if (!this.config.noGlobals) {
73
- global.Helper = global.codecept_helper = require('@codeceptjs/helper');
74
- global.actor = global.codecept_actor = require('./actor');
75
- global.pause = require('./pause');
76
- global.within = require('./within');
77
- global.session = require('./session');
78
- global.DataTable = require('./data/table');
79
- global.locate = locator => require('./locator').build(locator);
80
- global.inject = container.support;
81
- global.share = container.share;
82
- global.secret = require('./secret').secret;
83
- global.codecept_debug = output.debug;
84
- global.codeceptjs = require('./index'); // load all objects
85
-
86
- // BDD
87
- const stepDefinitions = require('./interfaces/bdd');
88
- global.Given = stepDefinitions.Given;
89
- global.When = stepDefinitions.When;
90
- global.Then = stepDefinitions.Then;
91
- global.DefineParameterType = stepDefinitions.defineParameterType;
92
-
93
- // debug mode
94
- global.debugMode = false;
95
-
96
- // mask sensitive data
97
- global.maskSensitiveData = this.config.maskSensitiveData || false;
98
- }
88
+ async initGlobals(dir) {
89
+ await initCodeceptGlobals(dir, this.config, container)
99
90
  }
100
91
 
101
92
  /**
102
93
  * Executes hooks.
103
94
  */
104
- runHooks() {
95
+ async runHooks() {
105
96
  // default hooks
106
- runHook(require('./listener/steps'));
107
- runHook(require('./listener/artifacts'));
108
- runHook(require('./listener/config'));
109
- runHook(require('./listener/helpers'));
110
- runHook(require('./listener/retry'));
111
- runHook(require('./listener/timeout'));
112
- runHook(require('./listener/exit'));
97
+ runHook(storeListener)
98
+ runHook(stepsListener)
99
+ runHook(configListener)
100
+ runHook(resultListener)
101
+ runHook(helpersListener)
102
+ runHook(globalTimeoutListener)
103
+ runHook(globalRetryListener)
104
+ runHook(exitListener)
105
+ runHook(emptyRunListener)
113
106
 
114
107
  // custom hooks (previous iteration of plugins)
115
- this.config.hooks.forEach(hook => runHook(hook));
108
+ this.config.hooks.forEach(hook => runHook(hook))
116
109
  }
117
110
 
118
111
  /**
@@ -120,7 +113,7 @@ class Codecept {
120
113
  *
121
114
  */
122
115
  async bootstrap() {
123
- return runHook(this.config.bootstrap, 'bootstrap');
116
+ return runHook(this.config.bootstrap, 'bootstrap')
124
117
  }
125
118
 
126
119
  /**
@@ -128,7 +121,7 @@ class Codecept {
128
121
 
129
122
  */
130
123
  async teardown() {
131
- return runHook(this.config.teardown, 'teardown');
124
+ return runHook(this.config.teardown, 'teardown')
132
125
  }
133
126
 
134
127
  /**
@@ -139,42 +132,44 @@ class Codecept {
139
132
  loadTests(pattern) {
140
133
  const options = {
141
134
  cwd: global.codecept_dir,
142
- };
135
+ }
143
136
 
144
- let patterns = [pattern];
137
+ let patterns = [pattern]
145
138
  if (!pattern) {
146
- patterns = [];
139
+ patterns = []
147
140
 
148
141
  // If the user wants to test a specific set of test files as an array or string.
149
142
  if (this.config.tests && !this.opts.features) {
150
143
  if (Array.isArray(this.config.tests)) {
151
- patterns.push(...this.config.tests);
144
+ patterns.push(...this.config.tests)
152
145
  } else {
153
- patterns.push(this.config.tests);
146
+ patterns.push(this.config.tests)
154
147
  }
155
148
  }
156
149
 
157
- if (this.config.gherkin.features && !this.opts.tests) {
150
+ if (this.config.gherkin && this.config.gherkin.features && !this.opts.tests) {
158
151
  if (Array.isArray(this.config.gherkin.features)) {
159
152
  this.config.gherkin.features.forEach(feature => {
160
- patterns.push(feature);
161
- });
153
+ patterns.push(feature)
154
+ })
162
155
  } else {
163
- patterns.push(this.config.gherkin.features);
156
+ patterns.push(this.config.gherkin.features)
164
157
  }
165
158
  }
166
159
  }
167
160
 
168
161
  for (pattern of patterns) {
169
- glob.sync(pattern, options).forEach((file) => {
170
- if (file.includes('node_modules')) return;
171
- if (!fsPath.isAbsolute(file)) {
172
- file = fsPath.join(global.codecept_dir, file);
173
- }
174
- if (!this.testFiles.includes(fsPath.resolve(file))) {
175
- this.testFiles.push(fsPath.resolve(file));
176
- }
177
- });
162
+ if (pattern) {
163
+ globSync(pattern, options).forEach(file => {
164
+ if (file.includes('node_modules')) return
165
+ if (!fsPath.isAbsolute(file)) {
166
+ file = fsPath.join(global.codecept_dir, file)
167
+ }
168
+ if (!this.testFiles.includes(fsPath.resolve(file))) {
169
+ this.testFiles.push(fsPath.resolve(file))
170
+ }
171
+ })
172
+ }
178
173
  }
179
174
  }
180
175
 
@@ -185,34 +180,50 @@ class Codecept {
185
180
  * @returns {Promise<void>}
186
181
  */
187
182
  async run(test) {
183
+ await container.started()
184
+
185
+ // Ensure translations are loaded for Gherkin features
186
+ try {
187
+ const { loadTranslations } = await import('./mocha/gherkin.js')
188
+ await loadTranslations()
189
+ } catch (e) {
190
+ // Ignore if gherkin module not available
191
+ }
192
+
188
193
  return new Promise((resolve, reject) => {
189
- const mocha = container.mocha();
190
- mocha.files = this.testFiles;
194
+ const mocha = container.mocha()
195
+ mocha.files = this.testFiles
196
+
191
197
  if (test) {
192
198
  if (!fsPath.isAbsolute(test)) {
193
- test = fsPath.join(global.codecept_dir, test);
199
+ test = fsPath.join(global.codecept_dir, test)
194
200
  }
195
- mocha.files = mocha.files.filter(t => fsPath.basename(t, '.js') === test || t === test);
201
+ const testBasename = fsPath.basename(test, '.js')
202
+ const testFeatureBasename = fsPath.basename(test, '.feature')
203
+ mocha.files = mocha.files.filter(t => {
204
+ return fsPath.basename(t, '.js') === testBasename || fsPath.basename(t, '.feature') === testFeatureBasename || t === test
205
+ })
196
206
  }
207
+
197
208
  const done = () => {
198
- event.emit(event.all.result, this);
199
- event.emit(event.all.after, this);
200
- resolve();
201
- };
209
+ event.emit(event.all.result, container.result())
210
+ event.emit(event.all.after, this)
211
+ resolve()
212
+ }
202
213
 
203
214
  try {
204
- event.emit(event.all.before, this);
205
- mocha.run(() => done());
215
+ event.emit(event.all.before, this)
216
+ mocha.run(() => done())
206
217
  } catch (e) {
207
- output.error(e.stack);
208
- reject(e);
218
+ output.error(e.stack)
219
+ reject(e)
209
220
  }
210
- });
221
+ })
211
222
  }
212
223
 
213
224
  static version() {
214
- return JSON.parse(readFileSync(`${__dirname}/../package.json`, 'utf8')).version;
225
+ return JSON.parse(readFileSync(`${__dirname}/../package.json`, 'utf8')).version
215
226
  }
216
227
  }
217
228
 
218
- module.exports = Codecept;
229
+ export default Codecept