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.
- package/bin/codecept.js +81 -84
- package/lib/actor.js +13 -13
- package/lib/ai.js +13 -10
- package/lib/assert/empty.js +21 -20
- package/lib/assert/equal.js +39 -37
- package/lib/assert/error.js +14 -14
- package/lib/assert/include.js +47 -46
- package/lib/assert/throws.js +11 -13
- package/lib/assert/truth.js +22 -19
- package/lib/assert.js +2 -4
- package/lib/cli.js +49 -57
- package/lib/codecept.js +155 -142
- package/lib/colorUtils.js +3 -3
- package/lib/command/configMigrate.js +52 -58
- package/lib/command/definitions.js +89 -88
- package/lib/command/dryRun.js +68 -71
- package/lib/command/generate.js +188 -197
- package/lib/command/gherkin/init.js +16 -27
- package/lib/command/gherkin/snippets.js +20 -20
- package/lib/command/gherkin/steps.js +8 -8
- package/lib/command/info.js +38 -40
- package/lib/command/init.js +288 -290
- package/lib/command/interactive.js +32 -32
- package/lib/command/list.js +26 -26
- package/lib/command/run-multiple/chunk.js +5 -5
- package/lib/command/run-multiple/collection.js +3 -3
- package/lib/command/run-multiple/run.js +2 -6
- package/lib/command/run-multiple.js +93 -113
- package/lib/command/run-rerun.js +25 -20
- package/lib/command/run-workers.js +66 -64
- package/lib/command/run.js +29 -26
- package/lib/command/utils.js +65 -80
- package/lib/command/workers/runTests.js +10 -10
- package/lib/config.js +9 -10
- package/lib/container.js +48 -40
- package/lib/data/context.js +59 -60
- package/lib/data/dataScenarioConfig.js +47 -47
- package/lib/data/dataTableArgument.js +29 -29
- package/lib/data/table.js +20 -26
- package/lib/dirname.js +5 -0
- package/lib/event.js +167 -163
- package/lib/heal.js +17 -13
- package/lib/helper/AI.js +41 -130
- package/lib/helper/ApiDataFactory.js +69 -73
- package/lib/helper/Appium.js +381 -412
- package/lib/helper/Expect.js +425 -0
- package/lib/helper/ExpectHelper.js +48 -40
- package/lib/helper/FileSystem.js +79 -80
- package/lib/helper/GraphQL.js +43 -44
- package/lib/helper/GraphQLDataFactory.js +50 -50
- package/lib/helper/JSONResponse.js +62 -65
- package/lib/helper/Mochawesome.js +28 -28
- package/lib/helper/MockServer.js +14 -12
- package/lib/helper/Nightmare.js +566 -662
- package/lib/helper/Playwright.js +1216 -1361
- package/lib/helper/Protractor.js +627 -663
- package/lib/helper/Puppeteer.js +1128 -1231
- package/lib/helper/REST.js +68 -159
- package/lib/helper/SoftExpectHelper.js +2 -2
- package/lib/helper/TestCafe.js +484 -490
- package/lib/helper/WebDriver.js +1156 -1297
- package/lib/helper/clientscripts/PollyWebDriverExt.js +1 -1
- package/lib/helper/errors/ConnectionRefused.js +1 -1
- package/lib/helper/errors/ElementAssertion.js +2 -2
- package/lib/helper/errors/ElementNotFound.js +2 -2
- package/lib/helper/errors/RemoteBrowserConnectionRefused.js +1 -1
- package/lib/helper/extras/Console.js +1 -1
- package/lib/helper/extras/PlaywrightPropEngine.js +2 -2
- package/lib/helper/extras/PlaywrightReactVueLocator.js +1 -1
- package/lib/helper/extras/PlaywrightRestartOpts.js +18 -21
- package/lib/helper/extras/Popup.js +1 -1
- package/lib/helper/extras/React.js +3 -3
- package/lib/helper/network/actions.js +7 -14
- package/lib/helper/network/utils.js +2 -3
- package/lib/helper/scripts/blurElement.js +1 -1
- package/lib/helper/scripts/focusElement.js +1 -1
- package/lib/helper/scripts/highlightElement.js +1 -1
- package/lib/helper/scripts/isElementClickable.js +1 -1
- package/lib/helper/testcafe/testControllerHolder.js +1 -1
- package/lib/helper/testcafe/testcafe-utils.js +7 -6
- package/lib/helper.js +3 -1
- package/lib/history.js +5 -6
- package/lib/hooks.js +6 -6
- package/lib/html.js +7 -7
- package/lib/index.js +41 -25
- package/lib/interfaces/bdd.js +64 -47
- package/lib/interfaces/featureConfig.js +19 -19
- package/lib/interfaces/gherkin.js +118 -124
- package/lib/interfaces/scenarioConfig.js +29 -29
- package/lib/listener/artifacts.js +9 -9
- package/lib/listener/config.js +24 -24
- package/lib/listener/exit.js +12 -12
- package/lib/listener/helpers.js +42 -42
- package/lib/listener/mocha.js +11 -11
- package/lib/listener/retry.js +30 -32
- package/lib/listener/steps.js +53 -50
- package/lib/listener/timeout.js +54 -54
- package/lib/locator.js +10 -6
- package/lib/mochaFactory.js +15 -18
- package/lib/output.js +10 -6
- package/lib/parser.js +12 -15
- package/lib/pause.js +33 -40
- package/lib/plugin/allure.js +15 -15
- package/lib/plugin/autoDelay.js +37 -29
- package/lib/plugin/autoLogin.js +65 -70
- package/lib/plugin/commentStep.js +18 -18
- package/lib/plugin/coverage.js +67 -115
- package/lib/plugin/customLocator.js +20 -21
- package/lib/plugin/debugErrors.js +24 -24
- package/lib/plugin/eachElement.js +38 -38
- package/lib/plugin/fakerTransform.js +6 -6
- package/lib/plugin/heal.js +108 -67
- package/lib/plugin/pauseOnFail.js +11 -11
- package/lib/plugin/retryFailedStep.js +39 -32
- package/lib/plugin/retryTo.js +40 -46
- package/lib/plugin/screenshotOnFail.js +87 -109
- package/lib/plugin/selenoid.js +118 -131
- package/lib/plugin/standardActingHelpers.js +8 -2
- package/lib/plugin/stepByStepReport.js +91 -110
- package/lib/plugin/stepTimeout.js +23 -24
- package/lib/plugin/subtitles.js +35 -34
- package/lib/plugin/tryTo.js +30 -40
- package/lib/plugin/wdio.js +75 -78
- package/lib/recorder.js +17 -14
- package/lib/rerun.js +10 -11
- package/lib/scenario.js +23 -25
- package/lib/secret.js +2 -4
- package/lib/session.js +10 -10
- package/lib/step.js +9 -12
- package/lib/store.js +3 -2
- package/lib/transform.js +1 -1
- package/lib/translation.js +8 -7
- package/lib/ui.js +14 -12
- package/lib/utils.js +72 -70
- package/lib/within.js +10 -10
- package/lib/workerStorage.js +25 -27
- package/lib/workers.js +32 -29
- package/package.json +53 -51
- package/translations/de-DE.js +1 -1
- package/translations/fr-FR.js +1 -1
- package/translations/index.js +13 -9
- package/translations/it-IT.js +1 -1
- package/translations/ja-JP.js +1 -1
- package/translations/pl-PL.js +1 -1
- package/translations/pt-BR.js +1 -1
- package/translations/ru-RU.js +1 -1
- package/translations/zh-CN.js +1 -1
- package/translations/zh-TW.js +1 -1
- package/typings/index.d.ts +65 -415
- package/typings/promiseBasedTypes.d.ts +32 -0
- package/typings/types.d.ts +32 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
33
|
+
export {
|
|
34
34
|
seeElementError,
|
|
35
35
|
dontSeeElementError,
|
|
36
36
|
seeElementInDOMError,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
19
|
+
export default ElementNotFound;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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.
|
|
@@ -6,28 +6,25 @@ const RESTART_OPTS = {
|
|
|
6
6
|
|
|
7
7
|
let restarts = null;
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
export function setRestartStrategy(options) {
|
|
10
|
+
const { restart } = options;
|
|
11
|
+
const stringOpts = Object.keys(RESTART_OPTS);
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
if (stringOpts.includes(restart)) {
|
|
14
|
+
return restarts = restart;
|
|
15
|
+
}
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
return restarts = restart;
|
|
17
|
-
}
|
|
17
|
+
restarts = Object.keys(RESTART_OPTS).find(key => RESTART_OPTS[key] === restart);
|
|
18
18
|
|
|
19
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
2
|
|
|
3
3
|
let resqScript;
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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
|
-
|
|
180
|
+
export {
|
|
181
181
|
createAdvancedTestResults,
|
|
182
182
|
extractQueryObjects,
|
|
183
183
|
allParameterValuePairsMatchExtreme,
|
|
184
184
|
allRequestPostDataValuePairsMatchExtreme,
|
|
185
|
-
getTrafficDump,
|
|
186
185
|
isInTraffic,
|
|
187
186
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
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
|
|
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
|
-
|
|
59
|
+
export default {
|
|
59
60
|
createTestFile,
|
|
60
61
|
mapError,
|
|
61
62
|
createClientFunction,
|
package/lib/helper.js
CHANGED
package/lib/history.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
51
|
+
export default new ReplHistory();
|
package/lib/hooks.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { isFunction, isAsyncFunction } from './utils.js';
|
|
2
|
+
import * as output from './output.js';
|
|
3
3
|
|
|
4
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
34
|
+
output,
|
|
15
35
|
/** @type {typeof CodeceptJS.Container} */
|
|
16
|
-
container
|
|
36
|
+
container,
|
|
17
37
|
/** @type {typeof CodeceptJS.event} */
|
|
18
|
-
event
|
|
38
|
+
event,
|
|
19
39
|
/** @type {CodeceptJS.recorder} */
|
|
20
|
-
recorder
|
|
40
|
+
recorder,
|
|
21
41
|
/** @type {typeof CodeceptJS.Config} */
|
|
22
|
-
config
|
|
42
|
+
config,
|
|
23
43
|
/** @type {CodeceptJS.actor} */
|
|
24
|
-
actor
|
|
44
|
+
actor,
|
|
25
45
|
/** @type {typeof CodeceptJS.Helper} */
|
|
26
|
-
helper
|
|
27
|
-
/** @type {typeof CodeceptJS.Helper} */
|
|
28
|
-
Helper: require('./helper'),
|
|
46
|
+
helper,
|
|
29
47
|
/** @type {typeof CodeceptJS.pause} */
|
|
30
|
-
pause
|
|
48
|
+
pause,
|
|
31
49
|
/** @type {typeof CodeceptJS.within} */
|
|
32
|
-
within
|
|
50
|
+
within,
|
|
33
51
|
/** @type {typeof CodeceptJS.DataTable} */
|
|
34
|
-
dataTable
|
|
52
|
+
dataTable,
|
|
35
53
|
/** @type {typeof CodeceptJS.DataTableArgument} */
|
|
36
|
-
dataTableArgument
|
|
54
|
+
dataTableArgument,
|
|
37
55
|
/** @type {typeof CodeceptJS.store} */
|
|
38
|
-
store
|
|
56
|
+
store,
|
|
39
57
|
/** @type {typeof CodeceptJS.Locator} */
|
|
40
|
-
locator
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
Workers: require('./workers'),
|
|
58
|
+
locator,
|
|
59
|
+
heal,
|
|
60
|
+
ai,
|
|
61
|
+
workers,
|
|
46
62
|
};
|
package/lib/interfaces/bdd.js
CHANGED
|
@@ -1,81 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
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(
|
|
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 = ({
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
+
};
|