codeceptjs 3.6.6 → 4.0.0-beta.1

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 (151) hide show
  1. package/bin/codecept.js +81 -84
  2. package/lib/actor.js +13 -13
  3. package/lib/ai.js +13 -10
  4. package/lib/assert/empty.js +21 -20
  5. package/lib/assert/equal.js +39 -37
  6. package/lib/assert/error.js +14 -14
  7. package/lib/assert/include.js +47 -46
  8. package/lib/assert/throws.js +11 -13
  9. package/lib/assert/truth.js +22 -19
  10. package/lib/assert.js +2 -4
  11. package/lib/cli.js +49 -57
  12. package/lib/codecept.js +155 -142
  13. package/lib/colorUtils.js +3 -3
  14. package/lib/command/configMigrate.js +52 -58
  15. package/lib/command/definitions.js +89 -88
  16. package/lib/command/dryRun.js +68 -71
  17. package/lib/command/generate.js +188 -197
  18. package/lib/command/gherkin/init.js +16 -27
  19. package/lib/command/gherkin/snippets.js +20 -20
  20. package/lib/command/gherkin/steps.js +8 -8
  21. package/lib/command/info.js +38 -40
  22. package/lib/command/init.js +288 -290
  23. package/lib/command/interactive.js +32 -32
  24. package/lib/command/list.js +26 -26
  25. package/lib/command/run-multiple/chunk.js +5 -5
  26. package/lib/command/run-multiple/collection.js +3 -3
  27. package/lib/command/run-multiple/run.js +2 -6
  28. package/lib/command/run-multiple.js +93 -113
  29. package/lib/command/run-rerun.js +25 -20
  30. package/lib/command/run-workers.js +66 -64
  31. package/lib/command/run.js +29 -26
  32. package/lib/command/utils.js +65 -80
  33. package/lib/command/workers/runTests.js +10 -10
  34. package/lib/config.js +9 -10
  35. package/lib/container.js +48 -40
  36. package/lib/data/context.js +59 -60
  37. package/lib/data/dataScenarioConfig.js +47 -47
  38. package/lib/data/dataTableArgument.js +29 -29
  39. package/lib/data/table.js +20 -26
  40. package/lib/dirname.js +5 -0
  41. package/lib/event.js +167 -163
  42. package/lib/heal.js +17 -13
  43. package/lib/helper/AI.js +41 -130
  44. package/lib/helper/ApiDataFactory.js +69 -73
  45. package/lib/helper/Appium.js +381 -412
  46. package/lib/helper/Expect.js +425 -0
  47. package/lib/helper/ExpectHelper.js +48 -40
  48. package/lib/helper/FileSystem.js +79 -80
  49. package/lib/helper/GraphQL.js +43 -44
  50. package/lib/helper/GraphQLDataFactory.js +50 -50
  51. package/lib/helper/JSONResponse.js +62 -65
  52. package/lib/helper/Mochawesome.js +28 -28
  53. package/lib/helper/MockServer.js +14 -12
  54. package/lib/helper/Nightmare.js +566 -662
  55. package/lib/helper/Playwright.js +1216 -1361
  56. package/lib/helper/Protractor.js +627 -663
  57. package/lib/helper/Puppeteer.js +1128 -1231
  58. package/lib/helper/REST.js +68 -159
  59. package/lib/helper/SoftExpectHelper.js +2 -2
  60. package/lib/helper/TestCafe.js +484 -490
  61. package/lib/helper/WebDriver.js +1156 -1297
  62. package/lib/helper/clientscripts/PollyWebDriverExt.js +1 -1
  63. package/lib/helper/errors/ConnectionRefused.js +1 -1
  64. package/lib/helper/errors/ElementAssertion.js +2 -2
  65. package/lib/helper/errors/ElementNotFound.js +2 -2
  66. package/lib/helper/errors/RemoteBrowserConnectionRefused.js +1 -1
  67. package/lib/helper/extras/Console.js +1 -1
  68. package/lib/helper/extras/PlaywrightPropEngine.js +2 -2
  69. package/lib/helper/extras/PlaywrightReactVueLocator.js +1 -1
  70. package/lib/helper/extras/PlaywrightRestartOpts.js +18 -21
  71. package/lib/helper/extras/Popup.js +1 -1
  72. package/lib/helper/extras/React.js +3 -3
  73. package/lib/helper/network/actions.js +7 -14
  74. package/lib/helper/network/utils.js +2 -3
  75. package/lib/helper/scripts/blurElement.js +1 -1
  76. package/lib/helper/scripts/focusElement.js +1 -1
  77. package/lib/helper/scripts/highlightElement.js +1 -1
  78. package/lib/helper/scripts/isElementClickable.js +1 -1
  79. package/lib/helper/testcafe/testControllerHolder.js +1 -1
  80. package/lib/helper/testcafe/testcafe-utils.js +7 -6
  81. package/lib/helper.js +3 -1
  82. package/lib/history.js +5 -6
  83. package/lib/hooks.js +6 -6
  84. package/lib/html.js +7 -7
  85. package/lib/index.js +41 -25
  86. package/lib/interfaces/bdd.js +64 -47
  87. package/lib/interfaces/featureConfig.js +19 -19
  88. package/lib/interfaces/gherkin.js +118 -124
  89. package/lib/interfaces/scenarioConfig.js +29 -29
  90. package/lib/listener/artifacts.js +9 -9
  91. package/lib/listener/config.js +24 -24
  92. package/lib/listener/exit.js +12 -12
  93. package/lib/listener/helpers.js +42 -42
  94. package/lib/listener/mocha.js +11 -11
  95. package/lib/listener/retry.js +30 -32
  96. package/lib/listener/steps.js +53 -50
  97. package/lib/listener/timeout.js +54 -54
  98. package/lib/locator.js +10 -6
  99. package/lib/mochaFactory.js +15 -18
  100. package/lib/output.js +10 -6
  101. package/lib/parser.js +12 -15
  102. package/lib/pause.js +33 -40
  103. package/lib/plugin/allure.js +15 -15
  104. package/lib/plugin/autoDelay.js +37 -29
  105. package/lib/plugin/autoLogin.js +65 -70
  106. package/lib/plugin/commentStep.js +18 -18
  107. package/lib/plugin/coverage.js +67 -115
  108. package/lib/plugin/customLocator.js +20 -21
  109. package/lib/plugin/debugErrors.js +24 -24
  110. package/lib/plugin/eachElement.js +38 -38
  111. package/lib/plugin/fakerTransform.js +6 -6
  112. package/lib/plugin/heal.js +108 -67
  113. package/lib/plugin/pauseOnFail.js +11 -11
  114. package/lib/plugin/retryFailedStep.js +39 -32
  115. package/lib/plugin/retryTo.js +40 -46
  116. package/lib/plugin/screenshotOnFail.js +87 -109
  117. package/lib/plugin/selenoid.js +118 -131
  118. package/lib/plugin/standardActingHelpers.js +8 -2
  119. package/lib/plugin/stepByStepReport.js +91 -110
  120. package/lib/plugin/stepTimeout.js +23 -24
  121. package/lib/plugin/subtitles.js +35 -34
  122. package/lib/plugin/tryTo.js +30 -40
  123. package/lib/plugin/wdio.js +75 -78
  124. package/lib/recorder.js +17 -14
  125. package/lib/rerun.js +10 -11
  126. package/lib/scenario.js +23 -25
  127. package/lib/secret.js +2 -4
  128. package/lib/session.js +10 -10
  129. package/lib/step.js +9 -12
  130. package/lib/store.js +3 -2
  131. package/lib/transform.js +1 -1
  132. package/lib/translation.js +8 -7
  133. package/lib/ui.js +14 -12
  134. package/lib/utils.js +72 -70
  135. package/lib/within.js +10 -10
  136. package/lib/workerStorage.js +25 -27
  137. package/lib/workers.js +32 -29
  138. package/package.json +53 -51
  139. package/translations/de-DE.js +1 -1
  140. package/translations/fr-FR.js +1 -1
  141. package/translations/index.js +13 -9
  142. package/translations/it-IT.js +1 -1
  143. package/translations/ja-JP.js +1 -1
  144. package/translations/pl-PL.js +1 -1
  145. package/translations/pt-BR.js +1 -1
  146. package/translations/ru-RU.js +1 -1
  147. package/translations/zh-CN.js +1 -1
  148. package/translations/zh-TW.js +1 -1
  149. package/typings/index.d.ts +65 -415
  150. package/typings/promiseBasedTypes.d.ts +32 -0
  151. package/typings/types.d.ts +32 -0
@@ -108,4 +108,4 @@ const pollyWebDriver = {
108
108
  },
109
109
  };
110
110
 
111
- module.exports = pollyWebDriver;
111
+ export default pollyWebDriver;
@@ -7,4 +7,4 @@ function ConnectionRefused(err) {
7
7
 
8
8
  ConnectionRefused.prototype = Object.create(Error.prototype);
9
9
 
10
- module.exports = ConnectionRefused;
10
+ export default ConnectionRefused;
@@ -1,4 +1,4 @@
1
- const Locator = require('../../locator');
1
+ import Locator from '../../locator.js';
2
2
 
3
3
  const prefixMessage = 'Element';
4
4
 
@@ -30,7 +30,7 @@ function dontSeeElementInDOMError(locator) {
30
30
  throw new Error(`${prefixMessage} "${(new Locator(locator))}" is not seen in DOM.`);
31
31
  }
32
32
 
33
- module.exports = {
33
+ export {
34
34
  seeElementError,
35
35
  dontSeeElementError,
36
36
  seeElementInDOMError,
@@ -1,4 +1,4 @@
1
- const Locator = require('../../locator');
1
+ import Locator from '../../locator.js';
2
2
  /**
3
3
  * Uses to throw readable element not found error
4
4
  * Stringify object's locators
@@ -16,4 +16,4 @@ class ElementNotFound {
16
16
  }
17
17
  }
18
18
 
19
- module.exports = ElementNotFound;
19
+ export default ElementNotFound;
@@ -6,4 +6,4 @@ function RemoteBrowserConnectionRefused(err) {
6
6
 
7
7
  RemoteBrowserConnectionRefused.prototype = Object.create(Error.prototype);
8
8
 
9
- module.exports = RemoteBrowserConnectionRefused;
9
+ export default RemoteBrowserConnectionRefused;
@@ -30,4 +30,4 @@ class Console {
30
30
  }
31
31
  }
32
32
 
33
- module.exports = Console;
33
+ export default Console;
@@ -1,4 +1,4 @@
1
- module.exports.createValueEngine = () => {
1
+ export const createValueEngine = () => {
2
2
  return {
3
3
  // Creates a selector that matches given target when queried at the root.
4
4
  // Can return undefined if unable to create one.
@@ -25,7 +25,7 @@ module.exports.createValueEngine = () => {
25
25
  };
26
26
  };
27
27
 
28
- module.exports.createDisabledEngine = () => {
28
+ export const createDisabledEngine = () => {
29
29
  return {
30
30
  // Creates a selector that matches given target when queried at the root.
31
31
  // Can return undefined if unable to create one.
@@ -40,4 +40,4 @@ function propBuilder(props) {
40
40
  return _props;
41
41
  }
42
42
 
43
- module.exports = { findReact, findVue, findByPlaywrightLocator };
43
+ export { findReact, findVue, findByPlaywrightLocator };
@@ -6,28 +6,25 @@ const RESTART_OPTS = {
6
6
 
7
7
  let restarts = null;
8
8
 
9
- module.exports = {
9
+ export function setRestartStrategy(options) {
10
+ const { restart } = options;
11
+ const stringOpts = Object.keys(RESTART_OPTS);
10
12
 
11
- setRestartStrategy(options) {
12
- const { restart } = options;
13
- const stringOpts = Object.keys(RESTART_OPTS);
13
+ if (stringOpts.includes(restart)) {
14
+ return restarts = restart;
15
+ }
14
16
 
15
- if (stringOpts.includes(restart)) {
16
- return restarts = restart;
17
- }
17
+ restarts = Object.keys(RESTART_OPTS).find(key => RESTART_OPTS[key] === restart);
18
18
 
19
- restarts = Object.keys(RESTART_OPTS).find(key => RESTART_OPTS[key] === restart);
19
+ if (restarts === null || restarts === undefined) throw new Error('No restart strategy set, use the following values for restart: session, context, browser');
20
+ }
20
21
 
21
- if (restarts === null || restarts === undefined) throw new Error('No restart strategy set, use the following values for restart: session, context, browser');
22
- },
23
-
24
- restartsSession() {
25
- return restarts === 'session';
26
- },
27
- restartsContext() {
28
- return restarts === 'context';
29
- },
30
- restartsBrowser() {
31
- return restarts === 'browser';
32
- },
33
- };
22
+ export function restartsSession() {
23
+ return restarts === 'session';
24
+ }
25
+ export function restartsContext() {
26
+ return restarts === 'context';
27
+ }
28
+ export function restartsBrowser() {
29
+ return restarts === 'browser';
30
+ }
@@ -64,4 +64,4 @@ class Popup {
64
64
  }
65
65
  }
66
66
 
67
- module.exports = Popup;
67
+ export default Popup;
@@ -1,8 +1,8 @@
1
- const fs = require('fs');
1
+ import fs from 'fs';
2
2
 
3
3
  let resqScript;
4
4
 
5
- module.exports = async function findReact(matcher, locator) {
5
+ export default async function findReact(matcher, locator) {
6
6
  if (!resqScript) resqScript = fs.readFileSync(require.resolve('resq'));
7
7
  await matcher.evaluate(resqScript.toString());
8
8
  await matcher
@@ -63,4 +63,4 @@ module.exports = async function findReact(matcher, locator) {
63
63
  }
64
64
 
65
65
  return result;
66
- };
66
+ }
@@ -1,7 +1,7 @@
1
- const assert = require('assert');
2
- const { isInTraffic, createAdvancedTestResults, getTrafficDump } = require('./utils');
1
+ import assert from 'assert'
2
+ import { isInTraffic, createAdvancedTestResults, getTrafficDump } from './utils.js';
3
3
 
4
- function dontSeeTraffic({ name, url }) {
4
+ export function dontSeeTraffic({ name, url }) {
5
5
  if (!this.recordedAtLeastOnce) {
6
6
  throw new Error('Failure in test automation. You use "I.dontSeeTraffic", but "I.startRecordingTraffic" was never called before.');
7
7
  }
@@ -19,7 +19,7 @@ function dontSeeTraffic({ name, url }) {
19
19
  }
20
20
  }
21
21
 
22
- async function seeTraffic({
22
+ export async function seeTraffic({
23
23
  name, url, parameters, requestPostData, timeout = 10,
24
24
  }) {
25
25
  if (!name) {
@@ -65,7 +65,7 @@ async function seeTraffic({
65
65
  }
66
66
  }
67
67
 
68
- async function grabRecordedNetworkTraffics() {
68
+ export async function grabRecordedNetworkTraffics() {
69
69
  if (!this.recording || !this.recordedAtLeastOnce) {
70
70
  throw new Error('Failure in test automation. You use "I.grabRecordedNetworkTraffics", but "I.startRecordingTraffic" was never called before.');
71
71
  }
@@ -104,20 +104,13 @@ async function grabRecordedNetworkTraffics() {
104
104
  return Promise.all(promises);
105
105
  }
106
106
 
107
- function stopRecordingTraffic() {
107
+ export function stopRecordingTraffic() {
108
108
  // @ts-ignore
109
109
  this.page.removeAllListeners('request');
110
110
  this.recording = false;
111
111
  }
112
112
 
113
- function flushNetworkTraffics() {
113
+ export function flushNetworkTraffics() {
114
114
  this.requests = [];
115
115
  }
116
116
 
117
- module.exports = {
118
- dontSeeTraffic,
119
- seeTraffic,
120
- grabRecordedNetworkTraffics,
121
- stopRecordingTraffic,
122
- flushNetworkTraffics,
123
- };
@@ -135,7 +135,7 @@ const allRequestPostDataValuePairsMatchExtreme = (RequestPostDataObject, advance
135
135
  * @return {string} List of URLs recorded as a string, separated by new lines after each URL
136
136
  * @private
137
137
  */
138
- function getTrafficDump() {
138
+ export function getTrafficDump() {
139
139
  let dumpedTraffic = '';
140
140
  this.requests.forEach((request) => {
141
141
  dumpedTraffic += `${request.method} - ${request.url}\n`;
@@ -177,11 +177,10 @@ function isInTraffic(url, parameters) {
177
177
  return isInTraffic;
178
178
  }
179
179
 
180
- module.exports = {
180
+ export {
181
181
  createAdvancedTestResults,
182
182
  extractQueryObjects,
183
183
  allParameterValuePairsMatchExtreme,
184
184
  allRequestPostDataValuePairsMatchExtreme,
185
- getTrafficDump,
186
185
  isInTraffic,
187
186
  };
@@ -1,4 +1,4 @@
1
- module.exports.blurElement = (element, context) => {
1
+ export const blurElement = (element, context) => {
2
2
  const clientSideBlurFn = el => {
3
3
  el.blur();
4
4
  };
@@ -1,4 +1,4 @@
1
- module.exports.focusElement = (element, context) => {
1
+ export const focusElement = (element, context) => {
2
2
  const clientSideFn = el => {
3
3
  el.focus();
4
4
  };
@@ -1,4 +1,4 @@
1
- module.exports.highlightElement = (element, context) => {
1
+ export const highlightElement = (element, context) => {
2
2
  const clientSideHighlightFn = el => {
3
3
  const style = '0px 0px 4px 3px rgba(255, 0, 0, 0.7)';
4
4
  const prevStyle = el.style.boxShadow;
@@ -61,4 +61,4 @@ function isElementClickable(element) {
61
61
  return element.disabled !== true && isElementInViewport(element) && isOverlappingElementMatch(getOverlappingElements(element), element);
62
62
  }
63
63
 
64
- module.exports = isElementClickable;
64
+ export default isElementClickable;
@@ -39,4 +39,4 @@ const testControllerHolder = {
39
39
  },
40
40
  };
41
41
 
42
- module.exports = testControllerHolder;
42
+ export default testControllerHolder;
@@ -1,9 +1,10 @@
1
- const { ClientFunction } = require('testcafe');
1
+ import { ClientFunction } from 'testcafe';
2
+ import assert from 'assert';
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import { getParamNames } from '../../utils.js';
2
6
 
3
- const assert = require('assert');
4
- const fs = require('fs');
5
- const path = require('path');
6
- const { getParamNames } = require('../../utils');
7
+ const __dirname = path.resolve();
7
8
 
8
9
  const createTestFile = () => {
9
10
  assert(global.output_dir, 'global.output_dir must be set');
@@ -55,7 +56,7 @@ function getFuncBody(func) {
55
56
  // TODO: support general functions
56
57
  }
57
58
 
58
- module.exports = {
59
+ export default {
59
60
  createTestFile,
60
61
  mapError,
61
62
  createClientFunction,
package/lib/helper.js CHANGED
@@ -1,2 +1,4 @@
1
1
  // helper class was moved out from this repository to allow extending from base class
2
- module.exports = require('@codeceptjs/helper');
2
+ import generated from '@codeceptjs/helper';
3
+
4
+ export default generated;
package/lib/history.js CHANGED
@@ -1,8 +1,7 @@
1
- const colors = require('chalk');
2
- const fs = require('fs');
3
- const path = require('path');
4
-
5
- const output = require('./output');
1
+ import colors from 'chalk';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import * as output from './output.js';
6
5
 
7
6
  /**
8
7
  * REPL history records REPL commands and stores them in
@@ -49,4 +48,4 @@ class ReplHistory {
49
48
  }
50
49
  }
51
50
 
52
- module.exports = new ReplHistory();
51
+ export default new ReplHistory();
package/lib/hooks.js CHANGED
@@ -1,17 +1,17 @@
1
- const { isFunction, isAsyncFunction } = require('./utils');
2
- const output = require('./output');
1
+ import { isFunction, isAsyncFunction } from './utils.js';
2
+ import * as output from './output.js';
3
3
 
4
- module.exports = async function (hook, stage) {
4
+ export default async function (hook, stage) {
5
5
  if (!hook) return;
6
6
  if (!isFunction(hook)) {
7
7
  throw new Error('CodeceptJS 3 allows bootstrap/teardown hooks only as async functions. More info: https://bit.ly/codecept3Up');
8
8
  }
9
9
 
10
- if (stage) output.log(`started ${stage} hook`);
10
+ if (stage) output.output.log(`started ${stage} hook`);
11
11
  if (isAsyncFunction(hook)) {
12
12
  await hook();
13
13
  } else {
14
14
  hook();
15
15
  }
16
- if (stage) output.log(`finished ${stage} hook`);
17
- };
16
+ if (stage) output.output.log(`finished ${stage} hook`);
17
+ }
package/lib/html.js CHANGED
@@ -1,7 +1,7 @@
1
- const { parse, serialize } = require('parse5');
2
- const { minify } = require('html-minifier-terser');
1
+ import { parse, serialize } from 'parse5';
2
+ import { minify } from 'html-minifier-terser';
3
3
 
4
- async function minifyHtml(html) {
4
+ export async function minifyHtml(html) {
5
5
  return minify(html, {
6
6
  collapseWhitespace: true,
7
7
  removeComments: true,
@@ -21,7 +21,7 @@ const defaultHtmlOpts = {
21
21
  allowedRoles: ['button', 'checkbox', 'search', 'textbox', 'tab'],
22
22
  };
23
23
 
24
- function removeNonInteractiveElements(html, opts = {}) {
24
+ export function removeNonInteractiveElements(html, opts = {}) {
25
25
  opts = { ...defaultHtmlOpts, ...opts };
26
26
  const {
27
27
  interactiveElements,
@@ -142,7 +142,7 @@ function removeNonInteractiveElements(html, opts = {}) {
142
142
  return serializedHTML;
143
143
  }
144
144
 
145
- function scanForErrorMessages(html, errorClasses = []) {
145
+ export function scanForErrorMessages(html, errorClasses = []) {
146
146
  // Parse the HTML into a document tree
147
147
  const document = parse(html);
148
148
 
@@ -216,7 +216,7 @@ function buildPath(node, path = '') {
216
216
  return path;
217
217
  }
218
218
 
219
- function splitByChunks(text, chunkSize) {
219
+ export function splitByChunks(text, chunkSize) {
220
220
  chunkSize -= 20;
221
221
  const chunks = [];
222
222
  for (let i = 0; i < text.length; i += chunkSize) {
@@ -250,7 +250,7 @@ function splitByChunks(text, chunkSize) {
250
250
  return chunks.map(chunk => chunk.trim());
251
251
  }
252
252
 
253
- module.exports = {
253
+ export default {
254
254
  scanForErrorMessages,
255
255
  removeNonInteractiveElements,
256
256
  splitByChunks,
package/lib/index.js CHANGED
@@ -1,3 +1,20 @@
1
+ import * as _codecept from './codecept.js';
2
+ import * as workers from './workers.js';
3
+ import * as dataTableArgument from './data/dataTableArgument.js';
4
+ import * as dataTable from './data/table.js';
5
+ import * as within from './within.js';
6
+ import * as pause from './pause.js';
7
+ import * as helper from './helper.js';
8
+ import * as actor from './actor.js';
9
+ import * as config from './config.js';
10
+ import * as output from './output.js';
11
+ import * as recorder from './recorder.js';
12
+ import * as container from './container.js';
13
+ import * as locator from './locator.js';
14
+ import * as event from './event.js';
15
+ import * as store from './store.js';
16
+ import * as heal from './heal.js';
17
+ import * as ai from './ai.js';
1
18
  /**
2
19
  * Index file for loading CodeceptJS programmatically.
3
20
  *
@@ -5,42 +22,41 @@
5
22
  * @alias index
6
23
  * @namespace
7
24
  */
8
- module.exports = {
9
- /** @type {typeof CodeceptJS.Codecept} */
10
- codecept: require('./codecept'),
11
- /** @type {typeof CodeceptJS.Codecept} */
12
- Codecept: require('./codecept'),
25
+ /** @type {typeof CodeceptJS.Codecept} */
26
+ export { _codecept as codecept };
27
+ /** @type {typeof CodeceptJS.Codecept} */
28
+ export { _codecept as Codecept };
29
+ /** @type {typeof CodeceptJS.Helper} */
30
+ export { helper as Helper };
31
+ export { workers as Workers };
32
+ export {
13
33
  /** @type {typeof CodeceptJS.output} */
14
- output: require('./output'),
34
+ output,
15
35
  /** @type {typeof CodeceptJS.Container} */
16
- container: require('./container'),
36
+ container,
17
37
  /** @type {typeof CodeceptJS.event} */
18
- event: require('./event'),
38
+ event,
19
39
  /** @type {CodeceptJS.recorder} */
20
- recorder: require('./recorder'),
40
+ recorder,
21
41
  /** @type {typeof CodeceptJS.Config} */
22
- config: require('./config'),
42
+ config,
23
43
  /** @type {CodeceptJS.actor} */
24
- actor: require('./actor'),
44
+ actor,
25
45
  /** @type {typeof CodeceptJS.Helper} */
26
- helper: require('./helper'),
27
- /** @type {typeof CodeceptJS.Helper} */
28
- Helper: require('./helper'),
46
+ helper,
29
47
  /** @type {typeof CodeceptJS.pause} */
30
- pause: require('./pause'),
48
+ pause,
31
49
  /** @type {typeof CodeceptJS.within} */
32
- within: require('./within'),
50
+ within,
33
51
  /** @type {typeof CodeceptJS.DataTable} */
34
- dataTable: require('./data/table'),
52
+ dataTable,
35
53
  /** @type {typeof CodeceptJS.DataTableArgument} */
36
- dataTableArgument: require('./data/dataTableArgument'),
54
+ dataTableArgument,
37
55
  /** @type {typeof CodeceptJS.store} */
38
- store: require('./store'),
56
+ store,
39
57
  /** @type {typeof CodeceptJS.Locator} */
40
- locator: require('./locator'),
41
-
42
- heal: require('./heal'),
43
- ai: require('./ai'),
44
-
45
- Workers: require('./workers'),
58
+ locator,
59
+ heal,
60
+ ai,
61
+ workers,
46
62
  };
@@ -1,81 +1,98 @@
1
- const { CucumberExpression, ParameterTypeRegistry, ParameterType } = require('@cucumber/cucumber-expressions')
2
- const Config = require('../config')
1
+ import { CucumberExpression, ParameterTypeRegistry, ParameterType } from '@cucumber/cucumber-expressions';
2
+ import Config from '../config.js';
3
3
 
4
- let steps = {}
4
+ let steps = {};
5
+ const codecept_dir = '';
5
6
 
6
- const STACK_POSITION = 2
7
+ const STACK_POSITION = 2;
7
8
 
8
9
  /**
9
10
  * @param {*} step
10
11
  * @param {*} fn
11
12
  */
12
13
  const addStep = (step, fn) => {
13
- const avoidDuplicateSteps = Config.get('gherkin', {}).avoidDuplicateSteps || false
14
- const stack = new Error().stack
14
+ const avoidDuplicateSteps = Config.get('gherkin', {}).avoidDuplicateSteps || false;
15
+ const stack = (new Error()).stack;
15
16
  if (avoidDuplicateSteps && steps[step]) {
16
- throw new Error(`Step '${step}' is already defined`)
17
+ throw new Error(`Step '${step}' is already defined`);
17
18
  }
18
- steps[step] = fn
19
- fn.line = stack && stack.split('\n')[STACK_POSITION]
19
+ steps[step] = fn;
20
+ fn.line = stack && stack.split('\n')[STACK_POSITION];
20
21
  if (fn.line) {
21
22
  fn.line = fn.line
22
23
  .trim()
23
24
  .replace(/^at (.*?)\(/, '(')
24
- .replace(codecept_dir, '.')
25
+ .replace(codecept_dir, '.');
25
26
  }
26
- }
27
+ };
27
28
 
28
- const parameterTypeRegistry = new ParameterTypeRegistry()
29
+ const parameterTypeRegistry = new ParameterTypeRegistry();
29
30
 
30
- const matchStep = (step) => {
31
+ export const matchStep = (step) => {
31
32
  for (const stepName in steps) {
32
33
  if (stepName.indexOf('/') === 0) {
33
- const regExpArr = stepName.match(/^\/(.*?)\/([gimy]*)$/) || []
34
- const res = step.match(new RegExp(regExpArr[1], regExpArr[2]))
34
+ const regExpArr = stepName.match(/^\/(.*?)\/([gimy]*)$/) || [];
35
+ const res = step.match(new RegExp(regExpArr[1], regExpArr[2]));
35
36
  if (res) {
36
- const fn = steps[stepName]
37
- fn.params = res.slice(1)
38
- return fn
37
+ const fn = steps[stepName];
38
+ fn.params = res.slice(1);
39
+ return fn;
39
40
  }
40
- continue
41
+ continue;
41
42
  }
42
- const expression = new CucumberExpression(stepName, parameterTypeRegistry)
43
- const res = expression.match(step)
43
+ const expression = new CucumberExpression(stepName, parameterTypeRegistry);
44
+ // console.log(expression)
45
+ // console.log((step))
46
+ const res = expression.match(step);
44
47
  if (res) {
45
- const fn = steps[stepName]
46
- fn.params = res.map((arg) => arg.getValue())
47
- return fn
48
+ const fn = steps[stepName];
49
+ fn.params = res.map(arg => arg.getValue());
50
+ return fn;
48
51
  }
49
52
  }
50
- throw new Error(`No steps matching "${step.toString()}"`)
51
- }
53
+ throw new Error(`No steps matching "${step.toString()}"`);
54
+ };
52
55
 
53
- const clearSteps = () => {
54
- steps = {}
55
- }
56
+ export const clearSteps = () => {
57
+ steps = {};
58
+ };
56
59
 
57
- const getSteps = () => {
58
- return steps
59
- }
60
+ export const getSteps = () => {
61
+ return steps;
62
+ };
60
63
 
61
- const defineParameterType = (options) => {
62
- const parameterType = buildParameterType(options)
63
- parameterTypeRegistry.defineParameterType(parameterType)
64
- }
64
+ export const defineParameterType = (options) => {
65
+ const parameterType = buildParameterType(options);
66
+ parameterTypeRegistry.defineParameterType(parameterType);
67
+ };
65
68
 
66
- const buildParameterType = ({ name, regexp, transformer, useForSnippets, preferForRegexpMatch }) => {
67
- if (typeof useForSnippets !== 'boolean') useForSnippets = true
68
- if (typeof preferForRegexpMatch !== 'boolean') preferForRegexpMatch = false
69
- return new ParameterType(name, regexp, null, transformer, useForSnippets, preferForRegexpMatch)
70
- }
69
+ export const buildParameterType = ({
70
+ name,
71
+ regexp,
72
+ transformer,
73
+ useForSnippets,
74
+ preferForRegexpMatch,
75
+ }) => {
76
+ if (typeof useForSnippets !== 'boolean') useForSnippets = true;
77
+ if (typeof preferForRegexpMatch !== 'boolean') preferForRegexpMatch = false;
78
+ return new ParameterType(
79
+ name,
80
+ regexp,
81
+ null,
82
+ transformer,
83
+ useForSnippets,
84
+ preferForRegexpMatch,
85
+ );
86
+ };
71
87
 
72
- module.exports = {
73
- Given: addStep,
74
- When: addStep,
75
- Then: addStep,
76
- And: addStep,
88
+ export { addStep as Given };
89
+ export { addStep as When };
90
+ export { addStep as Then };
91
+ export { addStep as And };
92
+
93
+ export default {
77
94
  matchStep,
78
95
  getSteps,
79
96
  clearSteps,
80
97
  defineParameterType,
81
- }
98
+ };