codeceptjs 3.6.7 → 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
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { getConfig, getTestRoot } from './utils.js';
|
|
4
|
+
import Codecept from '../codecept.js';
|
|
5
|
+
import container from '../container.js';
|
|
6
|
+
import * as output from '../output.js';
|
|
7
|
+
import plugin from '../plugin/standardActingHelpers.js';
|
|
3
8
|
|
|
4
|
-
const
|
|
5
|
-
const Codecept = require('../codecept')
|
|
6
|
-
const container = require('../container')
|
|
7
|
-
const output = require('../output')
|
|
8
|
-
const actingHelpers = [...require('../plugin/standardActingHelpers'), 'REST']
|
|
9
|
+
const actingHelpers = [...(plugin), 'REST'];
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Prepare data and generate content of definitions file
|
|
@@ -29,27 +30,32 @@ const getDefinitionsFileContent = ({
|
|
|
29
30
|
importPaths,
|
|
30
31
|
translations,
|
|
31
32
|
}) => {
|
|
32
|
-
const getHelperListFragment = ({
|
|
33
|
+
const getHelperListFragment = ({
|
|
34
|
+
hasCustomHelper,
|
|
35
|
+
hasCustomStepsFile,
|
|
36
|
+
}) => {
|
|
33
37
|
if (hasCustomHelper && hasCustomStepsFile) {
|
|
34
|
-
return `${['ReturnType<steps_file>', 'WithTranslation<Methods>'].join(', ')}
|
|
38
|
+
return `${['ReturnType<steps_file>', 'WithTranslation<Methods>'].join(', ')}`;
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
if (hasCustomStepsFile) {
|
|
38
|
-
return 'ReturnType<steps_file>'
|
|
42
|
+
return 'ReturnType<steps_file>';
|
|
39
43
|
}
|
|
40
44
|
|
|
41
|
-
return 'WithTranslation<Methods>'
|
|
42
|
-
}
|
|
45
|
+
return 'WithTranslation<Methods>';
|
|
46
|
+
};
|
|
43
47
|
|
|
44
48
|
const helpersListFragment = getHelperListFragment({
|
|
45
49
|
hasCustomHelper,
|
|
46
50
|
hasCustomStepsFile,
|
|
47
|
-
})
|
|
51
|
+
});
|
|
48
52
|
|
|
49
|
-
const importPathsFragment = importPaths.join('\n')
|
|
50
|
-
const supportObjectsTypeFragment = convertMapToType(supportObject)
|
|
51
|
-
const methodsTypeFragment = helperNames.length > 0
|
|
52
|
-
|
|
53
|
+
const importPathsFragment = importPaths.join('\n');
|
|
54
|
+
const supportObjectsTypeFragment = convertMapToType(supportObject);
|
|
55
|
+
const methodsTypeFragment = helperNames.length > 0
|
|
56
|
+
? `interface Methods extends ${helperNames.join(', ')} {}`
|
|
57
|
+
: '';
|
|
58
|
+
const translatedActionsFragment = JSON.stringify(translations.vocabulary.actions, null, 2);
|
|
53
59
|
|
|
54
60
|
return generateDefinitionsContent({
|
|
55
61
|
helpersListFragment,
|
|
@@ -57,8 +63,8 @@ const getDefinitionsFileContent = ({
|
|
|
57
63
|
supportObjectsTypeFragment,
|
|
58
64
|
methodsTypeFragment,
|
|
59
65
|
translatedActionsFragment,
|
|
60
|
-
})
|
|
61
|
-
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
62
68
|
|
|
63
69
|
/**
|
|
64
70
|
* Generate content for definitions file from fragments
|
|
@@ -91,83 +97,83 @@ declare namespace CodeceptJS {
|
|
|
91
97
|
interface Actions ${translatedActionsFragment}
|
|
92
98
|
}
|
|
93
99
|
}
|
|
94
|
-
|
|
95
|
-
}
|
|
100
|
+
`;
|
|
101
|
+
};
|
|
96
102
|
|
|
97
103
|
/** @type {Array<string>} */
|
|
98
|
-
const helperNames = []
|
|
104
|
+
const helperNames = [];
|
|
99
105
|
/** @type {Array<string>} */
|
|
100
|
-
const customHelpers = []
|
|
106
|
+
const customHelpers = [];
|
|
101
107
|
|
|
102
|
-
|
|
103
|
-
const configFile = options.config || genPath
|
|
108
|
+
export default function (genPath, options) {
|
|
109
|
+
const configFile = options.config || genPath;
|
|
104
110
|
/** @type {string} */
|
|
105
|
-
const testsPath = getTestRoot(configFile)
|
|
106
|
-
const config = getConfig(configFile)
|
|
107
|
-
if (!config) return
|
|
111
|
+
const testsPath = getTestRoot(configFile);
|
|
112
|
+
const config = getConfig(configFile);
|
|
113
|
+
if (!config) return;
|
|
108
114
|
|
|
109
115
|
/** @type {Object<string, string>} */
|
|
110
|
-
const helperPaths = {}
|
|
116
|
+
const helperPaths = {};
|
|
111
117
|
/** @type {Object<string, string>} */
|
|
112
|
-
const supportPaths = {}
|
|
118
|
+
const supportPaths = {};
|
|
113
119
|
/** @type {boolean} */
|
|
114
|
-
let hasCustomStepsFile = false
|
|
120
|
+
let hasCustomStepsFile = false;
|
|
115
121
|
/** @type {boolean} */
|
|
116
|
-
let hasCustomHelper = false
|
|
122
|
+
let hasCustomHelper = false;
|
|
117
123
|
|
|
118
124
|
/** @type {string} */
|
|
119
|
-
const targetFolderPath =
|
|
125
|
+
const targetFolderPath = options.output && getTestRoot(options.output) || testsPath;
|
|
120
126
|
|
|
121
|
-
const codecept = new Codecept(config, {})
|
|
122
|
-
codecept.init(testsPath)
|
|
127
|
+
const codecept = new Codecept(config, {});
|
|
128
|
+
codecept.init(testsPath);
|
|
123
129
|
|
|
124
|
-
const helpers = container.helpers()
|
|
125
|
-
const translations = container.translation()
|
|
130
|
+
const helpers = container.helpers();
|
|
131
|
+
const translations = container.translation();
|
|
126
132
|
for (const name in helpers) {
|
|
127
|
-
const require = codecept.config.helpers[name].require
|
|
133
|
+
const require = codecept.config.helpers[name].require;
|
|
128
134
|
if (require) {
|
|
129
|
-
helperPaths[name] = require
|
|
130
|
-
helperNames.push(name)
|
|
135
|
+
helperPaths[name] = require;
|
|
136
|
+
helperNames.push(name);
|
|
131
137
|
} else {
|
|
132
|
-
const fullBasedPromised = codecept.config.fullPromiseBased
|
|
133
|
-
helperNames.push(fullBasedPromised === true ? `${name}Ts` : name)
|
|
138
|
+
const fullBasedPromised = codecept.config.fullPromiseBased;
|
|
139
|
+
helperNames.push(fullBasedPromised === true ? `${name}Ts` : name);
|
|
134
140
|
}
|
|
135
141
|
|
|
136
142
|
if (!actingHelpers.includes(name)) {
|
|
137
|
-
customHelpers.push(name)
|
|
143
|
+
customHelpers.push(name);
|
|
138
144
|
}
|
|
139
145
|
}
|
|
140
146
|
|
|
141
|
-
let autoLogin
|
|
147
|
+
let autoLogin;
|
|
142
148
|
if (config.plugins.autoLogin) {
|
|
143
|
-
autoLogin = config.plugins.autoLogin.inject
|
|
149
|
+
autoLogin = config.plugins.autoLogin.inject;
|
|
144
150
|
}
|
|
145
151
|
|
|
146
|
-
const supportObject = new Map()
|
|
147
|
-
supportObject.set('I', 'I')
|
|
148
|
-
supportObject.set('current', 'any')
|
|
152
|
+
const supportObject = new Map();
|
|
153
|
+
supportObject.set('I', 'I');
|
|
154
|
+
supportObject.set('current', 'any');
|
|
149
155
|
|
|
150
156
|
if (translations.loaded) {
|
|
151
|
-
supportObject.set(translations.I, translations.I)
|
|
157
|
+
supportObject.set(translations.I, translations.I);
|
|
152
158
|
}
|
|
153
159
|
|
|
154
160
|
if (autoLogin) {
|
|
155
|
-
supportObject.set(autoLogin, 'any')
|
|
161
|
+
supportObject.set(autoLogin, 'any');
|
|
156
162
|
}
|
|
157
163
|
|
|
158
164
|
if (customHelpers.length > 0) {
|
|
159
|
-
hasCustomHelper = true
|
|
165
|
+
hasCustomHelper = true;
|
|
160
166
|
}
|
|
161
167
|
|
|
162
168
|
for (const name in codecept.config.include) {
|
|
163
|
-
const includePath = codecept.config.include[name]
|
|
169
|
+
const includePath = codecept.config.include[name];
|
|
164
170
|
if (name === 'I' || name === translations.I) {
|
|
165
|
-
hasCustomStepsFile = true
|
|
166
|
-
supportPaths.steps_file = includePath
|
|
167
|
-
continue
|
|
171
|
+
hasCustomStepsFile = true;
|
|
172
|
+
supportPaths.steps_file = includePath;
|
|
173
|
+
continue;
|
|
168
174
|
}
|
|
169
|
-
supportPaths[name] = includePath
|
|
170
|
-
supportObject.set(name, name)
|
|
175
|
+
supportPaths[name] = includePath;
|
|
176
|
+
supportObject.set(name, name);
|
|
171
177
|
}
|
|
172
178
|
|
|
173
179
|
let definitionsFileContent = getDefinitionsFileContent({
|
|
@@ -177,33 +183,30 @@ module.exports = function (genPath, options) {
|
|
|
177
183
|
translations,
|
|
178
184
|
hasCustomStepsFile,
|
|
179
185
|
hasCustomHelper,
|
|
180
|
-
})
|
|
186
|
+
});
|
|
181
187
|
|
|
182
188
|
// add aliases for translations
|
|
183
189
|
if (translations.loaded) {
|
|
184
|
-
const namespaceTranslationAliases = []
|
|
185
|
-
namespaceTranslationAliases.push(`interface ${translations.vocabulary.I} extends WithTranslation<Methods> {}`)
|
|
190
|
+
const namespaceTranslationAliases = [];
|
|
191
|
+
namespaceTranslationAliases.push(`interface ${translations.vocabulary.I} extends WithTranslation<Methods> {}`);
|
|
186
192
|
|
|
187
|
-
namespaceTranslationAliases.push(' namespace Translation {')
|
|
188
|
-
definitionsFileContent = definitionsFileContent.replace(
|
|
189
|
-
'namespace Translation {',
|
|
190
|
-
namespaceTranslationAliases.join('\n'),
|
|
191
|
-
)
|
|
193
|
+
namespaceTranslationAliases.push(' namespace Translation {');
|
|
194
|
+
definitionsFileContent = definitionsFileContent.replace('namespace Translation {', namespaceTranslationAliases.join('\n'));
|
|
192
195
|
|
|
193
|
-
const translationAliases = []
|
|
196
|
+
const translationAliases = [];
|
|
194
197
|
|
|
195
198
|
if (translations.vocabulary.contexts) {
|
|
196
|
-
Object.keys(translations.vocabulary.contexts).forEach(
|
|
197
|
-
translationAliases.push(`declare const ${translations.vocabulary.contexts[k]}: typeof ${k};`)
|
|
198
|
-
})
|
|
199
|
+
Object.keys(translations.vocabulary.contexts).forEach(k => {
|
|
200
|
+
translationAliases.push(`declare const ${translations.vocabulary.contexts[k]}: typeof ${k};`);
|
|
201
|
+
});
|
|
199
202
|
}
|
|
200
203
|
|
|
201
|
-
definitionsFileContent += `\n${translationAliases.join('\n')}
|
|
204
|
+
definitionsFileContent += `\n${translationAliases.join('\n')}`;
|
|
202
205
|
}
|
|
203
206
|
|
|
204
|
-
fs.writeFileSync(path.join(targetFolderPath, 'steps.d.ts'), definitionsFileContent)
|
|
205
|
-
output.print('TypeScript Definitions provide autocompletion in Visual Studio Code and other IDEs')
|
|
206
|
-
output.print('Definitions were generated in steps.d.ts')
|
|
207
|
+
fs.writeFileSync(path.join(targetFolderPath, 'steps.d.ts'), definitionsFileContent);
|
|
208
|
+
output.print('TypeScript Definitions provide autocompletion in Visual Studio Code and other IDEs');
|
|
209
|
+
output.print('Definitions were generated in steps.d.ts');
|
|
207
210
|
}
|
|
208
211
|
|
|
209
212
|
/**
|
|
@@ -213,13 +216,13 @@ module.exports = function (genPath, options) {
|
|
|
213
216
|
* @param {string} testsPath
|
|
214
217
|
*/
|
|
215
218
|
function getPath(originalPath, targetFolderPath, testsPath) {
|
|
216
|
-
const parsedPath = path.parse(originalPath)
|
|
219
|
+
const parsedPath = path.parse(originalPath);
|
|
217
220
|
|
|
218
221
|
// Remove typescript extension if exists.
|
|
219
|
-
if (parsedPath.base.endsWith('.d.ts')) parsedPath.base = parsedPath.base.substring(0, parsedPath.base.length - 5)
|
|
220
|
-
else if (parsedPath.ext === '.ts') parsedPath.base = parsedPath.name
|
|
222
|
+
if (parsedPath.base.endsWith('.d.ts')) parsedPath.base = parsedPath.base.substring(0, parsedPath.base.length - 5);
|
|
223
|
+
else if (parsedPath.ext === '.ts') parsedPath.base = parsedPath.name;
|
|
221
224
|
|
|
222
|
-
if (!parsedPath.dir.startsWith('.')) return path.posix.join(parsedPath.dir, parsedPath.base)
|
|
225
|
+
if (!parsedPath.dir.startsWith('.')) return path.posix.join(parsedPath.dir, parsedPath.base);
|
|
223
226
|
const relativePath = path.posix.relative(
|
|
224
227
|
targetFolderPath.split(path.sep).join(path.posix.sep),
|
|
225
228
|
path.posix.join(
|
|
@@ -227,9 +230,9 @@ function getPath(originalPath, targetFolderPath, testsPath) {
|
|
|
227
230
|
parsedPath.dir.split(path.sep).join(path.posix.sep),
|
|
228
231
|
parsedPath.base.split(path.sep).join(path.posix.sep),
|
|
229
232
|
),
|
|
230
|
-
)
|
|
233
|
+
);
|
|
231
234
|
|
|
232
|
-
return relativePath.startsWith('.') ? relativePath : `./${relativePath}
|
|
235
|
+
return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
|
|
233
236
|
}
|
|
234
237
|
|
|
235
238
|
/**
|
|
@@ -243,19 +246,19 @@ function getPath(originalPath, targetFolderPath, testsPath) {
|
|
|
243
246
|
* @returns {Array<string>}
|
|
244
247
|
*/
|
|
245
248
|
function getImportString(testsPath, targetFolderPath, pathsToType, pathsToValue) {
|
|
246
|
-
const importStrings = []
|
|
249
|
+
const importStrings = [];
|
|
247
250
|
|
|
248
251
|
for (const name in pathsToType) {
|
|
249
|
-
const relativePath = getPath(pathsToType[name], targetFolderPath, testsPath)
|
|
250
|
-
importStrings.push(`type ${name} = typeof import('${relativePath}');`)
|
|
252
|
+
const relativePath = getPath(pathsToType[name], targetFolderPath, testsPath);
|
|
253
|
+
importStrings.push(`type ${name} = typeof import('${relativePath}');`);
|
|
251
254
|
}
|
|
252
255
|
|
|
253
256
|
for (const name in pathsToValue) {
|
|
254
|
-
const relativePath = getPath(pathsToValue[name], targetFolderPath, testsPath)
|
|
255
|
-
importStrings.push(`type ${name} = import('${relativePath}');`)
|
|
257
|
+
const relativePath = getPath(pathsToValue[name], targetFolderPath, testsPath);
|
|
258
|
+
importStrings.push(`type ${name} = import('${relativePath}');`);
|
|
256
259
|
}
|
|
257
260
|
|
|
258
|
-
return importStrings
|
|
261
|
+
return importStrings;
|
|
259
262
|
}
|
|
260
263
|
|
|
261
264
|
/**
|
|
@@ -264,7 +267,5 @@ function getImportString(testsPath, targetFolderPath, pathsToType, pathsToValue)
|
|
|
264
267
|
* @returns {string}
|
|
265
268
|
*/
|
|
266
269
|
function convertMapToType(map) {
|
|
267
|
-
return `{ ${Array.from(map)
|
|
268
|
-
.map(([key, value]) => `${key}: ${value}`)
|
|
269
|
-
.join(', ')} }`
|
|
270
|
+
return `{ ${Array.from(map).map(([key, value]) => `${key}: ${value}`).join(', ')} }`;
|
|
270
271
|
}
|
package/lib/command/dryRun.js
CHANGED
|
@@ -1,122 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import { getConfig, getTestRoot } from './utils.js';
|
|
2
|
+
import Config from '../config.js';
|
|
3
|
+
import Codecept from '../codecept.js';
|
|
4
|
+
import { output } from '../output.js';
|
|
5
|
+
import * as event from '../event.js';
|
|
6
|
+
import { store } from '../store.js';
|
|
7
|
+
import container from '../container.js';
|
|
8
|
+
import colors from "chalk";
|
|
9
|
+
import figures from "figures";
|
|
10
|
+
|
|
11
|
+
export default async function (test, options) {
|
|
12
|
+
if (options.grep) process.env.grep = options.grep.toLowerCase();
|
|
13
|
+
const configFile = options.config;
|
|
14
|
+
let codecept;
|
|
15
|
+
|
|
16
|
+
const testRoot = getTestRoot(configFile);
|
|
17
|
+
let config = getConfig(configFile);
|
|
16
18
|
if (options.override) {
|
|
17
|
-
config = Config.append(JSON.parse(options.override))
|
|
19
|
+
config = Config.append(JSON.parse(options.override));
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
if (config.plugins) {
|
|
21
23
|
// disable all plugins by default, they can be enabled with -p option
|
|
22
24
|
for (const plugin in config.plugins) {
|
|
23
25
|
// if `-p all` is passed, then enabling all plugins, otherwise plugins could be enabled by `-p customLocator,commentStep,tryTo`
|
|
24
|
-
config.plugins[plugin].enabled = options.plugins === 'all'
|
|
26
|
+
config.plugins[plugin].enabled = options.plugins === 'all';
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
try {
|
|
29
|
-
codecept = new Codecept(config, options)
|
|
30
|
-
codecept.init(testRoot)
|
|
31
|
+
codecept = new Codecept(config, options);
|
|
32
|
+
codecept.init(testRoot);
|
|
31
33
|
|
|
32
|
-
if (options.bootstrap) await codecept.bootstrap()
|
|
34
|
+
if (options.bootstrap) await codecept.bootstrap();
|
|
33
35
|
|
|
34
|
-
codecept.loadTests()
|
|
35
|
-
store.dryRun = true
|
|
36
|
+
codecept.loadTests();
|
|
37
|
+
store.dryRun = true;
|
|
36
38
|
|
|
37
39
|
if (!options.steps && !options.verbose && !options.debug) {
|
|
38
|
-
printTests(codecept.testFiles)
|
|
39
|
-
return
|
|
40
|
+
printTests(codecept.testFiles);
|
|
41
|
+
return;
|
|
40
42
|
}
|
|
41
|
-
event.dispatcher.on(event.all.result, printFooter)
|
|
42
|
-
codecept.run(test)
|
|
43
|
+
event.dispatcher.on(event.all.result, printFooter);
|
|
44
|
+
codecept.run(test);
|
|
43
45
|
} catch (err) {
|
|
44
|
-
console.error(err)
|
|
45
|
-
process.exit(1)
|
|
46
|
+
console.error(err);
|
|
47
|
+
process.exit(1);
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
function printTests(files) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
output.print(output.styles.debug(`Tests from ${global.codecept_dir}:`));
|
|
53
|
+
output.print();
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
const mocha = container.mocha();
|
|
56
|
+
mocha.files = files;
|
|
57
|
+
mocha.loadFiles();
|
|
55
58
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
let numOfTests = 0
|
|
61
|
-
let numOfSuites = 0
|
|
62
|
-
let outputString = ''
|
|
63
|
-
const filterBy = process.env.grep ? process.env.grep.toLowerCase() : undefined
|
|
59
|
+
let numOfTests = 0;
|
|
60
|
+
let numOfSuites = 0;
|
|
61
|
+
let outputString = '';
|
|
62
|
+
const filterBy = process.env.grep ? process.env.grep.toLowerCase() : undefined;
|
|
64
63
|
|
|
65
64
|
if (filterBy) {
|
|
66
65
|
for (const suite of mocha.suite.suites) {
|
|
67
|
-
const currentSuite = suite.title
|
|
66
|
+
const currentSuite = suite.title;
|
|
68
67
|
if (suite.title.toLowerCase().includes(filterBy)) {
|
|
69
|
-
outputString += `${colors.white.bold(suite.title)} -- ${output.styles.log(suite.file || '')} -- ${mocha.suite.suites.length} tests\n
|
|
70
|
-
numOfSuites
|
|
68
|
+
outputString += `${colors.white.bold(suite.title)} -- ${output.styles.log(suite.file || '')} -- ${mocha.suite.suites.length} tests\n`;
|
|
69
|
+
numOfSuites++;
|
|
71
70
|
}
|
|
72
71
|
|
|
73
|
-
for (test of suite.tests) {
|
|
72
|
+
for (const test of suite.tests) {
|
|
74
73
|
if (test.title.toLowerCase().includes(filterBy)) {
|
|
75
|
-
numOfTests
|
|
76
|
-
outputString += `${colors.white.bold(test.parent.title)} -- ${output.styles.log(test.parent.file || '')} -- ${mocha.suite.suites.length} tests\n
|
|
77
|
-
outputString += ` ${output.styles.scenario(figures.checkboxOff)} ${test.title}\n
|
|
74
|
+
numOfTests++;
|
|
75
|
+
outputString += `${colors.white.bold(test.parent.title)} -- ${output.styles.log(test.parent.file || '')} -- ${mocha.suite.suites.length} tests\n`;
|
|
76
|
+
outputString += ` ${output.styles.scenario(figures.checkboxOff)} ${test.title}\n`;
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
79
|
}
|
|
81
|
-
numOfSuites = countSuites(outputString)
|
|
80
|
+
numOfSuites = countSuites(outputString);
|
|
82
81
|
} else {
|
|
83
82
|
for (const suite of mocha.suite.suites) {
|
|
84
|
-
output.print(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
numOfTests++
|
|
91
|
-
output.print(` ${output.styles.scenario(figures.checkboxOff)} ${test.title}`)
|
|
83
|
+
output.print(`${colors.white.bold(suite.title)} -- ${output.styles.log(suite.file || '')} -- ${mocha.suite.suites.length} tests`);
|
|
84
|
+
numOfSuites++;
|
|
85
|
+
|
|
86
|
+
for (const test of suite.tests) {
|
|
87
|
+
numOfTests++;
|
|
88
|
+
output.print(` ${output.styles.scenario(figures.checkboxOff)} ${test.title}`);
|
|
92
89
|
}
|
|
93
90
|
}
|
|
94
91
|
}
|
|
95
92
|
|
|
96
|
-
output.print(removeDuplicates(outputString))
|
|
97
|
-
output.print('')
|
|
98
|
-
output.success(` Total: ${numOfSuites} suites | ${numOfTests} tests `)
|
|
99
|
-
printFooter()
|
|
100
|
-
process.exit(0)
|
|
93
|
+
output.print(removeDuplicates(outputString));
|
|
94
|
+
output.print('');
|
|
95
|
+
output.success(` Total: ${numOfSuites} suites | ${numOfTests} tests `);
|
|
96
|
+
printFooter();
|
|
97
|
+
process.exit(0);
|
|
101
98
|
}
|
|
102
99
|
|
|
103
100
|
function printFooter() {
|
|
104
|
-
output.print()
|
|
105
|
-
output.print('--- DRY MODE: No tests were executed ---')
|
|
101
|
+
output.print();
|
|
102
|
+
output.print('--- DRY MODE: No tests were executed ---');
|
|
106
103
|
}
|
|
107
104
|
|
|
108
105
|
function removeDuplicates(inputString) {
|
|
109
|
-
const array = inputString.split('\n')
|
|
110
|
-
const uniqueLines = [...new Set(array)]
|
|
111
|
-
const resultString = uniqueLines.join('\n')
|
|
106
|
+
const array = inputString.split('\n');
|
|
107
|
+
const uniqueLines = [...new Set(array)];
|
|
108
|
+
const resultString = uniqueLines.join('\n');
|
|
112
109
|
|
|
113
|
-
return resultString
|
|
110
|
+
return resultString;
|
|
114
111
|
}
|
|
115
112
|
|
|
116
113
|
function countSuites(inputString) {
|
|
117
|
-
const array = inputString.split('\n')
|
|
114
|
+
const array = inputString.split('\n');
|
|
118
115
|
|
|
119
|
-
const uniqueLines = [...new Set(array)]
|
|
120
|
-
const res = uniqueLines.filter(
|
|
121
|
-
return res.length
|
|
116
|
+
const uniqueLines = [...new Set(array)];
|
|
117
|
+
const res = uniqueLines.filter(item => item.includes('-- '));
|
|
118
|
+
return res.length;
|
|
122
119
|
}
|