codeceptjs 4.0.0-beta.1 → 4.0.0-beta.11.esm-aria
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -120
- package/bin/codecept.js +107 -96
- package/bin/test-server.js +64 -0
- package/docs/webapi/clearCookie.mustache +1 -1
- package/docs/webapi/click.mustache +5 -1
- package/lib/actor.js +71 -103
- package/lib/ai.js +159 -188
- package/lib/assert/empty.js +22 -24
- package/lib/assert/equal.js +30 -37
- package/lib/assert/error.js +14 -14
- package/lib/assert/include.js +43 -48
- package/lib/assert/throws.js +11 -11
- package/lib/assert/truth.js +22 -22
- package/lib/assert.js +20 -18
- package/lib/codecept.js +238 -162
- package/lib/colorUtils.js +50 -52
- package/lib/command/check.js +206 -0
- package/lib/command/configMigrate.js +56 -51
- package/lib/command/definitions.js +96 -109
- package/lib/command/dryRun.js +77 -79
- package/lib/command/generate.js +234 -194
- package/lib/command/gherkin/init.js +42 -33
- package/lib/command/gherkin/snippets.js +76 -74
- package/lib/command/gherkin/steps.js +20 -17
- package/lib/command/info.js +74 -38
- package/lib/command/init.js +300 -290
- package/lib/command/interactive.js +41 -32
- package/lib/command/list.js +28 -27
- package/lib/command/run-multiple/chunk.js +51 -48
- package/lib/command/run-multiple/collection.js +5 -5
- package/lib/command/run-multiple/run.js +5 -1
- package/lib/command/run-multiple.js +97 -97
- package/lib/command/run-rerun.js +19 -25
- package/lib/command/run-workers.js +68 -92
- package/lib/command/run.js +39 -27
- package/lib/command/utils.js +80 -64
- package/lib/command/workers/runTests.js +388 -226
- package/lib/config.js +124 -50
- package/lib/container.js +765 -260
- package/lib/data/context.js +60 -61
- package/lib/data/dataScenarioConfig.js +47 -47
- package/lib/data/dataTableArgument.js +32 -32
- package/lib/data/table.js +22 -22
- package/lib/effects.js +307 -0
- package/lib/element/WebElement.js +327 -0
- package/lib/els.js +160 -0
- package/lib/event.js +173 -163
- package/lib/globals.js +141 -0
- package/lib/heal.js +89 -85
- package/lib/helper/AI.js +131 -41
- package/lib/helper/ApiDataFactory.js +107 -75
- package/lib/helper/Appium.js +542 -404
- package/lib/helper/FileSystem.js +100 -79
- package/lib/helper/GraphQL.js +44 -43
- package/lib/helper/GraphQLDataFactory.js +52 -52
- package/lib/helper/JSONResponse.js +126 -88
- package/lib/helper/Mochawesome.js +54 -29
- package/lib/helper/Playwright.js +2547 -1316
- package/lib/helper/Puppeteer.js +1578 -1181
- package/lib/helper/REST.js +209 -68
- package/lib/helper/WebDriver.js +1482 -1342
- package/lib/helper/errors/ConnectionRefused.js +6 -6
- package/lib/helper/errors/ElementAssertion.js +11 -16
- package/lib/helper/errors/ElementNotFound.js +5 -9
- package/lib/helper/errors/RemoteBrowserConnectionRefused.js +5 -5
- package/lib/helper/extras/Console.js +11 -11
- package/lib/helper/extras/PlaywrightLocator.js +110 -0
- package/lib/helper/extras/PlaywrightPropEngine.js +18 -18
- package/lib/helper/extras/PlaywrightReactVueLocator.js +17 -8
- package/lib/helper/extras/PlaywrightRestartOpts.js +25 -11
- package/lib/helper/extras/Popup.js +22 -22
- package/lib/helper/extras/React.js +27 -28
- package/lib/helper/network/actions.js +36 -42
- package/lib/helper/network/utils.js +78 -84
- package/lib/helper/scripts/blurElement.js +5 -5
- package/lib/helper/scripts/focusElement.js +5 -5
- package/lib/helper/scripts/highlightElement.js +8 -8
- package/lib/helper/scripts/isElementClickable.js +34 -34
- package/lib/helper.js +2 -3
- package/lib/history.js +23 -19
- package/lib/hooks.js +8 -8
- package/lib/html.js +94 -104
- package/lib/index.js +38 -27
- package/lib/listener/config.js +30 -23
- package/lib/listener/emptyRun.js +54 -0
- package/lib/listener/enhancedGlobalRetry.js +110 -0
- package/lib/listener/exit.js +16 -18
- package/lib/listener/globalRetry.js +70 -0
- package/lib/listener/globalTimeout.js +181 -0
- package/lib/listener/helpers.js +76 -51
- package/lib/listener/mocha.js +10 -11
- package/lib/listener/result.js +11 -0
- package/lib/listener/retryEnhancer.js +85 -0
- package/lib/listener/steps.js +71 -59
- package/lib/listener/store.js +20 -0
- package/lib/locator.js +214 -197
- package/lib/mocha/asyncWrapper.js +274 -0
- package/lib/mocha/bdd.js +167 -0
- package/lib/mocha/cli.js +341 -0
- package/lib/mocha/factory.js +163 -0
- package/lib/mocha/featureConfig.js +89 -0
- package/lib/mocha/gherkin.js +231 -0
- package/lib/mocha/hooks.js +121 -0
- package/lib/mocha/index.js +21 -0
- package/lib/mocha/inject.js +46 -0
- package/lib/{interfaces → mocha}/scenarioConfig.js +58 -34
- package/lib/mocha/suite.js +89 -0
- package/lib/mocha/test.js +184 -0
- package/lib/mocha/types.d.ts +42 -0
- package/lib/mocha/ui.js +242 -0
- package/lib/output.js +141 -71
- package/lib/parser.js +47 -44
- package/lib/pause.js +173 -145
- package/lib/plugin/analyze.js +403 -0
- package/lib/plugin/{autoLogin.js → auth.js} +178 -79
- package/lib/plugin/autoDelay.js +36 -40
- package/lib/plugin/coverage.js +131 -78
- package/lib/plugin/customLocator.js +22 -21
- package/lib/plugin/customReporter.js +53 -0
- package/lib/plugin/enhancedRetryFailedStep.js +99 -0
- package/lib/plugin/heal.js +101 -110
- package/lib/plugin/htmlReporter.js +3648 -0
- package/lib/plugin/pageInfo.js +140 -0
- package/lib/plugin/pauseOnFail.js +12 -11
- package/lib/plugin/retryFailedStep.js +82 -47
- package/lib/plugin/screenshotOnFail.js +111 -92
- package/lib/plugin/stepByStepReport.js +159 -101
- package/lib/plugin/stepTimeout.js +20 -25
- package/lib/plugin/subtitles.js +38 -38
- package/lib/recorder.js +193 -130
- package/lib/rerun.js +94 -49
- package/lib/result.js +238 -0
- package/lib/retryCoordinator.js +207 -0
- package/lib/secret.js +20 -18
- package/lib/session.js +95 -89
- package/lib/step/base.js +239 -0
- package/lib/step/comment.js +10 -0
- package/lib/step/config.js +50 -0
- package/lib/step/func.js +46 -0
- package/lib/step/helper.js +50 -0
- package/lib/step/meta.js +99 -0
- package/lib/step/record.js +74 -0
- package/lib/step/retry.js +11 -0
- package/lib/step/section.js +55 -0
- package/lib/step.js +18 -329
- package/lib/steps.js +54 -0
- package/lib/store.js +38 -7
- package/lib/template/heal.js +3 -12
- package/lib/template/prompts/generatePageObject.js +31 -0
- package/lib/template/prompts/healStep.js +13 -0
- package/lib/template/prompts/writeStep.js +9 -0
- package/lib/test-server.js +334 -0
- package/lib/timeout.js +60 -0
- package/lib/transform.js +8 -8
- package/lib/translation.js +34 -21
- package/lib/utils/mask_data.js +47 -0
- package/lib/utils.js +411 -228
- package/lib/workerStorage.js +37 -34
- package/lib/workers.js +532 -296
- package/package.json +115 -95
- package/translations/de-DE.js +5 -3
- package/translations/fr-FR.js +5 -4
- package/translations/index.js +22 -12
- package/translations/it-IT.js +4 -3
- package/translations/ja-JP.js +4 -3
- package/translations/nl-NL.js +76 -0
- package/translations/pl-PL.js +4 -3
- package/translations/pt-BR.js +4 -3
- package/translations/ru-RU.js +4 -3
- package/translations/utils.js +10 -0
- package/translations/zh-CN.js +4 -3
- package/translations/zh-TW.js +4 -3
- package/typings/index.d.ts +546 -185
- package/typings/promiseBasedTypes.d.ts +150 -879
- package/typings/types.d.ts +547 -996
- package/lib/cli.js +0 -249
- package/lib/dirname.js +0 -5
- package/lib/helper/Expect.js +0 -425
- package/lib/helper/ExpectHelper.js +0 -399
- package/lib/helper/MockServer.js +0 -223
- package/lib/helper/Nightmare.js +0 -1411
- package/lib/helper/Protractor.js +0 -1835
- package/lib/helper/SoftExpectHelper.js +0 -381
- package/lib/helper/TestCafe.js +0 -1410
- package/lib/helper/clientscripts/nightmare.js +0 -213
- package/lib/helper/testcafe/testControllerHolder.js +0 -42
- package/lib/helper/testcafe/testcafe-utils.js +0 -63
- package/lib/interfaces/bdd.js +0 -98
- package/lib/interfaces/featureConfig.js +0 -69
- package/lib/interfaces/gherkin.js +0 -195
- package/lib/listener/artifacts.js +0 -19
- package/lib/listener/retry.js +0 -68
- package/lib/listener/timeout.js +0 -109
- package/lib/mochaFactory.js +0 -110
- package/lib/plugin/allure.js +0 -15
- package/lib/plugin/commentStep.js +0 -136
- package/lib/plugin/debugErrors.js +0 -67
- package/lib/plugin/eachElement.js +0 -127
- package/lib/plugin/fakerTransform.js +0 -49
- package/lib/plugin/retryTo.js +0 -121
- package/lib/plugin/selenoid.js +0 -371
- package/lib/plugin/standardActingHelpers.js +0 -9
- package/lib/plugin/tryTo.js +0 -105
- package/lib/plugin/wdio.js +0 -246
- package/lib/scenario.js +0 -222
- package/lib/ui.js +0 -238
- package/lib/within.js +0 -70
package/lib/cli.js
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import mocha from 'mocha';
|
|
2
|
-
import ms from 'ms';
|
|
3
|
-
import * as event from './event.js';
|
|
4
|
-
import * as output from './output.js';
|
|
5
|
-
import AssertionFailedError from './assert/error.js';
|
|
6
|
-
import * as Codecept from './codecept.js';
|
|
7
|
-
import container from './container.js';
|
|
8
|
-
|
|
9
|
-
const { reporters: { Base } } = mocha;
|
|
10
|
-
|
|
11
|
-
const cursor = Base.cursor;
|
|
12
|
-
let currentMetaStep = [];
|
|
13
|
-
let codeceptjsEventDispatchersRegistered = false;
|
|
14
|
-
|
|
15
|
-
class Cli extends Base {
|
|
16
|
-
constructor(runner, opts) {
|
|
17
|
-
super(runner);
|
|
18
|
-
let level = 0;
|
|
19
|
-
this.loadedTests = [];
|
|
20
|
-
opts = opts.reporterOptions || opts;
|
|
21
|
-
if (opts.steps) level = 1;
|
|
22
|
-
if (opts.debug) level = 2;
|
|
23
|
-
if (opts.verbose) level = 3;
|
|
24
|
-
output.output.level(level);
|
|
25
|
-
const version = Codecept.version();
|
|
26
|
-
output.output.print(`CodeceptJS v${version} ${output.output.standWithUkraine()}`);
|
|
27
|
-
output.output.print(`Using test root "${global.codecept_dir}"`);
|
|
28
|
-
|
|
29
|
-
const showSteps = level >= 1;
|
|
30
|
-
|
|
31
|
-
if (level >= 2) {
|
|
32
|
-
output.output.print(output.output.styles.debug(`Helpers: ${Object.keys(container.helpers()).join(', ')}`));
|
|
33
|
-
output.output.print(output.output.styles.debug(`Plugins: ${Object.keys(container.plugins()).join(', ')}`));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
runner.on('start', () => {
|
|
37
|
-
console.log();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
runner.on('suite', (suite) => {
|
|
41
|
-
output.output.suite.started(suite);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
runner.on('fail', (test) => {
|
|
45
|
-
if (test.ctx.currentTest) {
|
|
46
|
-
this.loadedTests.push(test.ctx.currentTest.uid);
|
|
47
|
-
}
|
|
48
|
-
if (showSteps && test.steps) {
|
|
49
|
-
return output.output.scenario.failed(test);
|
|
50
|
-
}
|
|
51
|
-
cursor.CR();
|
|
52
|
-
output.output.test.failed(test);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
runner.on('pending', (test) => {
|
|
56
|
-
if (test.parent && test.parent.pending) {
|
|
57
|
-
const suite = test.parent;
|
|
58
|
-
const skipInfo = suite.opts.skipInfo || {};
|
|
59
|
-
skipTestConfig(test, skipInfo.message);
|
|
60
|
-
} else {
|
|
61
|
-
skipTestConfig(test, null);
|
|
62
|
-
}
|
|
63
|
-
this.loadedTests.push(test.uid);
|
|
64
|
-
cursor.CR();
|
|
65
|
-
output.output.test.skipped(test);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
runner.on('pass', (test) => {
|
|
69
|
-
if (showSteps && test.steps) {
|
|
70
|
-
return output.output.scenario.passed(test);
|
|
71
|
-
}
|
|
72
|
-
cursor.CR();
|
|
73
|
-
output.output.test.passed(test);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
if (showSteps) {
|
|
77
|
-
runner.on('test', (test) => {
|
|
78
|
-
currentMetaStep = [];
|
|
79
|
-
if (test.steps) {
|
|
80
|
-
output.output.test.started(test);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
if (!codeceptjsEventDispatchersRegistered) {
|
|
85
|
-
codeceptjsEventDispatchersRegistered = true;
|
|
86
|
-
|
|
87
|
-
event.dispatcher.on(event.bddStep.started, (step) => {
|
|
88
|
-
output.output.stepShift = 2;
|
|
89
|
-
output.output.step(step);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
event.dispatcher.on(event.step.started, (step) => {
|
|
93
|
-
let processingStep = step;
|
|
94
|
-
const metaSteps = [];
|
|
95
|
-
while (processingStep.metaStep) {
|
|
96
|
-
metaSteps.unshift(processingStep.metaStep);
|
|
97
|
-
processingStep = processingStep.metaStep;
|
|
98
|
-
}
|
|
99
|
-
const shift = metaSteps.length;
|
|
100
|
-
|
|
101
|
-
for (let i = 0; i < Math.max(currentMetaStep.length, metaSteps.length); i++) {
|
|
102
|
-
if (currentMetaStep[i] !== metaSteps[i]) {
|
|
103
|
-
output.output.stepShift = 3 + 2 * i;
|
|
104
|
-
if (!metaSteps[i]) continue;
|
|
105
|
-
// bdd steps are handled by bddStep.started
|
|
106
|
-
if (metaSteps[i].isBDD()) continue;
|
|
107
|
-
output.output.step(metaSteps[i]);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
currentMetaStep = metaSteps;
|
|
111
|
-
output.output.stepShift = 3 + 2 * shift;
|
|
112
|
-
if (step.helper.constructor.name !== 'ExpectHelper') {
|
|
113
|
-
output.output.step(step);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
event.dispatcher.on(event.step.finished, () => {
|
|
118
|
-
output.output.stepShift = 0;
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
runner.on('suite end', suite => {
|
|
124
|
-
let skippedCount = 0;
|
|
125
|
-
const grep = runner._grep;
|
|
126
|
-
for (const test of suite.tests) {
|
|
127
|
-
if (!test.state && !this.loadedTests.includes(test.uid)) {
|
|
128
|
-
if (matchTest(grep, test.title)) {
|
|
129
|
-
if (!test.opts) {
|
|
130
|
-
test.opts = {};
|
|
131
|
-
}
|
|
132
|
-
if (!test.opts.skipInfo) {
|
|
133
|
-
test.opts.skipInfo = {};
|
|
134
|
-
}
|
|
135
|
-
skipTestConfig(test, 'Skipped due to failure in \'before\' hook');
|
|
136
|
-
output.output.test.skipped(test);
|
|
137
|
-
skippedCount += 1;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
this.stats.pending += skippedCount;
|
|
143
|
-
this.stats.tests += skippedCount;
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
runner.on('end', this.result.bind(this));
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
result() {
|
|
150
|
-
const stats = this.stats;
|
|
151
|
-
console.log();
|
|
152
|
-
|
|
153
|
-
// passes
|
|
154
|
-
if (stats.failures) {
|
|
155
|
-
output.output.print(output.output.styles.bold('-- FAILURES:'));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const failuresLog = [];
|
|
159
|
-
|
|
160
|
-
// failures
|
|
161
|
-
if (stats.failures) {
|
|
162
|
-
// append step traces
|
|
163
|
-
this.failures.map((test) => {
|
|
164
|
-
const err = test.err;
|
|
165
|
-
|
|
166
|
-
let log = '';
|
|
167
|
-
|
|
168
|
-
if (err instanceof AssertionFailedError) {
|
|
169
|
-
err.message = err.inspect();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const steps = test.steps || (test.ctx && test.ctx.test.steps);
|
|
173
|
-
|
|
174
|
-
if (steps && steps.length) {
|
|
175
|
-
let scenarioTrace = '';
|
|
176
|
-
steps.reverse().forEach((step) => {
|
|
177
|
-
const line = `- ${step.toCode()} ${step.line()}`;
|
|
178
|
-
// if (step.status === 'failed') line = '' + line;
|
|
179
|
-
scenarioTrace += `\n${line}`;
|
|
180
|
-
});
|
|
181
|
-
log += `${output.output.styles.bold('Scenario Steps')}:${scenarioTrace}\n`;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// display artifacts in debug mode
|
|
185
|
-
if (test?.artifacts && Object.keys(test.artifacts).length) {
|
|
186
|
-
log += `\n${output.output.styles.bold('Artifacts:')}`;
|
|
187
|
-
for (const artifact of Object.keys(test.artifacts)) {
|
|
188
|
-
log += `\n- ${artifact}: ${test.artifacts[artifact]}`;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
let stack = err.stack ? err.stack.split('\n') : [];
|
|
193
|
-
if (stack[0] && stack[0].includes(err.message)) {
|
|
194
|
-
stack.shift();
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (output.output.level() < 3) {
|
|
198
|
-
stack = stack.slice(0, 3);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
err.stack = `${stack.join('\n')}\n\n${output.output.colors.blue(log)}`;
|
|
202
|
-
|
|
203
|
-
// clone err object so stack trace adjustments won't affect test other reports
|
|
204
|
-
test.err = err;
|
|
205
|
-
return test;
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
const originalLog = Base.consoleLog;
|
|
209
|
-
Base.consoleLog = (...data) => {
|
|
210
|
-
failuresLog.push([...data]);
|
|
211
|
-
originalLog(...data);
|
|
212
|
-
};
|
|
213
|
-
Base.list(this.failures);
|
|
214
|
-
Base.consoleLog = originalLog;
|
|
215
|
-
console.log();
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
event.emit(event.all.failures, { failuresLog, stats });
|
|
219
|
-
output.output.result(stats.passes, stats.failures, stats.pending, ms(stats.duration));
|
|
220
|
-
|
|
221
|
-
if (stats.failures && output.output.level() < 3) {
|
|
222
|
-
output.output.print(output.output.styles.debug('Run with --verbose flag to see complete NodeJS stacktrace'));
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function matchTest(grep, test) {
|
|
228
|
-
if (grep) {
|
|
229
|
-
return grep.test(test);
|
|
230
|
-
}
|
|
231
|
-
return true;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function skipTestConfig(test, message) {
|
|
235
|
-
if (!test.opts) {
|
|
236
|
-
test.opts = {};
|
|
237
|
-
}
|
|
238
|
-
if (!test.opts.skipInfo) {
|
|
239
|
-
test.opts.skipInfo = {};
|
|
240
|
-
}
|
|
241
|
-
test.opts.skipInfo.message = test.opts.skipInfo.message || message;
|
|
242
|
-
test.opts.skipInfo.isFastSkipped = true;
|
|
243
|
-
event.emit(event.test.skipped, test);
|
|
244
|
-
test.state = 'skipped';
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export default function cli(runner, opts) {
|
|
248
|
-
return new Cli(runner, opts);
|
|
249
|
-
}
|
package/lib/dirname.js
DELETED
package/lib/helper/Expect.js
DELETED
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
import * as chai from 'chai';
|
|
2
|
-
import chai_json_schema from 'chai-json-schema';
|
|
3
|
-
import chai_match_pattern from 'chai-match-pattern';
|
|
4
|
-
import chai_exclude from 'chai-exclude';
|
|
5
|
-
import chai_string from 'chai-string';
|
|
6
|
-
import * as output from '../output.js';
|
|
7
|
-
|
|
8
|
-
chai.use(chai_string);
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
chai.use(chai_exclude);
|
|
11
|
-
chai.use(chai_match_pattern);
|
|
12
|
-
chai.use(chai_json_schema);
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* This helper allows performing assertions based on Chai.
|
|
16
|
-
*
|
|
17
|
-
* ### Examples
|
|
18
|
-
*
|
|
19
|
-
* Zero-configuration when paired with other helpers like REST, Playwright:
|
|
20
|
-
*
|
|
21
|
-
* ```js
|
|
22
|
-
* // inside codecept.conf.js
|
|
23
|
-
*{
|
|
24
|
-
* helpers: {
|
|
25
|
-
* Playwright: {...},
|
|
26
|
-
* Expect: {},
|
|
27
|
-
* }
|
|
28
|
-
*}
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* ## Methods
|
|
32
|
-
*/
|
|
33
|
-
class ExpectHelper {
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
* @param {*} actualValue
|
|
37
|
-
* @param {*} expectedValue
|
|
38
|
-
* @param {*} [customErrorMsg]
|
|
39
|
-
*/
|
|
40
|
-
expectEqual(actualValue, expectedValue, customErrorMsg = '') {
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
output.output.step(`I expect "${JSON.stringify(actualValue)}" to equal "${JSON.stringify(expectedValue)}"`);
|
|
43
|
-
return chai.expect(actualValue, customErrorMsg).to.equal(expectedValue);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
*
|
|
48
|
-
* @param {*} actualValue
|
|
49
|
-
* @param {*} expectedValue
|
|
50
|
-
* @param {*} [customErrorMsg]
|
|
51
|
-
*/
|
|
52
|
-
expectNotEqual(actualValue, expectedValue, customErrorMsg = '') {
|
|
53
|
-
// @ts-ignore
|
|
54
|
-
output.output.step(`I expect "${JSON.stringify(actualValue)}" to not equal "${JSON.stringify(expectedValue)}"`);
|
|
55
|
-
return chai.expect(actualValue, customErrorMsg).not.to.equal(expectedValue);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
*
|
|
60
|
-
* @param {*} actualValue
|
|
61
|
-
* @param {*} expectedValue
|
|
62
|
-
* @param {*} [customErrorMsg]
|
|
63
|
-
|
|
64
|
-
*/
|
|
65
|
-
expectDeepEqual(actualValue, expectedValue, customErrorMsg = '') {
|
|
66
|
-
// @ts-ignore
|
|
67
|
-
output.output.step(`I expect "${JSON.stringify(actualValue)}" to deep equal "${JSON.stringify(expectedValue)}"`);
|
|
68
|
-
return chai.expect(actualValue, customErrorMsg).to.deep.equal(expectedValue);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
*
|
|
73
|
-
* @param {*} actualValue
|
|
74
|
-
* @param {*} expectedValue
|
|
75
|
-
* @param {*} [customErrorMsg]
|
|
76
|
-
*/
|
|
77
|
-
expectNotDeepEqual(actualValue, expectedValue, customErrorMsg = '') {
|
|
78
|
-
// @ts-ignore
|
|
79
|
-
output.output.step(`I expect "${JSON.stringify(actualValue)}" to not deep equal "${JSON.stringify(expectedValue)}"`);
|
|
80
|
-
return chai.expect(actualValue, customErrorMsg).to.not.deep.equal(expectedValue);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
*
|
|
85
|
-
* @param {*} actualValue
|
|
86
|
-
* @param {*} expectedValueToContain
|
|
87
|
-
* @param {*} [customErrorMsg]
|
|
88
|
-
*/
|
|
89
|
-
expectContain(actualValue, expectedValueToContain, customErrorMsg = '') {
|
|
90
|
-
// @ts-ignore
|
|
91
|
-
output.output.step(`I expect "${JSON.stringify(actualValue)}" to contain "${JSON.stringify(expectedValueToContain)}"`);
|
|
92
|
-
return chai.expect(actualValue, customErrorMsg).to.contain(
|
|
93
|
-
expectedValueToContain,
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
*
|
|
99
|
-
* @param {*} actualValue
|
|
100
|
-
* @param {*} expectedValueToNotContain
|
|
101
|
-
* @param {*} [customErrorMsg]
|
|
102
|
-
*/
|
|
103
|
-
expectNotContain(
|
|
104
|
-
actualValue,
|
|
105
|
-
expectedValueToNotContain,
|
|
106
|
-
customErrorMsg = '',
|
|
107
|
-
) {
|
|
108
|
-
// @ts-ignore
|
|
109
|
-
output.output.step(`I expect "${JSON.stringify(actualValue)}" to not contain "${JSON.stringify(expectedValueToNotContain)}"`);
|
|
110
|
-
return chai.expect(actualValue, customErrorMsg).not.to.contain(
|
|
111
|
-
expectedValueToNotContain,
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
*
|
|
117
|
-
* @param {*} actualValue
|
|
118
|
-
* @param {*} expectedValueToStartWith
|
|
119
|
-
* @param {*} [customErrorMsg]
|
|
120
|
-
*/
|
|
121
|
-
expectStartsWith(actualValue, expectedValueToStartWith, customErrorMsg = '') {
|
|
122
|
-
// @ts-ignore
|
|
123
|
-
output.output.step(`I expect "${JSON.stringify(actualValue)}" to start with "${JSON.stringify(expectedValueToStartWith)}"`);
|
|
124
|
-
return chai.expect(actualValue, customErrorMsg).to.startsWith(
|
|
125
|
-
expectedValueToStartWith,
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
*
|
|
131
|
-
* @param {*} actualValue
|
|
132
|
-
* @param {*} expectedValueToNotStartWith
|
|
133
|
-
* @param {*} [customErrorMsg]
|
|
134
|
-
*/
|
|
135
|
-
expectNotStartsWith(
|
|
136
|
-
actualValue,
|
|
137
|
-
expectedValueToNotStartWith,
|
|
138
|
-
customErrorMsg = '',
|
|
139
|
-
) {
|
|
140
|
-
// @ts-ignore
|
|
141
|
-
output.output.step(`I expect "${JSON.stringify(actualValue)}" to not start with "${JSON.stringify(expectedValueToNotStartWith)}"`);
|
|
142
|
-
return chai.expect(actualValue, customErrorMsg).not.to.startsWith(
|
|
143
|
-
expectedValueToNotStartWith,
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* @param {*} actualValue
|
|
149
|
-
* @param {*} expectedValueToEndWith
|
|
150
|
-
* @param {*} [customErrorMsg]
|
|
151
|
-
*/
|
|
152
|
-
expectEndsWith(actualValue, expectedValueToEndWith, customErrorMsg = '') {
|
|
153
|
-
// @ts-ignore
|
|
154
|
-
output.output.step(`I expect "${JSON.stringify(actualValue)}" to end with "${JSON.stringify(expectedValueToEndWith)}"`);
|
|
155
|
-
return chai.expect(actualValue, customErrorMsg).to.endsWith(
|
|
156
|
-
expectedValueToEndWith,
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* @param {*} actualValue
|
|
162
|
-
* @param {*} expectedValueToNotEndWith
|
|
163
|
-
* @param {*} [customErrorMsg]
|
|
164
|
-
*/
|
|
165
|
-
expectNotEndsWith(
|
|
166
|
-
actualValue,
|
|
167
|
-
expectedValueToNotEndWith,
|
|
168
|
-
customErrorMsg = '',
|
|
169
|
-
) {
|
|
170
|
-
// @ts-ignore
|
|
171
|
-
output.output.step(`I expect "${JSON.stringify(actualValue)}" to not end with "${JSON.stringify(expectedValueToNotEndWith)}"`);
|
|
172
|
-
return chai.expect(actualValue, customErrorMsg).not.to.endsWith(
|
|
173
|
-
expectedValueToNotEndWith,
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* @param {*} targetData
|
|
179
|
-
* @param {*} jsonSchema
|
|
180
|
-
* @param {*} [customErrorMsg]
|
|
181
|
-
*/
|
|
182
|
-
expectJsonSchema(targetData, jsonSchema, customErrorMsg = '') {
|
|
183
|
-
// @ts-ignore
|
|
184
|
-
output.output.step(`I expect "${JSON.stringify(targetData)}" to match this JSON schema "${JSON.stringify(jsonSchema)}"`);
|
|
185
|
-
|
|
186
|
-
return chai.expect(targetData, customErrorMsg).to.be.jsonSchema(jsonSchema);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* @param {*} targetData
|
|
191
|
-
* @param {*} jsonSchema
|
|
192
|
-
* @param {*} [customErrorMsg]
|
|
193
|
-
* @param {*} [ajvOptions] Pass AJV options
|
|
194
|
-
*/
|
|
195
|
-
expectJsonSchemaUsingAJV(
|
|
196
|
-
targetData,
|
|
197
|
-
jsonSchema,
|
|
198
|
-
customErrorMsg = '',
|
|
199
|
-
ajvOptions = { allErrors: true },
|
|
200
|
-
) {
|
|
201
|
-
// @ts-ignore
|
|
202
|
-
output.output.step(`I expect "${JSON.stringify(targetData)}" to match this JSON schema using AJV "${JSON.stringify(jsonSchema)}"`);
|
|
203
|
-
chai.use(require('chai-json-schema-ajv').create(ajvOptions));
|
|
204
|
-
return chai.expect(targetData, customErrorMsg).to.be.jsonSchema(jsonSchema);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* @param {*} targetData
|
|
209
|
-
* @param {*} propertyName
|
|
210
|
-
* @param {*} [customErrorMsg]
|
|
211
|
-
*/
|
|
212
|
-
expectHasProperty(targetData, propertyName, customErrorMsg = '') {
|
|
213
|
-
// @ts-ignore
|
|
214
|
-
output.output.step(`I expect "${JSON.stringify(targetData)}" to have property: "${JSON.stringify(propertyName)}"`);
|
|
215
|
-
return chai.expect(targetData, customErrorMsg).to.have.property(propertyName);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* @param {*} targetData
|
|
220
|
-
* @param {*} propertyName
|
|
221
|
-
* @param {*} [customErrorMsg]
|
|
222
|
-
*/
|
|
223
|
-
expectHasAProperty(targetData, propertyName, customErrorMsg = '') {
|
|
224
|
-
// @ts-ignore
|
|
225
|
-
output.output.step(`I expect "${JSON.stringify(targetData)}" to have a property: "${JSON.stringify(propertyName)}"`);
|
|
226
|
-
return chai.expect(targetData, customErrorMsg).to.have.a.property(propertyName);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* @param {*} targetData
|
|
231
|
-
* @param {*} type
|
|
232
|
-
* @param {*} [customErrorMsg]
|
|
233
|
-
*/
|
|
234
|
-
expectToBeA(targetData, type, customErrorMsg = '') {
|
|
235
|
-
// @ts-ignore
|
|
236
|
-
output.output.step(`I expect "${JSON.stringify(targetData)}" to be a "${JSON.stringify(type)}"`);
|
|
237
|
-
return chai.expect(targetData, customErrorMsg).to.be.a(type);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* @param {*} targetData
|
|
242
|
-
* @param {*} type
|
|
243
|
-
* @param {*} [customErrorMsg]
|
|
244
|
-
*/
|
|
245
|
-
expectToBeAn(targetData, type, customErrorMsg = '') {
|
|
246
|
-
// @ts-ignore
|
|
247
|
-
output.output.step(`I expect "${JSON.stringify(targetData)}" to be an "${JSON.stringify(type)}"`);
|
|
248
|
-
return chai.expect(targetData, customErrorMsg).to.be.an(type);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* @param {*} targetData
|
|
253
|
-
* @param {*} regex
|
|
254
|
-
* @param {*} [customErrorMsg]
|
|
255
|
-
*/
|
|
256
|
-
expectMatchRegex(targetData, regex, customErrorMsg = '') {
|
|
257
|
-
// @ts-ignore
|
|
258
|
-
output.output.step(`I expect "${JSON.stringify(targetData)}" to match the regex "${JSON.stringify(regex)}"`);
|
|
259
|
-
return chai.expect(targetData, customErrorMsg).to.match(regex);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* @param {*} targetData
|
|
264
|
-
* @param {*} length
|
|
265
|
-
* @param {*} [customErrorMsg]
|
|
266
|
-
*/
|
|
267
|
-
expectLengthOf(targetData, length, customErrorMsg = '') {
|
|
268
|
-
// @ts-ignore
|
|
269
|
-
output.output.step(`I expect "${JSON.stringify(targetData)}" to have length of "${JSON.stringify(length)}"`);
|
|
270
|
-
return chai.expect(targetData, customErrorMsg).to.have.lengthOf(length);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* @param {*} targetData
|
|
275
|
-
* @param {*} [customErrorMsg]
|
|
276
|
-
*/
|
|
277
|
-
expectEmpty(targetData, customErrorMsg = '') {
|
|
278
|
-
// @ts-ignore
|
|
279
|
-
output.output.step(`I expect "${JSON.stringify(targetData)}" to be empty`);
|
|
280
|
-
return chai.expect(targetData, customErrorMsg).to.be.empty;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* @param {*} targetData
|
|
285
|
-
* @param {*} [customErrorMsg]
|
|
286
|
-
*/
|
|
287
|
-
expectTrue(targetData, customErrorMsg = '') {
|
|
288
|
-
// @ts-ignore
|
|
289
|
-
output.output.step(`I expect "${JSON.stringify(targetData)}" to be true`);
|
|
290
|
-
return chai.expect(targetData, customErrorMsg).to.be.true;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* @param {*} targetData
|
|
295
|
-
* @param {*} [customErrorMsg]
|
|
296
|
-
*/
|
|
297
|
-
expectFalse(targetData, customErrorMsg = '') {
|
|
298
|
-
// @ts-ignore
|
|
299
|
-
output.output.step(`I expect "${JSON.stringify(targetData)}" to be false`);
|
|
300
|
-
return chai.expect(targetData, customErrorMsg).to.be.false;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* @param {*} targetData
|
|
305
|
-
* @param {*} aboveThan
|
|
306
|
-
* @param {*} [customErrorMsg]
|
|
307
|
-
*/
|
|
308
|
-
expectAbove(targetData, aboveThan, customErrorMsg = '') {
|
|
309
|
-
// @ts-ignore
|
|
310
|
-
output.output.step(`I expect "${JSON.stringify(targetData)}" to be above ${JSON.stringify(aboveThan)}`);
|
|
311
|
-
return chai.expect(targetData, customErrorMsg).to.be.above(aboveThan);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* @param {*} targetData
|
|
316
|
-
* @param {*} belowThan
|
|
317
|
-
* @param {*} [customErrorMsg]
|
|
318
|
-
*/
|
|
319
|
-
expectBelow(targetData, belowThan, customErrorMsg = '') {
|
|
320
|
-
// @ts-ignore
|
|
321
|
-
output.output.step(`I expect "${JSON.stringify(targetData)}" to be below ${JSON.stringify(belowThan)}`);
|
|
322
|
-
return chai.expect(targetData, customErrorMsg).to.be.below(belowThan);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* @param {*} targetData
|
|
327
|
-
* @param {*} lengthAboveThan
|
|
328
|
-
* @param {*} [customErrorMsg]
|
|
329
|
-
*/
|
|
330
|
-
expectLengthAboveThan(targetData, lengthAboveThan, customErrorMsg = '') {
|
|
331
|
-
// @ts-ignore
|
|
332
|
-
output.output.step(`I expect "${JSON.stringify(targetData)}" to have length of above ${JSON.stringify(lengthAboveThan)}`);
|
|
333
|
-
return chai.expect(targetData, customErrorMsg).to.have.lengthOf.above(
|
|
334
|
-
lengthAboveThan,
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* @param {*} targetData
|
|
340
|
-
* @param {*} lengthBelowThan
|
|
341
|
-
* @param {*} [customErrorMsg]
|
|
342
|
-
*/
|
|
343
|
-
expectLengthBelowThan(targetData, lengthBelowThan, customErrorMsg = '') {
|
|
344
|
-
// @ts-ignore
|
|
345
|
-
output.output.step(`I expect "${JSON.stringify(targetData)}" to have length of below ${JSON.stringify(lengthBelowThan)}`);
|
|
346
|
-
return chai.expect(targetData, customErrorMsg).to.have.lengthOf.below(
|
|
347
|
-
lengthBelowThan,
|
|
348
|
-
);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* @param {*} actualValue
|
|
353
|
-
* @param {*} expectedValue
|
|
354
|
-
* @param {*} [customErrorMsg]
|
|
355
|
-
*/
|
|
356
|
-
expectEqualIgnoreCase(actualValue, expectedValue, customErrorMsg = '') {
|
|
357
|
-
// @ts-ignore
|
|
358
|
-
output.output.step(`I expect and ingore case "${JSON.stringify(actualValue)}" to equal "${JSON.stringify(expectedValue)}"`);
|
|
359
|
-
return chai.expect(actualValue, customErrorMsg).to.equalIgnoreCase(
|
|
360
|
-
expectedValue,
|
|
361
|
-
);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* expects members of two arrays are deeply equal
|
|
366
|
-
* @param {*} actualValue
|
|
367
|
-
* @param {*} expectedValue
|
|
368
|
-
* @param {*} [customErrorMsg]
|
|
369
|
-
*/
|
|
370
|
-
expectDeepMembers(actualValue, expectedValue, customErrorMsg = '') {
|
|
371
|
-
// @ts-ignore
|
|
372
|
-
output.output.step(`I expect members of "${JSON.stringify(actualValue)}" and "${JSON.stringify(expectedValue)}" arrays are deeply equal`);
|
|
373
|
-
return chai.expect(actualValue, customErrorMsg).to.have.deep.members(
|
|
374
|
-
expectedValue,
|
|
375
|
-
);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* expects an array to be a superset of another array
|
|
380
|
-
* @param {*} superset
|
|
381
|
-
* @param {*} set
|
|
382
|
-
* @param {*} [customErrorMsg]
|
|
383
|
-
*/
|
|
384
|
-
expectDeepIncludeMembers(superset, set, customErrorMsg = '') {
|
|
385
|
-
// @ts-ignore
|
|
386
|
-
output.output.step(`I expect "${JSON.stringify(superset)}" array to be a superset of "${JSON.stringify(set)}" array`);
|
|
387
|
-
return chai.expect(superset, customErrorMsg).to.deep.include.members(
|
|
388
|
-
set,
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* expects members of two JSON objects are deeply equal excluding some properties
|
|
394
|
-
* @param {*} actualValue
|
|
395
|
-
* @param {*} expectedValue
|
|
396
|
-
* @param {*} fieldsToExclude
|
|
397
|
-
* @param {*} [customErrorMsg]
|
|
398
|
-
*/
|
|
399
|
-
expectDeepEqualExcluding(
|
|
400
|
-
actualValue,
|
|
401
|
-
expectedValue,
|
|
402
|
-
fieldsToExclude,
|
|
403
|
-
customErrorMsg = '',
|
|
404
|
-
) {
|
|
405
|
-
// @ts-ignore
|
|
406
|
-
output.output.step(`I expect members of "${JSON.stringify(actualValue)}" and "${JSON.stringify(expectedValue)}" JSON objects are deeply equal excluding properties: ${JSON.stringify(fieldsToExclude)}`);
|
|
407
|
-
return chai.expect(actualValue, customErrorMsg)
|
|
408
|
-
.excludingEvery(fieldsToExclude)
|
|
409
|
-
.to.deep.equal(expectedValue);
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* expects a JSON object matches a provided pattern
|
|
414
|
-
* @param {*} actualValue
|
|
415
|
-
* @param {*} expectedPattern
|
|
416
|
-
* @param {*} [customErrorMsg]
|
|
417
|
-
*/
|
|
418
|
-
expectMatchesPattern(actualValue, expectedPattern, customErrorMsg = '') {
|
|
419
|
-
// @ts-ignore
|
|
420
|
-
output.output.step(`I expect "${JSON.stringify(actualValue)}" to match the ${JSON.stringify(expectedPattern)} pattern`);
|
|
421
|
-
return chai.expect(actualValue, customErrorMsg).to.matchPattern(expectedPattern);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
export default ExpectHelper;
|