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