codeceptjs 4.0.0-beta.3 → 4.0.0-beta.5

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 (155) hide show
  1. package/README.md +134 -119
  2. package/bin/codecept.js +12 -2
  3. package/bin/test-server.js +53 -0
  4. package/docs/webapi/clearCookie.mustache +1 -1
  5. package/lib/actor.js +66 -102
  6. package/lib/ai.js +130 -121
  7. package/lib/assert/empty.js +3 -5
  8. package/lib/assert/equal.js +4 -7
  9. package/lib/assert/include.js +4 -6
  10. package/lib/assert/throws.js +2 -4
  11. package/lib/assert/truth.js +2 -2
  12. package/lib/codecept.js +141 -86
  13. package/lib/command/check.js +201 -0
  14. package/lib/command/configMigrate.js +2 -4
  15. package/lib/command/definitions.js +8 -26
  16. package/lib/command/dryRun.js +30 -35
  17. package/lib/command/generate.js +10 -14
  18. package/lib/command/gherkin/snippets.js +75 -73
  19. package/lib/command/gherkin/steps.js +1 -1
  20. package/lib/command/info.js +42 -8
  21. package/lib/command/init.js +13 -12
  22. package/lib/command/interactive.js +10 -2
  23. package/lib/command/list.js +1 -1
  24. package/lib/command/run-multiple/chunk.js +48 -45
  25. package/lib/command/run-multiple.js +12 -35
  26. package/lib/command/run-workers.js +21 -58
  27. package/lib/command/utils.js +5 -6
  28. package/lib/command/workers/runTests.js +263 -222
  29. package/lib/container.js +386 -238
  30. package/lib/data/context.js +10 -13
  31. package/lib/data/dataScenarioConfig.js +8 -8
  32. package/lib/data/dataTableArgument.js +6 -6
  33. package/lib/data/table.js +5 -11
  34. package/lib/effects.js +223 -0
  35. package/lib/element/WebElement.js +327 -0
  36. package/lib/els.js +158 -0
  37. package/lib/event.js +21 -17
  38. package/lib/heal.js +88 -80
  39. package/lib/helper/AI.js +2 -1
  40. package/lib/helper/ApiDataFactory.js +4 -7
  41. package/lib/helper/Appium.js +50 -57
  42. package/lib/helper/FileSystem.js +3 -3
  43. package/lib/helper/GraphQLDataFactory.js +4 -4
  44. package/lib/helper/JSONResponse.js +75 -37
  45. package/lib/helper/Mochawesome.js +31 -9
  46. package/lib/helper/Nightmare.js +37 -58
  47. package/lib/helper/Playwright.js +267 -272
  48. package/lib/helper/Protractor.js +56 -87
  49. package/lib/helper/Puppeteer.js +247 -264
  50. package/lib/helper/REST.js +29 -17
  51. package/lib/helper/TestCafe.js +22 -47
  52. package/lib/helper/WebDriver.js +157 -368
  53. package/lib/helper/extras/PlaywrightPropEngine.js +2 -2
  54. package/lib/helper/extras/Popup.js +22 -22
  55. package/lib/helper/network/utils.js +1 -1
  56. package/lib/helper/testcafe/testcafe-utils.js +27 -28
  57. package/lib/listener/emptyRun.js +55 -0
  58. package/lib/listener/exit.js +7 -10
  59. package/lib/listener/{retry.js → globalRetry.js} +5 -5
  60. package/lib/listener/globalTimeout.js +165 -0
  61. package/lib/listener/helpers.js +15 -15
  62. package/lib/listener/mocha.js +1 -1
  63. package/lib/listener/result.js +12 -0
  64. package/lib/listener/retryEnhancer.js +85 -0
  65. package/lib/listener/steps.js +32 -18
  66. package/lib/listener/store.js +20 -0
  67. package/lib/locator.js +1 -1
  68. package/lib/mocha/asyncWrapper.js +231 -0
  69. package/lib/{interfaces → mocha}/bdd.js +3 -3
  70. package/lib/mocha/cli.js +308 -0
  71. package/lib/mocha/factory.js +104 -0
  72. package/lib/{interfaces → mocha}/featureConfig.js +32 -12
  73. package/lib/{interfaces → mocha}/gherkin.js +26 -28
  74. package/lib/mocha/hooks.js +112 -0
  75. package/lib/mocha/index.js +12 -0
  76. package/lib/mocha/inject.js +29 -0
  77. package/lib/{interfaces → mocha}/scenarioConfig.js +31 -7
  78. package/lib/mocha/suite.js +82 -0
  79. package/lib/mocha/test.js +181 -0
  80. package/lib/mocha/types.d.ts +42 -0
  81. package/lib/mocha/ui.js +232 -0
  82. package/lib/output.js +93 -65
  83. package/lib/pause.js +160 -138
  84. package/lib/plugin/analyze.js +396 -0
  85. package/lib/plugin/auth.js +435 -0
  86. package/lib/plugin/autoDelay.js +8 -8
  87. package/lib/plugin/autoLogin.js +3 -338
  88. package/lib/plugin/commentStep.js +6 -1
  89. package/lib/plugin/coverage.js +10 -22
  90. package/lib/plugin/customLocator.js +3 -3
  91. package/lib/plugin/customReporter.js +52 -0
  92. package/lib/plugin/eachElement.js +1 -1
  93. package/lib/plugin/fakerTransform.js +1 -1
  94. package/lib/plugin/heal.js +36 -9
  95. package/lib/plugin/htmlReporter.js +1947 -0
  96. package/lib/plugin/pageInfo.js +140 -0
  97. package/lib/plugin/retryFailedStep.js +17 -18
  98. package/lib/plugin/retryTo.js +2 -113
  99. package/lib/plugin/screenshotOnFail.js +17 -58
  100. package/lib/plugin/selenoid.js +15 -35
  101. package/lib/plugin/standardActingHelpers.js +4 -1
  102. package/lib/plugin/stepByStepReport.js +56 -17
  103. package/lib/plugin/stepTimeout.js +5 -12
  104. package/lib/plugin/subtitles.js +4 -4
  105. package/lib/plugin/tryTo.js +3 -102
  106. package/lib/plugin/wdio.js +8 -10
  107. package/lib/recorder.js +155 -124
  108. package/lib/rerun.js +43 -42
  109. package/lib/result.js +161 -0
  110. package/lib/secret.js +1 -2
  111. package/lib/step/base.js +239 -0
  112. package/lib/step/comment.js +10 -0
  113. package/lib/step/config.js +50 -0
  114. package/lib/step/func.js +46 -0
  115. package/lib/step/helper.js +50 -0
  116. package/lib/step/meta.js +99 -0
  117. package/lib/step/record.js +74 -0
  118. package/lib/step/retry.js +11 -0
  119. package/lib/step/section.js +55 -0
  120. package/lib/step.js +21 -332
  121. package/lib/steps.js +50 -0
  122. package/lib/store.js +37 -5
  123. package/lib/template/heal.js +2 -11
  124. package/lib/test-server.js +323 -0
  125. package/lib/timeout.js +66 -0
  126. package/lib/utils.js +351 -218
  127. package/lib/within.js +75 -55
  128. package/lib/workerStorage.js +2 -1
  129. package/lib/workers.js +386 -277
  130. package/package.json +81 -75
  131. package/translations/de-DE.js +5 -3
  132. package/translations/fr-FR.js +5 -4
  133. package/translations/index.js +1 -0
  134. package/translations/it-IT.js +4 -3
  135. package/translations/ja-JP.js +4 -3
  136. package/translations/nl-NL.js +76 -0
  137. package/translations/pl-PL.js +4 -3
  138. package/translations/pt-BR.js +4 -3
  139. package/translations/ru-RU.js +4 -3
  140. package/translations/utils.js +9 -0
  141. package/translations/zh-CN.js +4 -3
  142. package/translations/zh-TW.js +4 -3
  143. package/typings/index.d.ts +197 -187
  144. package/typings/promiseBasedTypes.d.ts +53 -903
  145. package/typings/types.d.ts +372 -1042
  146. package/lib/cli.js +0 -257
  147. package/lib/helper/ExpectHelper.js +0 -391
  148. package/lib/helper/MockServer.js +0 -221
  149. package/lib/helper/SoftExpectHelper.js +0 -381
  150. package/lib/listener/artifacts.js +0 -19
  151. package/lib/listener/timeout.js +0 -109
  152. package/lib/mochaFactory.js +0 -113
  153. package/lib/plugin/debugErrors.js +0 -67
  154. package/lib/scenario.js +0 -224
  155. package/lib/ui.js +0 -236
@@ -1,221 +0,0 @@
1
- const { mock, settings } = require('pactum')
2
-
3
- /**
4
- * ## Configuration
5
- *
6
- * This helper should be configured in codecept.conf.(js|ts)
7
- *
8
- * @typedef MockServerConfig
9
- * @type {object}
10
- * @prop {number} [port=9393] - Mock server port
11
- * @prop {string} [host="0.0.0.0"] - Mock server host
12
- * @prop {object} [httpsOpts] - key & cert values are the paths to .key and .crt files
13
- */
14
- let config = {
15
- port: 9393,
16
- host: '0.0.0.0',
17
- httpsOpts: {
18
- key: '',
19
- cert: '',
20
- },
21
- }
22
-
23
- /**
24
- * MockServer
25
- *
26
- * 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.
27
- *
28
- * <!-- configuration -->
29
- *
30
- * #### Examples
31
- *
32
- * You can seamlessly integrate MockServer with other helpers like REST or Playwright. Here's a configuration example inside the `codecept.conf.js` file:
33
- *
34
- * ```javascript
35
- * {
36
- * helpers: {
37
- * REST: {...},
38
- * MockServer: {
39
- * // default mock server config
40
- * port: 9393,
41
- * host: '0.0.0.0',
42
- * httpsOpts: {
43
- * key: '',
44
- * cert: '',
45
- * },
46
- * },
47
- * }
48
- * }
49
- * ```
50
- *
51
- * #### Adding Interactions
52
- *
53
- * 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.
54
- *
55
- * ```javascript
56
- * I.addInteractionToMockServer({
57
- * request: {
58
- * method: 'GET',
59
- * path: '/api/hello'
60
- * },
61
- * response: {
62
- * status: 200,
63
- * body: {
64
- * 'say': 'hello to mock server'
65
- * }
66
- * }
67
- * });
68
- * ```
69
- *
70
- * #### Request Matching
71
- *
72
- * 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.
73
- *
74
- * - Strong match on HTTP Method, Path, Query Params & JSON body.
75
- * - Loose match on Headers.
76
- *
77
- * ##### Strong Match on Query Params
78
- *
79
- * You can send different responses based on query parameters:
80
- *
81
- * ```javascript
82
- * I.addInteractionToMockServer({
83
- * request: {
84
- * method: 'GET',
85
- * path: '/api/users',
86
- * queryParams: {
87
- * id: 1
88
- * }
89
- * },
90
- * response: {
91
- * status: 200,
92
- * body: 'user 1'
93
- * }
94
- * });
95
- *
96
- * I.addInteractionToMockServer({
97
- * request: {
98
- * method: 'GET',
99
- * path: '/api/users',
100
- * queryParams: {
101
- * id: 2
102
- * }
103
- * },
104
- * response: {
105
- * status: 200,
106
- * body: 'user 2'
107
- * }
108
- * });
109
- * ```
110
- *
111
- * - GET to `/api/users?id=1` will return 'user 1'.
112
- * - GET to `/api/users?id=2` will return 'user 2'.
113
- * - For all other requests, it returns a 404 status code.
114
- *
115
- * ##### Loose Match on Body
116
- *
117
- * When `strict` is set to false, it performs a loose match on query params and response body:
118
- *
119
- * ```javascript
120
- * I.addInteractionToMockServer({
121
- * strict: false,
122
- * request: {
123
- * method: 'POST',
124
- * path: '/api/users',
125
- * body: {
126
- * name: 'john'
127
- * }
128
- * },
129
- * response: {
130
- * status: 200
131
- * }
132
- * });
133
- * ```
134
- *
135
- * - POST to `/api/users` with the body containing `name` as 'john' will return a 200 status code.
136
- * - POST to `/api/users` without the `name` property in the body will return a 404 status code.
137
- *
138
- * Happy testing with MockServer in CodeceptJS! 🚀
139
- *
140
- * ## Methods
141
- */
142
- class MockServer {
143
- constructor(passedConfig) {
144
- settings.setLogLevel('SILENT')
145
- config = { ...passedConfig }
146
- if (global.debugMode) {
147
- settings.setLogLevel('VERBOSE')
148
- }
149
- }
150
-
151
- /**
152
- * Start the mock server
153
- * @param {number} [port] start the mock server with given port
154
- *
155
- * @returns void
156
- */
157
- async startMockServer(port) {
158
- const _config = { ...config }
159
- if (port) _config.port = port
160
- await mock.setDefaults(_config)
161
- await mock.start()
162
- }
163
-
164
- /**
165
- * Stop the mock server
166
- *
167
- * @returns void
168
- *
169
- */
170
- async stopMockServer() {
171
- await mock.stop()
172
- }
173
-
174
- /**
175
- * An interaction adds behavior to the mock server
176
- *
177
- *
178
- * ```js
179
- * I.addInteractionToMockServer({
180
- * request: {
181
- * method: 'GET',
182
- * path: '/api/hello'
183
- * },
184
- * response: {
185
- * status: 200,
186
- * body: {
187
- * 'say': 'hello to mock server'
188
- * }
189
- * }
190
- * });
191
- * ```
192
- * ```js
193
- * // with query params
194
- * I.addInteractionToMockServer({
195
- * request: {
196
- * method: 'GET',
197
- * path: '/api/hello',
198
- * queryParams: {
199
- * id: 2
200
- * }
201
- * },
202
- * response: {
203
- * status: 200,
204
- * body: {
205
- * 'say': 'hello to mock server'
206
- * }
207
- * }
208
- * });
209
- * ```
210
- *
211
- * @param {CodeceptJS.MockInteraction|object} interaction add behavior to the mock server
212
- *
213
- * @returns void
214
- *
215
- */
216
- async addInteractionToMockServer(interaction) {
217
- await mock.addInteraction(interaction)
218
- }
219
- }
220
-
221
- module.exports = MockServer
@@ -1,381 +0,0 @@
1
- const ExpectHelper = require('./ExpectHelper')
2
-
3
- /**
4
- * SoftAssertHelper is a utility class for performing soft assertions.
5
- * Unlike traditional assertions that stop the execution on failure,
6
- * soft assertions allow the execution to continue and report all failures at the end.
7
- *
8
- * ### Examples
9
- *
10
- * Zero-configuration when paired with other helpers like REST, Playwright:
11
- *
12
- * ```js
13
- * // inside codecept.conf.js
14
- * {
15
- * helpers: {
16
- * Playwright: {...},
17
- * SoftExpectHelper: {},
18
- * }
19
- * }
20
- * ```
21
- *
22
- * ```js
23
- * // in scenario
24
- * I.softExpectEqual('a', 'b')
25
- * I.flushSoftAssertions() // Throws an error if any soft assertions have failed. The error message contains all the accumulated failures.
26
- * ```
27
- *
28
- * ## Methods
29
- */
30
- class SoftAssertHelper extends ExpectHelper {
31
- constructor() {
32
- super()
33
- this.errors = []
34
- }
35
-
36
- /**
37
- * Performs a soft assertion by executing the provided assertion function.
38
- * If the assertion fails, the error is caught and stored without halting the execution.
39
- *
40
- * @param {Function} assertionFn - The assertion function to execute.
41
- * @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails.
42
- */
43
- softAssert(assertionFn, customErrorMsg = '') {
44
- try {
45
- assertionFn()
46
- } catch (error) {
47
- this.errors.push({ customErrorMsg, error })
48
- }
49
- }
50
-
51
- /**
52
- * Throws an error if any soft assertions have failed.
53
- * The error message contains all the accumulated failures.
54
- *
55
- * @throws {Error} If there are any soft assertion failures.
56
- */
57
- flushSoftAssertions() {
58
- if (this.errors.length > 0) {
59
- let errorMessage = 'Soft assertions failed:\n'
60
- this.errors.forEach((err, index) => {
61
- errorMessage += `\n[${index + 1}] ${err.customErrorMsg}\n${err.error.message}\n`
62
- })
63
- this.errors = []
64
- throw new Error(errorMessage)
65
- }
66
- }
67
-
68
- /**
69
- * Softly asserts that two values are equal.
70
- *
71
- * @param {*} actualValue - The actual value.
72
- * @param {*} expectedValue - The expected value.
73
- * @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails.
74
- */
75
- softExpectEqual(actualValue, expectedValue, customErrorMsg = '') {
76
- this.softAssert(() => this.expectEqual(actualValue, expectedValue, customErrorMsg), customErrorMsg)
77
- }
78
-
79
- /**
80
- * Softly asserts that two values are not equal.
81
- *
82
- * @param {*} actualValue - The actual value.
83
- * @param {*} expectedValue - The expected value.
84
- * @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails.
85
- */
86
- softExpectNotEqual(actualValue, expectedValue, customErrorMsg = '') {
87
- this.softAssert(() => this.expectNotEqual(actualValue, expectedValue, customErrorMsg), customErrorMsg)
88
- }
89
-
90
- /**
91
- * Softly asserts that two values are deeply equal.
92
- *
93
- * @param {*} actualValue - The actual value.
94
- * @param {*} expectedValue - The expected value.
95
- * @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails.
96
- */
97
- softExpectDeepEqual(actualValue, expectedValue, customErrorMsg = '') {
98
- this.softAssert(() => this.expectDeepEqual(actualValue, expectedValue, customErrorMsg), customErrorMsg)
99
- }
100
-
101
- /**
102
- * Softly asserts that two values are not deeply equal.
103
- *
104
- * @param {*} actualValue - The actual value.
105
- * @param {*} expectedValue - The expected value.
106
- * @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails.
107
- */
108
- softExpectNotDeepEqual(actualValue, expectedValue, customErrorMsg = '') {
109
- this.softAssert(() => this.expectNotDeepEqual(actualValue, expectedValue, customErrorMsg), customErrorMsg)
110
- }
111
-
112
- /**
113
- * Softly asserts that a value contains the expected value.
114
- *
115
- * @param {*} actualValue - The actual value.
116
- * @param {*} expectedValueToContain - The value that should be contained within the actual value.
117
- * @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails.
118
- */
119
- softExpectContain(actualValue, expectedValueToContain, customErrorMsg = '') {
120
- this.softAssert(() => this.expectContain(actualValue, expectedValueToContain, customErrorMsg), customErrorMsg)
121
- }
122
-
123
- /**
124
- * Softly asserts that a value does not contain the expected value.
125
- *
126
- * @param {*} actualValue - The actual value.
127
- * @param {*} expectedValueToNotContain - The value that should not be contained within the actual value.
128
- * @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails.
129
- */
130
- softExpectNotContain(actualValue, expectedValueToNotContain, customErrorMsg = '') {
131
- this.softAssert(() => this.expectNotContain(actualValue, expectedValueToNotContain, customErrorMsg), customErrorMsg)
132
- }
133
-
134
- /**
135
- * Softly asserts that a value starts with the expected value.
136
- *
137
- * @param {*} actualValue - The actual value.
138
- * @param {*} expectedValueToStartWith - The value that the actual value should start with.
139
- * @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails.
140
- */
141
- softExpectStartsWith(actualValue, expectedValueToStartWith, customErrorMsg = '') {
142
- this.softAssert(() => this.expectStartsWith(actualValue, expectedValueToStartWith, customErrorMsg), customErrorMsg)
143
- }
144
-
145
- /**
146
- * Softly asserts that a value does not start with the expected value.
147
- *
148
- * @param {*} actualValue - The actual value.
149
- * @param {*} expectedValueToNotStartWith - The value that the actual value should not start with.
150
- * @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails.
151
- */
152
- softExpectNotStartsWith(actualValue, expectedValueToNotStartWith, customErrorMsg = '') {
153
- this.softAssert(
154
- () => this.expectNotStartsWith(actualValue, expectedValueToNotStartWith, customErrorMsg),
155
- customErrorMsg,
156
- )
157
- }
158
-
159
- /**
160
- * Softly asserts that a value ends with the expected value.
161
- *
162
- * @param {*} actualValue - The actual value.
163
- * @param {*} expectedValueToEndWith - The value that the actual value should end with.
164
- * @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails.
165
- */
166
- softExpectEndsWith(actualValue, expectedValueToEndWith, customErrorMsg = '') {
167
- this.softAssert(() => this.expectEndsWith(actualValue, expectedValueToEndWith, customErrorMsg), customErrorMsg)
168
- }
169
-
170
- /**
171
- * Softly asserts that a value does not end with the expected value.
172
- *
173
- * @param {*} actualValue - The actual value.
174
- * @param {*} expectedValueToNotEndWith - The value that the actual value should not end with.
175
- * @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails.
176
- */
177
- softExpectNotEndsWith(actualValue, expectedValueToNotEndWith, customErrorMsg = '') {
178
- this.softAssert(
179
- () => this.expectNotEndsWith(actualValue, expectedValueToNotEndWith, customErrorMsg),
180
- customErrorMsg,
181
- )
182
- }
183
-
184
- /**
185
- * Softly asserts that the target data matches the given JSON schema.
186
- *
187
- * @param {*} targetData - The data to validate.
188
- * @param {Object} jsonSchema - The JSON schema to validate against.
189
- * @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails.
190
- */
191
- softExpectJsonSchema(targetData, jsonSchema, customErrorMsg = '') {
192
- this.softAssert(() => this.expectJsonSchema(targetData, jsonSchema, customErrorMsg), customErrorMsg)
193
- }
194
-
195
- /**
196
- * Softly asserts that the target data matches the given JSON schema using AJV.
197
- *
198
- * @param {*} targetData - The data to validate.
199
- * @param {Object} jsonSchema - The JSON schema to validate against.
200
- * @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails.
201
- * @param {Object} [ajvOptions={ allErrors: true }] - Options to pass to AJV.
202
- */
203
- softExpectJsonSchemaUsingAJV(targetData, jsonSchema, customErrorMsg = '', ajvOptions = { allErrors: true }) {
204
- this.softAssert(
205
- () => this.expectJsonSchemaUsingAJV(targetData, jsonSchema, customErrorMsg, ajvOptions),
206
- customErrorMsg,
207
- )
208
- }
209
-
210
- /**
211
- * Softly asserts that the target data has the specified property.
212
- *
213
- * @param {*} targetData - The data to check.
214
- * @param {string} propertyName - The property name to check for.
215
- * @param {string} [customErrorMsg=''] - A custom error message to display if the assertion
216
- fails. */ softExpectHasProperty(targetData, propertyName, customErrorMsg = '') {
217
- this.softAssert(() => this.expectHasProperty(targetData, propertyName, customErrorMsg), customErrorMsg)
218
- }
219
-
220
- /**
221
- Softly asserts that the target data has a property with the specified name.
222
- @param {*} targetData - The data to check.
223
- @param {string} propertyName - The property name to check for.
224
- @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails.
225
- */
226
- softExpectHasAProperty(targetData, propertyName, customErrorMsg = '') {
227
- this.softAssert(() => this.expectHasAProperty(targetData, propertyName, customErrorMsg), customErrorMsg)
228
- }
229
-
230
- /**
231
- Softly asserts that the target data is of a specific type.
232
- @param {*} targetData - The data to check.
233
- @param {string} type - The expected type (e.g., 'string', 'number').
234
- @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails. */
235
- softExpectToBeA(targetData, type, customErrorMsg = '') {
236
- this.softAssert(() => this.expectToBeA(targetData, type, customErrorMsg), customErrorMsg)
237
- }
238
-
239
- /**
240
- Softly asserts that the target data is of a specific type (alternative for articles).
241
- @param {*} targetData - The data to check.
242
- @param {string} type - The expected type (e.g., 'string', 'number').
243
- @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails. */
244
- softExpectToBeAn(targetData, type, customErrorMsg = '') {
245
- this.softAssert(() => this.expectToBeAn(targetData, type, customErrorMsg), customErrorMsg)
246
- }
247
-
248
- /*
249
- Softly asserts that the target data matches the specified regular expression.
250
- @param {*} targetData - The data to check.
251
- @param {RegExp} regex - The regular expression to match.
252
- @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails. */
253
- softExpectMatchRegex(targetData, regex, customErrorMsg = '') {
254
- this.softAssert(() => this.expectMatchRegex(targetData, regex, customErrorMsg), customErrorMsg)
255
- }
256
-
257
- /**
258
- Softly asserts that the target data has a specified length.
259
- @param {*} targetData - The data to check.
260
- @param {number} length - The expected length.
261
- @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails. */
262
- softExpectLengthOf(targetData, length, customErrorMsg = '') {
263
- this.softAssert(() => this.expectLengthOf(targetData, length, customErrorMsg), customErrorMsg)
264
- }
265
-
266
- /**
267
-
268
- Softly asserts that the target data is empty.
269
- @param {*} targetData - The data to check.
270
- @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails. */
271
- softExpectEmpty(targetData, customErrorMsg = '') {
272
- this.softAssert(() => this.expectEmpty(targetData, customErrorMsg), customErrorMsg)
273
- }
274
-
275
- /**
276
-
277
- Softly asserts that the target data is true.
278
- @param {*} targetData - The data to check.
279
- @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails. */
280
- softExpectTrue(targetData, customErrorMsg = '') {
281
- this.softAssert(() => this.expectTrue(targetData, customErrorMsg), customErrorMsg)
282
- }
283
-
284
- /**
285
-
286
- Softly asserts that the target data is false.
287
- @param {*} targetData - The data to check.
288
- @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails. */
289
- softExpectFalse(targetData, customErrorMsg = '') {
290
- this.softAssert(() => this.expectFalse(targetData, customErrorMsg), customErrorMsg)
291
- }
292
-
293
- /**
294
-
295
- Softly asserts that the target data is above a specified value.
296
- @param {*} targetData - The data to check.
297
- @param {*} aboveThan - The value that the target data should be above.
298
- @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails. */
299
- softExpectAbove(targetData, aboveThan, customErrorMsg = '') {
300
- this.softAssert(() => this.expectAbove(targetData, aboveThan, customErrorMsg), customErrorMsg)
301
- }
302
-
303
- /**
304
-
305
- Softly asserts that the target data is below a specified value.
306
- @param {*} targetData - The data to check.
307
- @param {*} belowThan - The value that the target data should be below.
308
- @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails. */
309
- softExpectBelow(targetData, belowThan, customErrorMsg = '') {
310
- this.softAssert(() => this.expectBelow(targetData, belowThan, customErrorMsg), customErrorMsg)
311
- }
312
-
313
- /**
314
-
315
- Softly asserts that the length of the target data is above a specified value.
316
- @param {*} targetData - The data to check.
317
- @param {number} lengthAboveThan - The length that the target data should be above.
318
- @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails. */
319
- softExpectLengthAboveThan(targetData, lengthAboveThan, customErrorMsg = '') {
320
- this.softAssert(() => this.expectLengthAboveThan(targetData, lengthAboveThan, customErrorMsg), customErrorMsg)
321
- }
322
-
323
- /**
324
- Softly asserts that the length of the target data is below a specified value.
325
- @param {*} targetData - The data to check.
326
- @param {number} lengthBelowThan - The length that the target data should be below.
327
- @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails. */
328
- softExpectLengthBelowThan(targetData, lengthBelowThan, customErrorMsg = '') {
329
- this.softAssert(() => this.expectLengthBelowThan(targetData, lengthBelowThan, customErrorMsg), customErrorMsg)
330
- }
331
-
332
- /**
333
- Softly asserts that two values are equal, ignoring case.
334
- @param {string} actualValue - The actual string value.
335
- @param {string} expectedValue - The expected string value.
336
- @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails. */
337
- softExpectEqualIgnoreCase(actualValue, expectedValue, customErrorMsg = '') {
338
- this.softAssert(() => this.expectEqualIgnoreCase(actualValue, expectedValue, customErrorMsg), customErrorMsg)
339
- }
340
-
341
- /**
342
- Softly asserts that two arrays have deep equality, considering members in any order.
343
- @param {Array} actualValue - The actual array.
344
- @param {Array} expectedValue - The expected array.
345
- @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails. */
346
- softExpectDeepMembers(actualValue, expectedValue, customErrorMsg = '') {
347
- this.softAssert(() => this.expectDeepMembers(actualValue, expectedValue, customErrorMsg), customErrorMsg)
348
- }
349
-
350
- /**
351
- Softly asserts that an array (superset) deeply includes all members of another array (set).
352
- @param {Array} superset - The array that should contain the expected members.
353
- @param {Array} set - The array with members that should be included.
354
- @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails. */
355
- softExpectDeepIncludeMembers(superset, set, customErrorMsg = '') {
356
- this.softAssert(() => this.expectDeepIncludeMembers(superset, set, customErrorMsg), customErrorMsg)
357
- }
358
-
359
- /**
360
- Softly asserts that two objects are deeply equal, excluding specified fields.
361
- @param {Object} actualValue - The actual object.
362
- @param {Object} expectedValue - The expected object.
363
- @param {Array<string>} fieldsToExclude - The fields to exclude from the comparison.
364
- @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails. */
365
- softExpectDeepEqualExcluding(actualValue, expectedValue, fieldsToExclude, customErrorMsg = '') {
366
- this.softAssert(
367
- () => this.expectDeepEqualExcluding(actualValue, expectedValue, fieldsToExclude, customErrorMsg),
368
- customErrorMsg,
369
- )
370
- }
371
-
372
- /**
373
- Softly asserts that a value matches the expected pattern.
374
- @param {*} actualValue - The actual value.
375
- @param {*} expectedPattern - The pattern the value should match.
376
- @param {string} [customErrorMsg=''] - A custom error message to display if the assertion fails. */
377
- softExpectMatchesPattern(actualValue, expectedPattern, customErrorMsg = '') {
378
- this.softAssert(() => this.expectMatchesPattern(actualValue, expectedPattern, customErrorMsg), customErrorMsg)
379
- }
380
- }
381
- module.exports = SoftAssertHelper
@@ -1,19 +0,0 @@
1
- const event = require('../event')
2
- const recorder = require('../recorder')
3
-
4
- /**
5
- * Create and clean up empty artifacts
6
- */
7
- module.exports = function () {
8
- event.dispatcher.on(event.test.before, (test) => {
9
- test.artifacts = {}
10
- })
11
-
12
- event.dispatcher.on(event.test.after, (test) => {
13
- recorder.add('clean up empty artifacts', () => {
14
- for (const key in test.artifacts || {}) {
15
- if (!test.artifacts[key]) delete test.artifacts[key]
16
- }
17
- })
18
- })
19
- }