codeceptjs 4.0.0-beta.1 → 4.0.0-beta.3
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 +84 -81
- package/lib/actor.js +13 -13
- package/lib/ai.js +10 -13
- package/lib/assert/empty.js +20 -21
- package/lib/assert/equal.js +37 -39
- package/lib/assert/error.js +14 -14
- package/lib/assert/include.js +46 -47
- package/lib/assert/throws.js +13 -11
- package/lib/assert/truth.js +19 -22
- package/lib/assert.js +4 -2
- package/lib/cli.js +57 -49
- package/lib/codecept.js +142 -155
- package/lib/colorUtils.js +3 -3
- package/lib/command/configMigrate.js +58 -52
- package/lib/command/definitions.js +88 -89
- package/lib/command/dryRun.js +71 -68
- package/lib/command/generate.js +197 -188
- package/lib/command/gherkin/init.js +27 -16
- package/lib/command/gherkin/snippets.js +20 -20
- package/lib/command/gherkin/steps.js +8 -8
- package/lib/command/info.js +40 -38
- package/lib/command/init.js +290 -288
- 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 +6 -2
- package/lib/command/run-multiple.js +113 -93
- package/lib/command/run-rerun.js +20 -25
- package/lib/command/run-workers.js +64 -66
- package/lib/command/run.js +26 -29
- package/lib/command/utils.js +80 -65
- package/lib/command/workers/runTests.js +10 -10
- package/lib/config.js +10 -9
- package/lib/container.js +40 -48
- package/lib/data/context.js +60 -59
- package/lib/data/dataScenarioConfig.js +47 -47
- package/lib/data/dataTableArgument.js +29 -29
- package/lib/data/table.js +26 -20
- package/lib/event.js +163 -167
- package/lib/heal.js +13 -17
- package/lib/helper/AI.js +130 -41
- package/lib/helper/ApiDataFactory.js +73 -69
- package/lib/helper/Appium.js +413 -382
- package/lib/helper/ExpectHelper.js +40 -48
- package/lib/helper/FileSystem.js +80 -79
- package/lib/helper/GraphQL.js +44 -43
- package/lib/helper/GraphQLDataFactory.js +50 -50
- package/lib/helper/JSONResponse.js +65 -62
- package/lib/helper/Mochawesome.js +28 -28
- package/lib/helper/MockServer.js +12 -14
- package/lib/helper/Nightmare.js +662 -566
- package/lib/helper/Playwright.js +1361 -1216
- package/lib/helper/Protractor.js +663 -627
- package/lib/helper/Puppeteer.js +1231 -1128
- package/lib/helper/REST.js +159 -68
- package/lib/helper/SoftExpectHelper.js +2 -2
- package/lib/helper/TestCafe.js +490 -484
- package/lib/helper/WebDriver.js +1297 -1156
- 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 +21 -18
- package/lib/helper/extras/Popup.js +1 -1
- package/lib/helper/extras/React.js +3 -3
- package/lib/helper/network/actions.js +14 -7
- package/lib/helper/network/utils.js +3 -2
- 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 +6 -7
- package/lib/helper.js +1 -3
- package/lib/history.js +6 -5
- package/lib/hooks.js +6 -6
- package/lib/html.js +7 -7
- package/lib/index.js +25 -41
- package/lib/interfaces/bdd.js +47 -64
- package/lib/interfaces/featureConfig.js +19 -19
- package/lib/interfaces/gherkin.js +124 -118
- 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 +32 -30
- package/lib/listener/steps.js +50 -53
- package/lib/listener/timeout.js +54 -54
- package/lib/locator.js +6 -10
- package/lib/mochaFactory.js +18 -15
- package/lib/output.js +6 -10
- package/lib/parser.js +15 -12
- package/lib/pause.js +40 -33
- package/lib/plugin/allure.js +15 -15
- package/lib/plugin/autoDelay.js +29 -37
- package/lib/plugin/autoLogin.js +70 -65
- package/lib/plugin/commentStep.js +18 -18
- package/lib/plugin/coverage.js +115 -67
- package/lib/plugin/customLocator.js +21 -20
- 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 +67 -108
- package/lib/plugin/pauseOnFail.js +11 -11
- package/lib/plugin/retryFailedStep.js +32 -39
- package/lib/plugin/retryTo.js +46 -40
- package/lib/plugin/screenshotOnFail.js +109 -87
- package/lib/plugin/selenoid.js +131 -118
- package/lib/plugin/standardActingHelpers.js +2 -8
- package/lib/plugin/stepByStepReport.js +110 -91
- package/lib/plugin/stepTimeout.js +24 -23
- package/lib/plugin/subtitles.js +34 -35
- package/lib/plugin/tryTo.js +40 -30
- package/lib/plugin/wdio.js +78 -75
- package/lib/recorder.js +14 -17
- package/lib/rerun.js +11 -10
- package/lib/scenario.js +25 -23
- package/lib/secret.js +4 -2
- package/lib/session.js +10 -10
- package/lib/step.js +12 -9
- package/lib/store.js +2 -3
- package/lib/transform.js +1 -1
- package/lib/translation.js +7 -8
- package/lib/ui.js +12 -14
- package/lib/utils.js +70 -72
- package/lib/within.js +10 -10
- package/lib/workerStorage.js +27 -25
- package/lib/workers.js +29 -32
- package/package.json +56 -57
- package/translations/de-DE.js +1 -1
- package/translations/fr-FR.js +1 -1
- package/translations/index.js +9 -13
- 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 +415 -65
- package/typings/promiseBasedTypes.d.ts +32 -0
- package/typings/types.d.ts +32 -0
- package/lib/dirname.js +0 -5
- package/lib/helper/Expect.js +0 -425
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const Locator = require('../../locator');
|
|
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
|
+
module.exports = {
|
|
34
34
|
seeElementError,
|
|
35
35
|
dontSeeElementError,
|
|
36
36
|
seeElementInDOMError,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const Locator = require('../../locator');
|
|
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
|
+
module.exports = ElementNotFound;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
module.exports.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 @@ export const createValueEngine = () => {
|
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
module.exports.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,25 +6,28 @@ const RESTART_OPTS = {
|
|
|
6
6
|
|
|
7
7
|
let restarts = null;
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
const { restart } = options;
|
|
11
|
-
const stringOpts = Object.keys(RESTART_OPTS);
|
|
9
|
+
module.exports = {
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
setRestartStrategy(options) {
|
|
12
|
+
const { restart } = options;
|
|
13
|
+
const stringOpts = Object.keys(RESTART_OPTS);
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
if (stringOpts.includes(restart)) {
|
|
16
|
+
return restarts = restart;
|
|
17
|
+
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
}
|
|
19
|
+
restarts = Object.keys(RESTART_OPTS).find(key => RESTART_OPTS[key] === restart);
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
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
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
const fs = require('fs');
|
|
2
2
|
|
|
3
3
|
let resqScript;
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
module.exports = 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 @@ export default async function findReact(matcher, locator) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
return result;
|
|
66
|
-
}
|
|
66
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
const { isInTraffic, createAdvancedTestResults, getTrafficDump } = require('./utils');
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
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 @@ export function dontSeeTraffic({ name, url }) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
async function seeTraffic({
|
|
23
23
|
name, url, parameters, requestPostData, timeout = 10,
|
|
24
24
|
}) {
|
|
25
25
|
if (!name) {
|
|
@@ -65,7 +65,7 @@ export async function seeTraffic({
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
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,13 +104,20 @@ export async function grabRecordedNetworkTraffics() {
|
|
|
104
104
|
return Promise.all(promises);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
function stopRecordingTraffic() {
|
|
108
108
|
// @ts-ignore
|
|
109
109
|
this.page.removeAllListeners('request');
|
|
110
110
|
this.recording = false;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
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
|
-
|
|
138
|
+
function getTrafficDump() {
|
|
139
139
|
let dumpedTraffic = '';
|
|
140
140
|
this.requests.forEach((request) => {
|
|
141
141
|
dumpedTraffic += `${request.method} - ${request.url}\n`;
|
|
@@ -177,10 +177,11 @@ function isInTraffic(url, parameters) {
|
|
|
177
177
|
return isInTraffic;
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
|
|
180
|
+
module.exports = {
|
|
181
181
|
createAdvancedTestResults,
|
|
182
182
|
extractQueryObjects,
|
|
183
183
|
allParameterValuePairsMatchExtreme,
|
|
184
184
|
allRequestPostDataValuePairsMatchExtreme,
|
|
185
|
+
getTrafficDump,
|
|
185
186
|
isInTraffic,
|
|
186
187
|
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import assert from 'assert';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { getParamNames } from '../../utils.js';
|
|
1
|
+
const { ClientFunction } = require('testcafe');
|
|
6
2
|
|
|
7
|
-
const
|
|
3
|
+
const assert = require('assert');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { getParamNames } = require('../../utils');
|
|
8
7
|
|
|
9
8
|
const createTestFile = () => {
|
|
10
9
|
assert(global.output_dir, 'global.output_dir must be set');
|
|
@@ -56,7 +55,7 @@ function getFuncBody(func) {
|
|
|
56
55
|
// TODO: support general functions
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
|
|
58
|
+
module.exports = {
|
|
60
59
|
createTestFile,
|
|
61
60
|
mapError,
|
|
62
61
|
createClientFunction,
|
package/lib/helper.js
CHANGED
package/lib/history.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
const colors = require('chalk');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
const output = require('./output');
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* REPL history records REPL commands and stores them in
|
|
@@ -48,4 +49,4 @@ class ReplHistory {
|
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
module.exports = new ReplHistory();
|
package/lib/hooks.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const { isFunction, isAsyncFunction } = require('./utils');
|
|
2
|
+
const output = require('./output');
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
module.exports = 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.
|
|
10
|
+
if (stage) 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.
|
|
17
|
-
}
|
|
16
|
+
if (stage) output.log(`finished ${stage} hook`);
|
|
17
|
+
};
|
package/lib/html.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const { parse, serialize } = require('parse5');
|
|
2
|
+
const { minify } = require('html-minifier-terser');
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
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
|
-
|
|
24
|
+
function removeNonInteractiveElements(html, opts = {}) {
|
|
25
25
|
opts = { ...defaultHtmlOpts, ...opts };
|
|
26
26
|
const {
|
|
27
27
|
interactiveElements,
|
|
@@ -142,7 +142,7 @@ export function removeNonInteractiveElements(html, opts = {}) {
|
|
|
142
142
|
return serializedHTML;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
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
|
-
|
|
219
|
+
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 @@ export function splitByChunks(text, chunkSize) {
|
|
|
250
250
|
return chunks.map(chunk => chunk.trim());
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
|
|
253
|
+
module.exports = {
|
|
254
254
|
scanForErrorMessages,
|
|
255
255
|
removeNonInteractiveElements,
|
|
256
256
|
splitByChunks,
|
package/lib/index.js
CHANGED
|
@@ -1,20 +1,3 @@
|
|
|
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';
|
|
18
1
|
/**
|
|
19
2
|
* Index file for loading CodeceptJS programmatically.
|
|
20
3
|
*
|
|
@@ -22,41 +5,42 @@ import * as ai from './ai.js';
|
|
|
22
5
|
* @alias index
|
|
23
6
|
* @namespace
|
|
24
7
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export { helper as Helper };
|
|
31
|
-
export { workers as Workers };
|
|
32
|
-
export {
|
|
8
|
+
module.exports = {
|
|
9
|
+
/** @type {typeof CodeceptJS.Codecept} */
|
|
10
|
+
codecept: require('./codecept'),
|
|
11
|
+
/** @type {typeof CodeceptJS.Codecept} */
|
|
12
|
+
Codecept: require('./codecept'),
|
|
33
13
|
/** @type {typeof CodeceptJS.output} */
|
|
34
|
-
output,
|
|
14
|
+
output: require('./output'),
|
|
35
15
|
/** @type {typeof CodeceptJS.Container} */
|
|
36
|
-
container,
|
|
16
|
+
container: require('./container'),
|
|
37
17
|
/** @type {typeof CodeceptJS.event} */
|
|
38
|
-
event,
|
|
18
|
+
event: require('./event'),
|
|
39
19
|
/** @type {CodeceptJS.recorder} */
|
|
40
|
-
recorder,
|
|
20
|
+
recorder: require('./recorder'),
|
|
41
21
|
/** @type {typeof CodeceptJS.Config} */
|
|
42
|
-
config,
|
|
22
|
+
config: require('./config'),
|
|
43
23
|
/** @type {CodeceptJS.actor} */
|
|
44
|
-
actor,
|
|
24
|
+
actor: require('./actor'),
|
|
45
25
|
/** @type {typeof CodeceptJS.Helper} */
|
|
46
|
-
helper,
|
|
26
|
+
helper: require('./helper'),
|
|
27
|
+
/** @type {typeof CodeceptJS.Helper} */
|
|
28
|
+
Helper: require('./helper'),
|
|
47
29
|
/** @type {typeof CodeceptJS.pause} */
|
|
48
|
-
pause,
|
|
30
|
+
pause: require('./pause'),
|
|
49
31
|
/** @type {typeof CodeceptJS.within} */
|
|
50
|
-
within,
|
|
32
|
+
within: require('./within'),
|
|
51
33
|
/** @type {typeof CodeceptJS.DataTable} */
|
|
52
|
-
dataTable,
|
|
34
|
+
dataTable: require('./data/table'),
|
|
53
35
|
/** @type {typeof CodeceptJS.DataTableArgument} */
|
|
54
|
-
dataTableArgument,
|
|
36
|
+
dataTableArgument: require('./data/dataTableArgument'),
|
|
55
37
|
/** @type {typeof CodeceptJS.store} */
|
|
56
|
-
store,
|
|
38
|
+
store: require('./store'),
|
|
57
39
|
/** @type {typeof CodeceptJS.Locator} */
|
|
58
|
-
locator,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
40
|
+
locator: require('./locator'),
|
|
41
|
+
|
|
42
|
+
heal: require('./heal'),
|
|
43
|
+
ai: require('./ai'),
|
|
44
|
+
|
|
45
|
+
Workers: require('./workers'),
|
|
62
46
|
};
|
package/lib/interfaces/bdd.js
CHANGED
|
@@ -1,98 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const { CucumberExpression, ParameterTypeRegistry, ParameterType } = require('@cucumber/cucumber-expressions')
|
|
2
|
+
const Config = require('../config')
|
|
3
3
|
|
|
4
|
-
let steps = {}
|
|
5
|
-
const codecept_dir = '';
|
|
4
|
+
let steps = {}
|
|
6
5
|
|
|
7
|
-
const STACK_POSITION = 2
|
|
6
|
+
const STACK_POSITION = 2
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* @param {*} step
|
|
11
10
|
* @param {*} fn
|
|
12
11
|
*/
|
|
13
12
|
const addStep = (step, fn) => {
|
|
14
|
-
const avoidDuplicateSteps = Config.get('gherkin', {}).avoidDuplicateSteps || false
|
|
15
|
-
const stack =
|
|
13
|
+
const avoidDuplicateSteps = Config.get('gherkin', {}).avoidDuplicateSteps || false
|
|
14
|
+
const stack = new Error().stack
|
|
16
15
|
if (avoidDuplicateSteps && steps[step]) {
|
|
17
|
-
throw new Error(`Step '${step}' is already defined`)
|
|
16
|
+
throw new Error(`Step '${step}' is already defined`)
|
|
18
17
|
}
|
|
19
|
-
steps[step] = fn
|
|
20
|
-
fn.line = stack && stack.split('\n')[STACK_POSITION]
|
|
18
|
+
steps[step] = fn
|
|
19
|
+
fn.line = stack && stack.split('\n')[STACK_POSITION]
|
|
21
20
|
if (fn.line) {
|
|
22
21
|
fn.line = fn.line
|
|
23
22
|
.trim()
|
|
24
23
|
.replace(/^at (.*?)\(/, '(')
|
|
25
|
-
.replace(codecept_dir, '.')
|
|
24
|
+
.replace(codecept_dir, '.')
|
|
26
25
|
}
|
|
27
|
-
}
|
|
26
|
+
}
|
|
28
27
|
|
|
29
|
-
const parameterTypeRegistry = new ParameterTypeRegistry()
|
|
28
|
+
const parameterTypeRegistry = new ParameterTypeRegistry()
|
|
30
29
|
|
|
31
|
-
|
|
30
|
+
const matchStep = (step) => {
|
|
32
31
|
for (const stepName in steps) {
|
|
33
32
|
if (stepName.indexOf('/') === 0) {
|
|
34
|
-
const regExpArr = stepName.match(/^\/(.*?)\/([gimy]*)$/) || []
|
|
35
|
-
const res = step.match(new RegExp(regExpArr[1], regExpArr[2]))
|
|
33
|
+
const regExpArr = stepName.match(/^\/(.*?)\/([gimy]*)$/) || []
|
|
34
|
+
const res = step.match(new RegExp(regExpArr[1], regExpArr[2]))
|
|
36
35
|
if (res) {
|
|
37
|
-
const fn = steps[stepName]
|
|
38
|
-
fn.params = res.slice(1)
|
|
39
|
-
return fn
|
|
36
|
+
const fn = steps[stepName]
|
|
37
|
+
fn.params = res.slice(1)
|
|
38
|
+
return fn
|
|
40
39
|
}
|
|
41
|
-
continue
|
|
40
|
+
continue
|
|
42
41
|
}
|
|
43
|
-
const expression = new CucumberExpression(stepName, parameterTypeRegistry)
|
|
44
|
-
|
|
45
|
-
// console.log((step))
|
|
46
|
-
const res = expression.match(step);
|
|
42
|
+
const expression = new CucumberExpression(stepName, parameterTypeRegistry)
|
|
43
|
+
const res = expression.match(step)
|
|
47
44
|
if (res) {
|
|
48
|
-
const fn = steps[stepName]
|
|
49
|
-
fn.params = res.map(arg => arg.getValue())
|
|
50
|
-
return fn
|
|
45
|
+
const fn = steps[stepName]
|
|
46
|
+
fn.params = res.map((arg) => arg.getValue())
|
|
47
|
+
return fn
|
|
51
48
|
}
|
|
52
49
|
}
|
|
53
|
-
throw new Error(`No steps matching "${step.toString()}"`)
|
|
54
|
-
}
|
|
50
|
+
throw new Error(`No steps matching "${step.toString()}"`)
|
|
51
|
+
}
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
steps = {}
|
|
58
|
-
}
|
|
53
|
+
const clearSteps = () => {
|
|
54
|
+
steps = {}
|
|
55
|
+
}
|
|
59
56
|
|
|
60
|
-
|
|
61
|
-
return steps
|
|
62
|
-
}
|
|
57
|
+
const getSteps = () => {
|
|
58
|
+
return steps
|
|
59
|
+
}
|
|
63
60
|
|
|
64
|
-
|
|
65
|
-
const parameterType = buildParameterType(options)
|
|
66
|
-
parameterTypeRegistry.defineParameterType(parameterType)
|
|
67
|
-
}
|
|
61
|
+
const defineParameterType = (options) => {
|
|
62
|
+
const parameterType = buildParameterType(options)
|
|
63
|
+
parameterTypeRegistry.defineParameterType(parameterType)
|
|
64
|
+
}
|
|
68
65
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
transformer,
|
|
73
|
-
|
|
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
|
-
};
|
|
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
|
+
}
|
|
87
71
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
export default {
|
|
72
|
+
module.exports = {
|
|
73
|
+
Given: addStep,
|
|
74
|
+
When: addStep,
|
|
75
|
+
Then: addStep,
|
|
76
|
+
And: addStep,
|
|
94
77
|
matchStep,
|
|
95
78
|
getSteps,
|
|
96
79
|
clearSteps,
|
|
97
80
|
defineParameterType,
|
|
98
|
-
}
|
|
81
|
+
}
|