codeceptjs 4.0.0-beta.1 → 4.0.0-beta.10.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.
Files changed (207) hide show
  1. package/README.md +133 -120
  2. package/bin/codecept.js +107 -96
  3. package/bin/test-server.js +64 -0
  4. package/docs/webapi/clearCookie.mustache +1 -1
  5. package/docs/webapi/click.mustache +5 -1
  6. package/lib/actor.js +71 -103
  7. package/lib/ai.js +159 -188
  8. package/lib/assert/empty.js +22 -24
  9. package/lib/assert/equal.js +30 -37
  10. package/lib/assert/error.js +14 -14
  11. package/lib/assert/include.js +43 -48
  12. package/lib/assert/throws.js +11 -11
  13. package/lib/assert/truth.js +22 -22
  14. package/lib/assert.js +20 -18
  15. package/lib/codecept.js +238 -162
  16. package/lib/colorUtils.js +50 -52
  17. package/lib/command/check.js +206 -0
  18. package/lib/command/configMigrate.js +56 -51
  19. package/lib/command/definitions.js +96 -109
  20. package/lib/command/dryRun.js +77 -79
  21. package/lib/command/generate.js +234 -194
  22. package/lib/command/gherkin/init.js +42 -33
  23. package/lib/command/gherkin/snippets.js +76 -74
  24. package/lib/command/gherkin/steps.js +20 -17
  25. package/lib/command/info.js +74 -38
  26. package/lib/command/init.js +300 -290
  27. package/lib/command/interactive.js +41 -32
  28. package/lib/command/list.js +28 -27
  29. package/lib/command/run-multiple/chunk.js +51 -48
  30. package/lib/command/run-multiple/collection.js +5 -5
  31. package/lib/command/run-multiple/run.js +5 -1
  32. package/lib/command/run-multiple.js +97 -97
  33. package/lib/command/run-rerun.js +19 -25
  34. package/lib/command/run-workers.js +68 -92
  35. package/lib/command/run.js +39 -27
  36. package/lib/command/utils.js +80 -64
  37. package/lib/command/workers/runTests.js +388 -226
  38. package/lib/config.js +124 -50
  39. package/lib/container.js +751 -260
  40. package/lib/data/context.js +60 -61
  41. package/lib/data/dataScenarioConfig.js +47 -47
  42. package/lib/data/dataTableArgument.js +32 -32
  43. package/lib/data/table.js +22 -22
  44. package/lib/effects.js +307 -0
  45. package/lib/element/WebElement.js +327 -0
  46. package/lib/els.js +160 -0
  47. package/lib/event.js +173 -163
  48. package/lib/globals.js +141 -0
  49. package/lib/heal.js +89 -85
  50. package/lib/helper/AI.js +131 -41
  51. package/lib/helper/ApiDataFactory.js +107 -75
  52. package/lib/helper/Appium.js +542 -404
  53. package/lib/helper/FileSystem.js +100 -79
  54. package/lib/helper/GraphQL.js +44 -43
  55. package/lib/helper/GraphQLDataFactory.js +52 -52
  56. package/lib/helper/JSONResponse.js +126 -88
  57. package/lib/helper/Mochawesome.js +54 -29
  58. package/lib/helper/Playwright.js +2547 -1316
  59. package/lib/helper/Puppeteer.js +1578 -1181
  60. package/lib/helper/REST.js +209 -68
  61. package/lib/helper/WebDriver.js +1482 -1342
  62. package/lib/helper/errors/ConnectionRefused.js +6 -6
  63. package/lib/helper/errors/ElementAssertion.js +11 -16
  64. package/lib/helper/errors/ElementNotFound.js +5 -9
  65. package/lib/helper/errors/RemoteBrowserConnectionRefused.js +5 -5
  66. package/lib/helper/extras/Console.js +11 -11
  67. package/lib/helper/extras/PlaywrightLocator.js +110 -0
  68. package/lib/helper/extras/PlaywrightPropEngine.js +18 -18
  69. package/lib/helper/extras/PlaywrightReactVueLocator.js +17 -8
  70. package/lib/helper/extras/PlaywrightRestartOpts.js +25 -11
  71. package/lib/helper/extras/Popup.js +22 -22
  72. package/lib/helper/extras/React.js +27 -28
  73. package/lib/helper/network/actions.js +36 -42
  74. package/lib/helper/network/utils.js +78 -84
  75. package/lib/helper/scripts/blurElement.js +5 -5
  76. package/lib/helper/scripts/focusElement.js +5 -5
  77. package/lib/helper/scripts/highlightElement.js +8 -8
  78. package/lib/helper/scripts/isElementClickable.js +34 -34
  79. package/lib/helper.js +2 -3
  80. package/lib/history.js +23 -19
  81. package/lib/hooks.js +8 -8
  82. package/lib/html.js +94 -104
  83. package/lib/index.js +38 -27
  84. package/lib/listener/config.js +30 -23
  85. package/lib/listener/emptyRun.js +54 -0
  86. package/lib/listener/enhancedGlobalRetry.js +110 -0
  87. package/lib/listener/exit.js +16 -18
  88. package/lib/listener/globalRetry.js +70 -0
  89. package/lib/listener/globalTimeout.js +181 -0
  90. package/lib/listener/helpers.js +76 -51
  91. package/lib/listener/mocha.js +10 -11
  92. package/lib/listener/result.js +11 -0
  93. package/lib/listener/retryEnhancer.js +85 -0
  94. package/lib/listener/steps.js +71 -59
  95. package/lib/listener/store.js +20 -0
  96. package/lib/locator.js +214 -197
  97. package/lib/mocha/asyncWrapper.js +274 -0
  98. package/lib/mocha/bdd.js +167 -0
  99. package/lib/mocha/cli.js +341 -0
  100. package/lib/mocha/factory.js +163 -0
  101. package/lib/mocha/featureConfig.js +89 -0
  102. package/lib/mocha/gherkin.js +231 -0
  103. package/lib/mocha/hooks.js +121 -0
  104. package/lib/mocha/index.js +21 -0
  105. package/lib/mocha/inject.js +46 -0
  106. package/lib/{interfaces → mocha}/scenarioConfig.js +58 -34
  107. package/lib/mocha/suite.js +89 -0
  108. package/lib/mocha/test.js +184 -0
  109. package/lib/mocha/types.d.ts +42 -0
  110. package/lib/mocha/ui.js +242 -0
  111. package/lib/output.js +141 -71
  112. package/lib/parser.js +47 -44
  113. package/lib/pause.js +173 -145
  114. package/lib/plugin/analyze.js +403 -0
  115. package/lib/plugin/{autoLogin.js → auth.js} +178 -79
  116. package/lib/plugin/autoDelay.js +36 -40
  117. package/lib/plugin/coverage.js +131 -78
  118. package/lib/plugin/customLocator.js +22 -21
  119. package/lib/plugin/customReporter.js +53 -0
  120. package/lib/plugin/enhancedRetryFailedStep.js +99 -0
  121. package/lib/plugin/heal.js +101 -110
  122. package/lib/plugin/htmlReporter.js +3648 -0
  123. package/lib/plugin/pageInfo.js +140 -0
  124. package/lib/plugin/pauseOnFail.js +12 -11
  125. package/lib/plugin/retryFailedStep.js +82 -47
  126. package/lib/plugin/screenshotOnFail.js +111 -92
  127. package/lib/plugin/stepByStepReport.js +159 -101
  128. package/lib/plugin/stepTimeout.js +20 -25
  129. package/lib/plugin/subtitles.js +38 -38
  130. package/lib/recorder.js +193 -130
  131. package/lib/rerun.js +94 -49
  132. package/lib/result.js +238 -0
  133. package/lib/retryCoordinator.js +207 -0
  134. package/lib/secret.js +20 -18
  135. package/lib/session.js +95 -89
  136. package/lib/step/base.js +239 -0
  137. package/lib/step/comment.js +10 -0
  138. package/lib/step/config.js +50 -0
  139. package/lib/step/func.js +46 -0
  140. package/lib/step/helper.js +50 -0
  141. package/lib/step/meta.js +99 -0
  142. package/lib/step/record.js +74 -0
  143. package/lib/step/retry.js +11 -0
  144. package/lib/step/section.js +55 -0
  145. package/lib/step.js +18 -329
  146. package/lib/steps.js +54 -0
  147. package/lib/store.js +38 -7
  148. package/lib/template/heal.js +3 -12
  149. package/lib/template/prompts/generatePageObject.js +31 -0
  150. package/lib/template/prompts/healStep.js +13 -0
  151. package/lib/template/prompts/writeStep.js +9 -0
  152. package/lib/test-server.js +334 -0
  153. package/lib/timeout.js +60 -0
  154. package/lib/transform.js +8 -8
  155. package/lib/translation.js +34 -21
  156. package/lib/utils/mask_data.js +47 -0
  157. package/lib/utils.js +411 -228
  158. package/lib/workerStorage.js +37 -34
  159. package/lib/workers.js +532 -296
  160. package/package.json +115 -95
  161. package/translations/de-DE.js +5 -3
  162. package/translations/fr-FR.js +5 -4
  163. package/translations/index.js +22 -12
  164. package/translations/it-IT.js +4 -3
  165. package/translations/ja-JP.js +4 -3
  166. package/translations/nl-NL.js +76 -0
  167. package/translations/pl-PL.js +4 -3
  168. package/translations/pt-BR.js +4 -3
  169. package/translations/ru-RU.js +4 -3
  170. package/translations/utils.js +10 -0
  171. package/translations/zh-CN.js +4 -3
  172. package/translations/zh-TW.js +4 -3
  173. package/typings/index.d.ts +546 -185
  174. package/typings/promiseBasedTypes.d.ts +150 -879
  175. package/typings/types.d.ts +547 -996
  176. package/lib/cli.js +0 -249
  177. package/lib/dirname.js +0 -5
  178. package/lib/helper/Expect.js +0 -425
  179. package/lib/helper/ExpectHelper.js +0 -399
  180. package/lib/helper/MockServer.js +0 -223
  181. package/lib/helper/Nightmare.js +0 -1411
  182. package/lib/helper/Protractor.js +0 -1835
  183. package/lib/helper/SoftExpectHelper.js +0 -381
  184. package/lib/helper/TestCafe.js +0 -1410
  185. package/lib/helper/clientscripts/nightmare.js +0 -213
  186. package/lib/helper/testcafe/testControllerHolder.js +0 -42
  187. package/lib/helper/testcafe/testcafe-utils.js +0 -63
  188. package/lib/interfaces/bdd.js +0 -98
  189. package/lib/interfaces/featureConfig.js +0 -69
  190. package/lib/interfaces/gherkin.js +0 -195
  191. package/lib/listener/artifacts.js +0 -19
  192. package/lib/listener/retry.js +0 -68
  193. package/lib/listener/timeout.js +0 -109
  194. package/lib/mochaFactory.js +0 -110
  195. package/lib/plugin/allure.js +0 -15
  196. package/lib/plugin/commentStep.js +0 -136
  197. package/lib/plugin/debugErrors.js +0 -67
  198. package/lib/plugin/eachElement.js +0 -127
  199. package/lib/plugin/fakerTransform.js +0 -49
  200. package/lib/plugin/retryTo.js +0 -121
  201. package/lib/plugin/selenoid.js +0 -371
  202. package/lib/plugin/standardActingHelpers.js +0 -9
  203. package/lib/plugin/tryTo.js +0 -105
  204. package/lib/plugin/wdio.js +0 -246
  205. package/lib/scenario.js +0 -222
  206. package/lib/ui.js +0 -238
  207. package/lib/within.js +0 -70
@@ -1,399 +0,0 @@
1
- import * as output from '../output.js';
2
-
3
- import { expect } from 'chai'
4
-
5
- import('chai').then((chai) => {
6
- chai.use(require('chai-string'))
7
- // @ts-ignore
8
- chai.use(require('chai-exclude'))
9
- chai.use(require('chai-match-pattern'))
10
- chai.use(require('chai-json-schema'))
11
- })
12
-
13
- /**
14
- * This helper allows performing assertions based on Chai.
15
- *
16
- * ### Examples
17
- *
18
- * Zero-configuration when paired with other helpers like REST, Playwright:
19
- *
20
- * ```js
21
- * // inside codecept.conf.js
22
- *{
23
- * helpers: {
24
- * Playwright: {...},
25
- * ExpectHelper: {},
26
- * }
27
- *}
28
- * ```
29
- *
30
- * ## Methods
31
- */
32
- class ExpectHelper {
33
- /**
34
- *
35
- * @param {*} actualValue
36
- * @param {*} expectedValue
37
- * @param {*} [customErrorMsg]
38
- */
39
- expectEqual(actualValue, expectedValue, customErrorMsg = '') {
40
- // @ts-ignore
41
- output.output.step(`I expect "${JSON.stringify(actualValue)}" to equal "${JSON.stringify(expectedValue)}"`)
42
- return expect(actualValue, customErrorMsg).to.equal(expectedValue)
43
- }
44
-
45
- /**
46
- *
47
- * @param {*} actualValue
48
- * @param {*} expectedValue
49
- * @param {*} [customErrorMsg]
50
- */
51
- expectNotEqual(actualValue, expectedValue, customErrorMsg = '') {
52
- // @ts-ignore
53
- output.output.step(`I expect "${JSON.stringify(actualValue)}" to not equal "${JSON.stringify(expectedValue)}"`)
54
- return expect(actualValue, customErrorMsg).not.to.equal(expectedValue)
55
- }
56
-
57
- /**
58
- *
59
- * @param {*} actualValue
60
- * @param {*} expectedValue
61
- * @param {*} [customErrorMsg]
62
-
63
- */
64
- expectDeepEqual(actualValue, expectedValue, customErrorMsg = '') {
65
- // @ts-ignore
66
- output.output.step(`I expect "${JSON.stringify(actualValue)}" to deep equal "${JSON.stringify(expectedValue)}"`)
67
- return expect(actualValue, customErrorMsg).to.deep.equal(expectedValue)
68
- }
69
-
70
- /**
71
- *
72
- * @param {*} actualValue
73
- * @param {*} expectedValue
74
- * @param {*} [customErrorMsg]
75
- */
76
- expectNotDeepEqual(actualValue, expectedValue, customErrorMsg = '') {
77
- // @ts-ignore
78
- output.output.step(`I expect "${JSON.stringify(actualValue)}" to not deep equal "${JSON.stringify(expectedValue)}"`)
79
- return expect(actualValue, customErrorMsg).to.not.deep.equal(expectedValue)
80
- }
81
-
82
- /**
83
- *
84
- * @param {*} actualValue
85
- * @param {*} expectedValueToContain
86
- * @param {*} [customErrorMsg]
87
- */
88
- expectContain(actualValue, expectedValueToContain, customErrorMsg = '') {
89
- // @ts-ignore
90
- output.output.step(`I expect "${JSON.stringify(actualValue)}" to contain "${JSON.stringify(expectedValueToContain)}"`)
91
- return expect(actualValue, customErrorMsg).to.contain(expectedValueToContain)
92
- }
93
-
94
- /**
95
- *
96
- * @param {*} actualValue
97
- * @param {*} expectedValueToNotContain
98
- * @param {*} [customErrorMsg]
99
- */
100
- expectNotContain(actualValue, expectedValueToNotContain, customErrorMsg = '') {
101
- // @ts-ignore
102
- output.output.step(
103
- `I expect "${JSON.stringify(actualValue)}" to not contain "${JSON.stringify(expectedValueToNotContain)}"`,
104
- )
105
- return expect(actualValue, customErrorMsg).not.to.contain(expectedValueToNotContain)
106
- }
107
-
108
- /**
109
- *
110
- * @param {*} actualValue
111
- * @param {*} expectedValueToStartWith
112
- * @param {*} [customErrorMsg]
113
- */
114
- expectStartsWith(actualValue, expectedValueToStartWith, customErrorMsg = '') {
115
- // Log the step output
116
- output.output.step(`I expect "${JSON.stringify(actualValue)}" to start with "${JSON.stringify(expectedValueToStartWith)}"`);
117
-
118
- // Check if actualValue is a string
119
- expect(actualValue, customErrorMsg).to.be.a('string');
120
-
121
- // Check if actualValue starts with expectedValueToStartWith
122
- expect(actualValue.startsWith(expectedValueToStartWith), customErrorMsg).to.be.true;
123
- }
124
-
125
-
126
- /**
127
- *
128
- * @param {*} actualValue
129
- * @param {*} expectedValueToNotStartWith
130
- * @param {*} [customErrorMsg]
131
- */
132
- expectNotStartsWith(actualValue, expectedValueToNotStartWith, customErrorMsg = '') {
133
- // Log the step output
134
- output.output.step(`I expect "${JSON.stringify(actualValue)}" to not start with "${JSON.stringify(expectedValueToNotStartWith)}"`);
135
-
136
- // Check if actualValue is a string
137
- expect(actualValue, customErrorMsg).to.be.a('string');
138
-
139
- // Check if actualValue starts with expectedValueToStartWith
140
- expect(actualValue.startsWith(expectedValueToNotStartWith), customErrorMsg).to.be.false;
141
- }
142
-
143
- /**
144
- * @param {*} actualValue
145
- * @param {*} expectedValueToEndWith
146
- * @param {*} [customErrorMsg]
147
- */
148
- expectEndsWith(actualValue, expectedValueToEndWith, customErrorMsg = '') {
149
- // @ts-ignore
150
- output.output.step(`I expect "${JSON.stringify(actualValue)}" to end with "${JSON.stringify(expectedValueToEndWith)}"`)
151
- return expect(actualValue, customErrorMsg).to.endsWith(expectedValueToEndWith)
152
- }
153
-
154
- /**
155
- * @param {*} actualValue
156
- * @param {*} expectedValueToNotEndWith
157
- * @param {*} [customErrorMsg]
158
- */
159
- expectNotEndsWith(actualValue, expectedValueToNotEndWith, customErrorMsg = '') {
160
- // @ts-ignore
161
- output.output.step(
162
- `I expect "${JSON.stringify(actualValue)}" to not end with "${JSON.stringify(expectedValueToNotEndWith)}"`,
163
- )
164
- return expect(actualValue, customErrorMsg).not.to.endsWith(expectedValueToNotEndWith)
165
- }
166
-
167
- /**
168
- * @param {*} targetData
169
- * @param {*} jsonSchema
170
- * @param {*} [customErrorMsg]
171
- */
172
- expectJsonSchema(targetData, jsonSchema, customErrorMsg = '') {
173
- // @ts-ignore
174
- output.output.step(`I expect "${JSON.stringify(targetData)}" to match this JSON schema "${JSON.stringify(jsonSchema)}"`)
175
-
176
- return expect(targetData, customErrorMsg).to.be.jsonSchema(jsonSchema)
177
- }
178
-
179
- /**
180
- * @param {*} targetData
181
- * @param {*} jsonSchema
182
- * @param {*} [customErrorMsg]
183
- * @param {*} [ajvOptions] Pass AJV options
184
- */
185
- expectJsonSchemaUsingAJV(targetData, jsonSchema, customErrorMsg = '', ajvOptions = { allErrors: true }) {
186
- // @ts-ignore
187
- output.output.step(
188
- `I expect "${JSON.stringify(targetData)}" to match this JSON schema using AJV "${JSON.stringify(jsonSchema)}"`,
189
- )
190
- chai.use(require('chai-json-schema-ajv').create(ajvOptions))
191
- return expect(targetData, customErrorMsg).to.be.jsonSchema(jsonSchema)
192
- }
193
-
194
- /**
195
- * @param {*} targetData
196
- * @param {*} propertyName
197
- * @param {*} [customErrorMsg]
198
- */
199
- expectHasProperty(targetData, propertyName, customErrorMsg = '') {
200
- // @ts-ignore
201
- output.output.step(`I expect "${JSON.stringify(targetData)}" to have property: "${JSON.stringify(propertyName)}"`)
202
- return expect(targetData, customErrorMsg).to.have.property(propertyName)
203
- }
204
-
205
- /**
206
- * @param {*} targetData
207
- * @param {*} propertyName
208
- * @param {*} [customErrorMsg]
209
- */
210
- expectHasAProperty(targetData, propertyName, customErrorMsg = '') {
211
- // @ts-ignore
212
- output.output.step(`I expect "${JSON.stringify(targetData)}" to have a property: "${JSON.stringify(propertyName)}"`)
213
- return expect(targetData, customErrorMsg).to.have.a.property(propertyName)
214
- }
215
-
216
- /**
217
- * @param {*} targetData
218
- * @param {*} type
219
- * @param {*} [customErrorMsg]
220
- */
221
- expectToBeA(targetData, type, customErrorMsg = '') {
222
- // @ts-ignore
223
- output.output.step(`I expect "${JSON.stringify(targetData)}" to be a "${JSON.stringify(type)}"`)
224
- return expect(targetData, customErrorMsg).to.be.a(type)
225
- }
226
-
227
- /**
228
- * @param {*} targetData
229
- * @param {*} type
230
- * @param {*} [customErrorMsg]
231
- */
232
- expectToBeAn(targetData, type, customErrorMsg = '') {
233
- // @ts-ignore
234
- output.output.step(`I expect "${JSON.stringify(targetData)}" to be an "${JSON.stringify(type)}"`)
235
- return expect(targetData, customErrorMsg).to.be.an(type)
236
- }
237
-
238
- /**
239
- * @param {*} targetData
240
- * @param {*} regex
241
- * @param {*} [customErrorMsg]
242
- */
243
- expectMatchRegex(targetData, regex, customErrorMsg = '') {
244
- // @ts-ignore
245
- output.output.step(`I expect "${JSON.stringify(targetData)}" to match the regex "${JSON.stringify(regex)}"`)
246
- return expect(targetData, customErrorMsg).to.match(regex)
247
- }
248
-
249
- /**
250
- * @param {*} targetData
251
- * @param {*} length
252
- * @param {*} [customErrorMsg]
253
- */
254
- expectLengthOf(targetData, length, customErrorMsg = '') {
255
- // @ts-ignore
256
- output.output.step(`I expect "${JSON.stringify(targetData)}" to have length of "${JSON.stringify(length)}"`)
257
- return expect(targetData, customErrorMsg).to.have.lengthOf(length)
258
- }
259
-
260
- /**
261
- * @param {*} targetData
262
- * @param {*} [customErrorMsg]
263
- */
264
- expectEmpty(targetData, customErrorMsg = '') {
265
- // @ts-ignore
266
- output.output.step(`I expect "${JSON.stringify(targetData)}" to be empty`)
267
- return expect(targetData, customErrorMsg).to.be.empty
268
- }
269
-
270
- /**
271
- * @param {*} targetData
272
- * @param {*} [customErrorMsg]
273
- */
274
- expectTrue(targetData, customErrorMsg = '') {
275
- // @ts-ignore
276
- output.output.step(`I expect "${JSON.stringify(targetData)}" to be true`)
277
- return expect(targetData, customErrorMsg).to.be.true
278
- }
279
-
280
- /**
281
- * @param {*} targetData
282
- * @param {*} [customErrorMsg]
283
- */
284
- expectFalse(targetData, customErrorMsg = '') {
285
- // @ts-ignore
286
- output.output.step(`I expect "${JSON.stringify(targetData)}" to be false`)
287
- return expect(targetData, customErrorMsg).to.be.false
288
- }
289
-
290
- /**
291
- * @param {*} targetData
292
- * @param {*} aboveThan
293
- * @param {*} [customErrorMsg]
294
- */
295
- expectAbove(targetData, aboveThan, customErrorMsg = '') {
296
- // @ts-ignore
297
- output.output.step(`I expect "${JSON.stringify(targetData)}" to be above ${JSON.stringify(aboveThan)}`)
298
- return expect(targetData, customErrorMsg).to.be.above(aboveThan)
299
- }
300
-
301
- /**
302
- * @param {*} targetData
303
- * @param {*} belowThan
304
- * @param {*} [customErrorMsg]
305
- */
306
- expectBelow(targetData, belowThan, customErrorMsg = '') {
307
- // @ts-ignore
308
- output.output.step(`I expect "${JSON.stringify(targetData)}" to be below ${JSON.stringify(belowThan)}`)
309
- return expect(targetData, customErrorMsg).to.be.below(belowThan)
310
- }
311
-
312
- /**
313
- * @param {*} targetData
314
- * @param {*} lengthAboveThan
315
- * @param {*} [customErrorMsg]
316
- */
317
- expectLengthAboveThan(targetData, lengthAboveThan, customErrorMsg = '') {
318
- // @ts-ignore
319
- output.output.step(`I expect "${JSON.stringify(targetData)}" to have length of above ${JSON.stringify(lengthAboveThan)}`)
320
- return expect(targetData, customErrorMsg).to.have.lengthOf.above(lengthAboveThan)
321
- }
322
-
323
- /**
324
- * @param {*} targetData
325
- * @param {*} lengthBelowThan
326
- * @param {*} [customErrorMsg]
327
- */
328
- expectLengthBelowThan(targetData, lengthBelowThan, customErrorMsg = '') {
329
- // @ts-ignore
330
- output.output.step(`I expect "${JSON.stringify(targetData)}" to have length of below ${JSON.stringify(lengthBelowThan)}`)
331
- return expect(targetData, customErrorMsg).to.have.lengthOf.below(lengthBelowThan)
332
- }
333
-
334
- /**
335
- * @param {*} actualValue
336
- * @param {*} expectedValue
337
- * @param {*} [customErrorMsg]
338
- */
339
- expectEqualIgnoreCase(actualValue, expectedValue, customErrorMsg = '') {
340
- // @ts-ignore
341
- output.output.step(`I expect and ingore case "${JSON.stringify(actualValue)}" to equal "${JSON.stringify(expectedValue)}"`)
342
- return expect(actualValue, customErrorMsg).to.equalIgnoreCase(expectedValue)
343
- }
344
-
345
- /**
346
- * expects members of two arrays are deeply equal
347
- * @param {*} actualValue
348
- * @param {*} expectedValue
349
- * @param {*} [customErrorMsg]
350
- */
351
- expectDeepMembers(actualValue, expectedValue, customErrorMsg = '') {
352
- // @ts-ignore
353
- output.output.step(
354
- `I expect members of "${JSON.stringify(actualValue)}" and "${JSON.stringify(expectedValue)}" arrays are deeply equal`,
355
- )
356
- return expect(actualValue, customErrorMsg).to.have.deep.members(expectedValue)
357
- }
358
-
359
- /**
360
- * expects an array to be a superset of another array
361
- * @param {*} superset
362
- * @param {*} set
363
- * @param {*} [customErrorMsg]
364
- */
365
- expectDeepIncludeMembers(superset, set, customErrorMsg = '') {
366
- // @ts-ignore
367
- output.output.step(`I expect "${JSON.stringify(superset)}" array to be a superset of "${JSON.stringify(set)}" array`)
368
- return expect(superset, customErrorMsg).to.deep.include.members(set)
369
- }
370
-
371
- /**
372
- * expects members of two JSON objects are deeply equal excluding some properties
373
- * @param {*} actualValue
374
- * @param {*} expectedValue
375
- * @param {*} fieldsToExclude
376
- * @param {*} [customErrorMsg]
377
- */
378
- expectDeepEqualExcluding(actualValue, expectedValue, fieldsToExclude, customErrorMsg = '') {
379
- // @ts-ignore
380
- output.output.step(
381
- `I expect members of "${JSON.stringify(actualValue)}" and "${JSON.stringify(expectedValue)}" JSON objects are deeply equal excluding properties: ${JSON.stringify(fieldsToExclude)}`,
382
- )
383
- return expect(actualValue, customErrorMsg).excludingEvery(fieldsToExclude).to.deep.equal(expectedValue)
384
- }
385
-
386
- /**
387
- * expects a JSON object matches a provided pattern
388
- * @param {*} actualValue
389
- * @param {*} expectedPattern
390
- * @param {*} [customErrorMsg]
391
- */
392
- expectMatchesPattern(actualValue, expectedPattern, customErrorMsg = '') {
393
- // @ts-ignore
394
- output.output.step(`I expect "${JSON.stringify(actualValue)}" to match the ${JSON.stringify(expectedPattern)} pattern`)
395
- return expect(actualValue, customErrorMsg).to.matchPattern(expectedPattern)
396
- }
397
- }
398
-
399
- 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;