@koenvanbelle/cypress-soft-assertions 2.4.2 → 2.4.3
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/dist/index.js +55 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -161,6 +161,12 @@ function setupSoftAssertions() {
|
|
|
161
161
|
// Final aggregated error must propagate to fail the test.
|
|
162
162
|
if (String((error === null || error === void 0 ? void 0 : error.name) || '') === 'SoftAssertionError')
|
|
163
163
|
throw error;
|
|
164
|
+
const runnable = cy.state('runnable');
|
|
165
|
+
const retryStatusInfo = getRetryStatusInfo(runnable);
|
|
166
|
+
if (retryStatusInfo.shouldAttemptsContinue) {
|
|
167
|
+
abortSoftTest();
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
164
170
|
// Check if this is an assertion error that was already handled by
|
|
165
171
|
// patchedAssertionAssert (swallowed after timeout). In that case
|
|
166
172
|
// the fail handler should NOT fire. But for non-assertion command
|
|
@@ -220,6 +226,41 @@ function abortSoftTest() {
|
|
|
220
226
|
retryAssertionFailures.clear();
|
|
221
227
|
retryFirstSeen.clear();
|
|
222
228
|
}
|
|
229
|
+
function getRetryStatusInfo(test) {
|
|
230
|
+
var _a;
|
|
231
|
+
const currentRetry = typeof (test === null || test === void 0 ? void 0 : test.currentRetry) === 'function'
|
|
232
|
+
? test.currentRetry()
|
|
233
|
+
: typeof Cypress.currentRetry === 'number'
|
|
234
|
+
? Cypress.currentRetry
|
|
235
|
+
: 0;
|
|
236
|
+
const maxRetries = typeof (test === null || test === void 0 ? void 0 : test.retries) === 'function'
|
|
237
|
+
? test.retries()
|
|
238
|
+
: typeof (test === null || test === void 0 ? void 0 : test._retries) === 'number'
|
|
239
|
+
? test._retries
|
|
240
|
+
: typeof Cypress.getTestRetries === 'function'
|
|
241
|
+
? (_a = Cypress.getTestRetries()) !== null && _a !== void 0 ? _a : 0
|
|
242
|
+
: 0;
|
|
243
|
+
return {
|
|
244
|
+
attempts: currentRetry + 1,
|
|
245
|
+
shouldAttemptsContinue: currentRetry < maxRetries,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function finalizeSoftTestInQueue(expectsSoftFailure) {
|
|
249
|
+
return cy.then(() => {
|
|
250
|
+
if (!isInSoftTest)
|
|
251
|
+
return;
|
|
252
|
+
const finalError = finalizeSoftTest();
|
|
253
|
+
if (expectsSoftFailure) {
|
|
254
|
+
if (!finalError) {
|
|
255
|
+
throw new Error('Expected SoftAssertionError but soft_it.expectFailure test completed without one.');
|
|
256
|
+
}
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (finalError) {
|
|
260
|
+
throw finalError;
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
223
264
|
function createSoftIt(baseIt, options) {
|
|
224
265
|
return function (title, fn) {
|
|
225
266
|
return baseIt(title, function () {
|
|
@@ -230,7 +271,14 @@ function createSoftIt(baseIt, options) {
|
|
|
230
271
|
retryFirstSeen.clear();
|
|
231
272
|
setupSoftAssertions();
|
|
232
273
|
try {
|
|
233
|
-
|
|
274
|
+
const result = fn.call(this);
|
|
275
|
+
if (result && typeof result.then === 'function' && !Cypress.isCy(result)) {
|
|
276
|
+
return Cypress.Promise.resolve(result).then(() => {
|
|
277
|
+
finalizeSoftTestInQueue(expectSoftFailureCurrentSoftTest);
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
finalizeSoftTestInQueue(expectSoftFailureCurrentSoftTest);
|
|
281
|
+
return result;
|
|
234
282
|
}
|
|
235
283
|
catch (error) {
|
|
236
284
|
abortSoftTest();
|
|
@@ -291,11 +339,15 @@ afterEach(function () {
|
|
|
291
339
|
if (finalError) {
|
|
292
340
|
const test = this.currentTest;
|
|
293
341
|
if (test) {
|
|
342
|
+
const retryStatusInfo = getRetryStatusInfo(test);
|
|
343
|
+
if (retryStatusInfo.shouldAttemptsContinue) {
|
|
344
|
+
throw finalError;
|
|
345
|
+
}
|
|
294
346
|
test.err = finalError;
|
|
295
347
|
test._cypressTestStatusInfo = {
|
|
296
348
|
outerStatus: 'failed',
|
|
297
|
-
shouldAttemptsContinue:
|
|
298
|
-
attempts:
|
|
349
|
+
shouldAttemptsContinue: retryStatusInfo.shouldAttemptsContinue,
|
|
350
|
+
attempts: retryStatusInfo.attempts,
|
|
299
351
|
strategy: 'detect-flake-and-pass-on-threshold',
|
|
300
352
|
};
|
|
301
353
|
const prevAttempts = Array.isArray(test.prevAttempts) ? test.prevAttempts : [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koenvanbelle/cypress-soft-assertions",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.3",
|
|
4
4
|
"description": "A Cypress plugin that provides soft_it() for soft assertions - all assertions continue on failure and are reported together",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|