codeceptjs 4.0.0-beta.2 → 4.0.0-beta.4

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.
Files changed (152) hide show
  1. package/README.md +2 -2
  2. package/bin/codecept.js +84 -81
  3. package/lib/actor.js +13 -13
  4. package/lib/ai.js +10 -13
  5. package/lib/assert/empty.js +20 -21
  6. package/lib/assert/equal.js +37 -39
  7. package/lib/assert/error.js +14 -14
  8. package/lib/assert/include.js +46 -47
  9. package/lib/assert/throws.js +13 -11
  10. package/lib/assert/truth.js +19 -22
  11. package/lib/assert.js +4 -2
  12. package/lib/cli.js +56 -49
  13. package/lib/codecept.js +145 -155
  14. package/lib/colorUtils.js +3 -3
  15. package/lib/command/configMigrate.js +58 -52
  16. package/lib/command/definitions.js +88 -89
  17. package/lib/command/dryRun.js +79 -81
  18. package/lib/command/generate.js +197 -188
  19. package/lib/command/gherkin/init.js +27 -16
  20. package/lib/command/gherkin/snippets.js +21 -21
  21. package/lib/command/gherkin/steps.js +8 -8
  22. package/lib/command/info.js +40 -38
  23. package/lib/command/init.js +290 -288
  24. package/lib/command/interactive.js +32 -32
  25. package/lib/command/list.js +26 -26
  26. package/lib/command/run-multiple/chunk.js +5 -5
  27. package/lib/command/run-multiple/collection.js +3 -3
  28. package/lib/command/run-multiple/run.js +6 -2
  29. package/lib/command/run-multiple.js +113 -93
  30. package/lib/command/run-rerun.js +20 -25
  31. package/lib/command/run-workers.js +64 -66
  32. package/lib/command/run.js +26 -29
  33. package/lib/command/utils.js +80 -65
  34. package/lib/command/workers/runTests.js +11 -12
  35. package/lib/config.js +10 -9
  36. package/lib/container.js +40 -48
  37. package/lib/data/context.js +60 -59
  38. package/lib/data/dataScenarioConfig.js +47 -47
  39. package/lib/data/dataTableArgument.js +29 -29
  40. package/lib/data/table.js +26 -20
  41. package/lib/event.js +163 -167
  42. package/lib/heal.js +14 -18
  43. package/lib/helper/AI.js +130 -41
  44. package/lib/helper/ApiDataFactory.js +74 -70
  45. package/lib/helper/Appium.js +416 -388
  46. package/lib/helper/ExpectHelper.js +40 -48
  47. package/lib/helper/FileSystem.js +80 -79
  48. package/lib/helper/GraphQL.js +44 -43
  49. package/lib/helper/GraphQLDataFactory.js +51 -51
  50. package/lib/helper/JSONResponse.js +65 -62
  51. package/lib/helper/Mochawesome.js +28 -28
  52. package/lib/helper/Nightmare.js +664 -571
  53. package/lib/helper/Playwright.js +1367 -1222
  54. package/lib/helper/Protractor.js +663 -635
  55. package/lib/helper/Puppeteer.js +1232 -1132
  56. package/lib/helper/REST.js +183 -68
  57. package/lib/helper/SoftExpectHelper.js +2 -2
  58. package/lib/helper/TestCafe.js +490 -486
  59. package/lib/helper/WebDriver.js +1246 -1297
  60. package/lib/helper/clientscripts/PollyWebDriverExt.js +1 -1
  61. package/lib/helper/errors/ConnectionRefused.js +1 -1
  62. package/lib/helper/errors/ElementAssertion.js +2 -2
  63. package/lib/helper/errors/ElementNotFound.js +2 -2
  64. package/lib/helper/errors/RemoteBrowserConnectionRefused.js +1 -1
  65. package/lib/helper/extras/Console.js +1 -1
  66. package/lib/helper/extras/PlaywrightPropEngine.js +4 -4
  67. package/lib/helper/extras/PlaywrightReactVueLocator.js +1 -1
  68. package/lib/helper/extras/PlaywrightRestartOpts.js +21 -18
  69. package/lib/helper/extras/Popup.js +1 -1
  70. package/lib/helper/extras/React.js +3 -3
  71. package/lib/helper/network/actions.js +14 -7
  72. package/lib/helper/network/utils.js +4 -3
  73. package/lib/helper/scripts/blurElement.js +1 -1
  74. package/lib/helper/scripts/focusElement.js +1 -1
  75. package/lib/helper/scripts/highlightElement.js +1 -1
  76. package/lib/helper/scripts/isElementClickable.js +1 -1
  77. package/lib/helper/testcafe/testControllerHolder.js +1 -1
  78. package/lib/helper/testcafe/testcafe-utils.js +7 -8
  79. package/lib/helper.js +1 -3
  80. package/lib/history.js +6 -5
  81. package/lib/hooks.js +6 -6
  82. package/lib/html.js +7 -7
  83. package/lib/index.js +25 -41
  84. package/lib/interfaces/bdd.js +47 -64
  85. package/lib/interfaces/featureConfig.js +19 -19
  86. package/lib/interfaces/gherkin.js +124 -118
  87. package/lib/interfaces/scenarioConfig.js +29 -29
  88. package/lib/listener/artifacts.js +9 -9
  89. package/lib/listener/config.js +24 -24
  90. package/lib/listener/exit.js +12 -12
  91. package/lib/listener/helpers.js +42 -42
  92. package/lib/listener/mocha.js +11 -11
  93. package/lib/listener/retry.js +32 -30
  94. package/lib/listener/steps.js +50 -53
  95. package/lib/listener/timeout.js +54 -54
  96. package/lib/locator.js +7 -11
  97. package/lib/mochaFactory.js +18 -15
  98. package/lib/output.js +19 -15
  99. package/lib/parser.js +15 -12
  100. package/lib/pause.js +45 -38
  101. package/lib/plugin/allure.js +15 -15
  102. package/lib/plugin/autoDelay.js +29 -37
  103. package/lib/plugin/autoLogin.js +70 -65
  104. package/lib/plugin/commentStep.js +18 -18
  105. package/lib/plugin/coverage.js +112 -67
  106. package/lib/plugin/customLocator.js +21 -20
  107. package/lib/plugin/debugErrors.js +24 -24
  108. package/lib/plugin/eachElement.js +38 -38
  109. package/lib/plugin/fakerTransform.js +6 -6
  110. package/lib/plugin/heal.js +67 -108
  111. package/lib/plugin/pauseOnFail.js +11 -11
  112. package/lib/plugin/retryFailedStep.js +32 -39
  113. package/lib/plugin/retryTo.js +46 -40
  114. package/lib/plugin/screenshotOnFail.js +109 -87
  115. package/lib/plugin/selenoid.js +131 -118
  116. package/lib/plugin/standardActingHelpers.js +2 -8
  117. package/lib/plugin/stepByStepReport.js +110 -91
  118. package/lib/plugin/stepTimeout.js +24 -23
  119. package/lib/plugin/subtitles.js +34 -35
  120. package/lib/plugin/tryTo.js +40 -30
  121. package/lib/plugin/wdio.js +78 -75
  122. package/lib/recorder.js +14 -17
  123. package/lib/rerun.js +11 -10
  124. package/lib/scenario.js +25 -23
  125. package/lib/secret.js +4 -3
  126. package/lib/session.js +10 -10
  127. package/lib/step.js +12 -9
  128. package/lib/store.js +2 -3
  129. package/lib/transform.js +1 -1
  130. package/lib/translation.js +7 -8
  131. package/lib/ui.js +12 -14
  132. package/lib/utils.js +70 -72
  133. package/lib/within.js +10 -10
  134. package/lib/workerStorage.js +27 -25
  135. package/lib/workers.js +29 -33
  136. package/package.json +67 -68
  137. package/translations/de-DE.js +2 -1
  138. package/translations/fr-FR.js +2 -2
  139. package/translations/index.js +9 -13
  140. package/translations/it-IT.js +1 -1
  141. package/translations/ja-JP.js +1 -1
  142. package/translations/pl-PL.js +1 -1
  143. package/translations/pt-BR.js +1 -1
  144. package/translations/ru-RU.js +1 -1
  145. package/translations/zh-CN.js +1 -1
  146. package/translations/zh-TW.js +1 -1
  147. package/typings/index.d.ts +423 -65
  148. package/typings/promiseBasedTypes.d.ts +41 -172
  149. package/typings/types.d.ts +43 -178
  150. package/lib/dirname.js +0 -5
  151. package/lib/helper/Expect.js +0 -425
  152. package/lib/helper/MockServer.js +0 -223
@@ -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;
@@ -1,223 +0,0 @@
1
- import pkg from 'pactum';
2
-
3
- const { mock, settings } = pkg;
4
-
5
- /**
6
- * ## Configuration
7
- *
8
- * This helper should be configured in codecept.conf.(js|ts)
9
- *
10
- * @typedef MockServerConfig
11
- * @type {object}
12
- * @prop {number} [port=9393] - Mock server port
13
- * @prop {string} [host="0.0.0.0"] - Mock server host
14
- * @prop {object} [httpsOpts] - key & cert values are the paths to .key and .crt files
15
- */
16
- let config = {
17
- port: 9393,
18
- host: '0.0.0.0',
19
- httpsOpts: {
20
- key: '',
21
- cert: '',
22
- },
23
- };
24
-
25
- /**
26
- * MockServer
27
- *
28
- * The MockServer Helper in CodeceptJS empowers you to mock any server or service via HTTP or HTTPS, making it an excellent tool for simulating REST endpoints and other HTTP-based APIs.
29
- *
30
- * <!-- configuration -->
31
- *
32
- * #### Examples
33
- *
34
- * You can seamlessly integrate MockServer with other helpers like REST or Playwright. Here's a configuration example inside the `codecept.conf.js` file:
35
- *
36
- * ```javascript
37
- * {
38
- * helpers: {
39
- * REST: {...},
40
- * MockServer: {
41
- * // default mock server config
42
- * port: 9393,
43
- * host: '0.0.0.0',
44
- * httpsOpts: {
45
- * key: '',
46
- * cert: '',
47
- * },
48
- * },
49
- * }
50
- * }
51
- * ```
52
- *
53
- * #### Adding Interactions
54
- *
55
- * Interactions add behavior to the mock server. Use the `I.addInteractionToMockServer()` method to include interactions. It takes an interaction object as an argument, containing request and response details.
56
- *
57
- * ```javascript
58
- * I.addInteractionToMockServer({
59
- * request: {
60
- * method: 'GET',
61
- * path: '/api/hello'
62
- * },
63
- * response: {
64
- * status: 200,
65
- * body: {
66
- * 'say': 'hello to mock server'
67
- * }
68
- * }
69
- * });
70
- * ```
71
- *
72
- * #### Request Matching
73
- *
74
- * When a real request is sent to the mock server, it matches the received request with the interactions. If a match is found, it returns the specified response; otherwise, a 404 status code is returned.
75
- *
76
- * - Strong match on HTTP Method, Path, Query Params & JSON body.
77
- * - Loose match on Headers.
78
- *
79
- * ##### Strong Match on Query Params
80
- *
81
- * You can send different responses based on query parameters:
82
- *
83
- * ```javascript
84
- * I.addInteractionToMockServer({
85
- * request: {
86
- * method: 'GET',
87
- * path: '/api/users',
88
- * queryParams: {
89
- * id: 1
90
- * }
91
- * },
92
- * response: {
93
- * status: 200,
94
- * body: 'user 1'
95
- * }
96
- * });
97
- *
98
- * I.addInteractionToMockServer({
99
- * request: {
100
- * method: 'GET',
101
- * path: '/api/users',
102
- * queryParams: {
103
- * id: 2
104
- * }
105
- * },
106
- * response: {
107
- * status: 200,
108
- * body: 'user 2'
109
- * }
110
- * });
111
- * ```
112
- *
113
- * - GET to `/api/users?id=1` will return 'user 1'.
114
- * - GET to `/api/users?id=2` will return 'user 2'.
115
- * - For all other requests, it returns a 404 status code.
116
- *
117
- * ##### Loose Match on Body
118
- *
119
- * When `strict` is set to false, it performs a loose match on query params and response body:
120
- *
121
- * ```javascript
122
- * I.addInteractionToMockServer({
123
- * strict: false,
124
- * request: {
125
- * method: 'POST',
126
- * path: '/api/users',
127
- * body: {
128
- * name: 'john'
129
- * }
130
- * },
131
- * response: {
132
- * status: 200
133
- * }
134
- * });
135
- * ```
136
- *
137
- * - POST to `/api/users` with the body containing `name` as 'john' will return a 200 status code.
138
- * - POST to `/api/users` without the `name` property in the body will return a 404 status code.
139
- *
140
- * Happy testing with MockServer in CodeceptJS! 🚀
141
- *
142
- * ## Methods
143
- */
144
- class MockServer {
145
- constructor(passedConfig) {
146
- settings.setLogLevel('SILENT');
147
- config = { ...passedConfig };
148
- if (global.debugMode) {
149
- settings.setLogLevel('VERBOSE');
150
- }
151
- }
152
-
153
- /**
154
- * Start the mock server
155
- * @param {number} [port] start the mock server with given port
156
- *
157
- * @returns void
158
- */
159
- async startMockServer(port) {
160
- const _config = { ...config };
161
- if (port) _config.port = port;
162
- await mock.setDefaults(_config);
163
- await mock.start();
164
- }
165
-
166
- /**
167
- * Stop the mock server
168
- *
169
- * @returns void
170
- *
171
- */
172
- async stopMockServer() {
173
- await mock.stop();
174
- }
175
-
176
- /**
177
- * An interaction adds behavior to the mock server
178
- *
179
- *
180
- * ```js
181
- * I.addInteractionToMockServer({
182
- * request: {
183
- * method: 'GET',
184
- * path: '/api/hello'
185
- * },
186
- * response: {
187
- * status: 200,
188
- * body: {
189
- * 'say': 'hello to mock server'
190
- * }
191
- * }
192
- * });
193
- * ```
194
- * ```js
195
- * // with query params
196
- * I.addInteractionToMockServer({
197
- * request: {
198
- * method: 'GET',
199
- * path: '/api/hello',
200
- * queryParams: {
201
- * id: 2
202
- * }
203
- * },
204
- * response: {
205
- * status: 200,
206
- * body: {
207
- * 'say': 'hello to mock server'
208
- * }
209
- * }
210
- * });
211
- * ```
212
- *
213
- * @param {CodeceptJS.MockInteraction|object} interaction add behavior to the mock server
214
- *
215
- * @returns void
216
- *
217
- */
218
- async addInteractionToMockServer(interaction) {
219
- await mock.addInteraction(interaction);
220
- }
221
- }
222
-
223
- export default MockServer;