@koenvanbelle/cypress-soft-assertions 2.0.1 → 2.1.0

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 (2) hide show
  1. package/dist/index.js +53 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -64,6 +64,29 @@ function toTokenPart(value) {
64
64
  return String(value);
65
65
  }
66
66
  }
67
+ function getRetryableCommandId() {
68
+ var _a, _b, _c, _d, _e, _f, _g;
69
+ try {
70
+ const current = cy.state('current');
71
+ if (!current)
72
+ return '';
73
+ // In Cypress 15, inside a .should()/.and() callback, cy.state('current')
74
+ // points to the parent command (e.g. 'wrap', 'window', 'get'). The
75
+ // 'followedByShouldCallback' attribute is set to true, and
76
+ // 'currentAssertionCommand' points to the should/and command object.
77
+ const assertionCmd = (_a = current.get) === null || _a === void 0 ? void 0 : _a.call(current, 'currentAssertionCommand');
78
+ if (assertionCmd) {
79
+ const id = (_d = (_c = (_b = assertionCmd.get) === null || _b === void 0 ? void 0 : _b.call(assertionCmd, 'id')) !== null && _c !== void 0 ? _c : assertionCmd.id) !== null && _d !== void 0 ? _d : '';
80
+ return id ? String(id) : '';
81
+ }
82
+ if ((_e = current.get) === null || _e === void 0 ? void 0 : _e.call(current, 'followedByShouldCallback')) {
83
+ const id = (_g = (_f = current.get) === null || _f === void 0 ? void 0 : _f.call(current, 'id')) !== null && _g !== void 0 ? _g : '';
84
+ return id ? String(id) : '';
85
+ }
86
+ }
87
+ catch ( /* ignore */_h) { /* ignore */ }
88
+ return '';
89
+ }
67
90
  function getAssertionToken(assertionContext, args) {
68
91
  const subjectKey = getSubjectKey(assertionContext);
69
92
  if (!subjectKey)
@@ -94,6 +117,13 @@ function patchedAssertionAssert(...args) {
94
117
  retryAssertionFailures.delete(token);
95
118
  retryFirstSeen.delete(token);
96
119
  }
120
+ // Also clear command-based fallback tokens for this command
121
+ const retryableCid = getRetryableCommandId();
122
+ if (retryableCid) {
123
+ const fallbackToken = `__cmd__|${retryableCid}|${toTokenPart(args === null || args === void 0 ? void 0 : args[3])}`;
124
+ retryAssertionFailures.delete(fallbackToken);
125
+ retryFirstSeen.delete(fallbackToken);
126
+ }
97
127
  }
98
128
  return result;
99
129
  }
@@ -127,8 +157,29 @@ function patchedAssertionAssert(...args) {
127
157
  // Map and will be promoted to softAssertionErrors at finalization.
128
158
  return;
129
159
  }
130
- // No identifiable subject capture directly (e.g. bare expect() calls
131
- // in .then() callbacks).
160
+ // No identifiable subject from the DOM. If we're inside a retryable
161
+ // command (.should() / .and()), derive a token from the command ID so the
162
+ // retry-window logic still applies (e.g. window property assertions).
163
+ const retryableCid = getRetryableCommandId();
164
+ if (retryableCid) {
165
+ const fallbackToken = `__cmd__|${retryableCid}|${toTokenPart(args === null || args === void 0 ? void 0 : args[3])}`;
166
+ retryAssertionFailures.set(fallbackToken, {
167
+ message: String((error === null || error === void 0 ? void 0 : error.message) || error),
168
+ stack: error === null || error === void 0 ? void 0 : error.stack,
169
+ });
170
+ const now = Date.now();
171
+ if (!retryFirstSeen.has(fallbackToken)) {
172
+ retryFirstSeen.set(fallbackToken, now);
173
+ }
174
+ const elapsed = now - retryFirstSeen.get(fallbackToken);
175
+ const timeout = getEffectiveTimeout();
176
+ if (elapsed < timeout * 0.75) {
177
+ throw error;
178
+ }
179
+ // Past retry budget — swallow and let Cypress move on.
180
+ return;
181
+ }
182
+ // Bare expect() in .then() callbacks — capture directly.
132
183
  captureSoftAssertion(error);
133
184
  }
134
185
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koenvanbelle/cypress-soft-assertions",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
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",