bupkis 0.7.2 → 0.9.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.
- package/CHANGELOG.md +15 -0
- package/README.md +19 -2
- package/dist/commonjs/assertion/assertion-async.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion-async.js +37 -7
- package/dist/commonjs/assertion/assertion-async.js.map +1 -1
- package/dist/commonjs/assertion/assertion-sync.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion-sync.js +32 -8
- package/dist/commonjs/assertion/assertion-sync.js.map +1 -1
- package/dist/commonjs/assertion/assertion-types.d.ts +37 -31
- package/dist/commonjs/assertion/assertion-types.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion-types.js +0 -32
- package/dist/commonjs/assertion/assertion-types.js.map +1 -1
- package/dist/commonjs/assertion/assertion.d.ts +3 -21
- package/dist/commonjs/assertion/assertion.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion.js +42 -27
- package/dist/commonjs/assertion/assertion.js.map +1 -1
- package/dist/commonjs/assertion/create.d.ts +2 -0
- package/dist/commonjs/assertion/create.d.ts.map +1 -1
- package/dist/commonjs/assertion/create.js +38 -42
- package/dist/commonjs/assertion/create.js.map +1 -1
- package/dist/commonjs/assertion/impl/assertion-util.d.ts +16 -4
- package/dist/commonjs/assertion/impl/assertion-util.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/assertion-util.js +20 -15
- package/dist/commonjs/assertion/impl/assertion-util.js.map +1 -1
- package/dist/commonjs/assertion/impl/async-parametric.d.ts +63 -11
- package/dist/commonjs/assertion/impl/async-parametric.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/async-parametric.js +89 -52
- package/dist/commonjs/assertion/impl/async-parametric.js.map +1 -1
- package/dist/commonjs/assertion/impl/async.d.ts +116 -12
- package/dist/commonjs/assertion/impl/async.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/async.js +1 -1
- package/dist/commonjs/assertion/impl/sync-basic.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync-basic.js +6 -4
- package/dist/commonjs/assertion/impl/sync-basic.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync-collection.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync-collection.js +24 -14
- package/dist/commonjs/assertion/impl/sync-collection.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync-esoteric.d.ts +1 -5
- package/dist/commonjs/assertion/impl/sync-esoteric.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync-esoteric.js +11 -13
- package/dist/commonjs/assertion/impl/sync-esoteric.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync-parametric.d.ts +27 -7
- package/dist/commonjs/assertion/impl/sync-parametric.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync-parametric.js +75 -51
- package/dist/commonjs/assertion/impl/sync-parametric.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync.d.ts +54 -22
- package/dist/commonjs/assertion/impl/sync.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync.js +1 -1
- package/dist/commonjs/assertion/impl/sync.js.map +1 -1
- package/dist/commonjs/assertion/index.d.ts +1 -1
- package/dist/commonjs/assertion/index.d.ts.map +1 -1
- package/dist/commonjs/assertion/index.js +0 -1
- package/dist/commonjs/assertion/index.js.map +1 -1
- package/dist/commonjs/assertion/slotify.d.ts +1 -13
- package/dist/commonjs/assertion/slotify.d.ts.map +1 -1
- package/dist/commonjs/assertion/slotify.js +49 -16
- package/dist/commonjs/assertion/slotify.js.map +1 -1
- package/dist/commonjs/bootstrap.d.ts +85 -17
- package/dist/commonjs/bootstrap.d.ts.map +1 -1
- package/dist/commonjs/bootstrap.js +1 -0
- package/dist/commonjs/bootstrap.js.map +1 -1
- package/dist/commonjs/diff.d.ts +51 -0
- package/dist/commonjs/diff.d.ts.map +1 -0
- package/dist/commonjs/diff.js +279 -0
- package/dist/commonjs/diff.js.map +1 -0
- package/dist/commonjs/error.d.ts +37 -18
- package/dist/commonjs/error.d.ts.map +1 -1
- package/dist/commonjs/error.js +44 -30
- package/dist/commonjs/error.js.map +1 -1
- package/dist/commonjs/expect.d.ts.map +1 -1
- package/dist/commonjs/expect.js +131 -78
- package/dist/commonjs/expect.js.map +1 -1
- package/dist/commonjs/guards.d.ts +24 -10
- package/dist/commonjs/guards.d.ts.map +1 -1
- package/dist/commonjs/guards.js +56 -39
- package/dist/commonjs/guards.js.map +1 -1
- package/dist/commonjs/index.d.ts +85 -17
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/internal-schema.d.ts +25 -0
- package/dist/commonjs/internal-schema.d.ts.map +1 -0
- package/dist/commonjs/internal-schema.js +209 -0
- package/dist/commonjs/internal-schema.js.map +1 -0
- package/dist/commonjs/schema.d.ts.map +1 -1
- package/dist/commonjs/schema.js +3 -2
- package/dist/commonjs/schema.js.map +1 -1
- package/dist/commonjs/use.js +22 -8
- package/dist/commonjs/use.js.map +1 -1
- package/dist/commonjs/util.d.ts +1 -0
- package/dist/commonjs/util.d.ts.map +1 -1
- package/dist/commonjs/util.js +14 -10
- package/dist/commonjs/util.js.map +1 -1
- package/dist/commonjs/value-to-schema.d.ts +1 -0
- package/dist/commonjs/value-to-schema.d.ts.map +1 -1
- package/dist/commonjs/value-to-schema.js +19 -12
- package/dist/commonjs/value-to-schema.js.map +1 -1
- package/dist/esm/assertion/assertion-async.d.ts.map +1 -1
- package/dist/esm/assertion/assertion-async.js +37 -7
- package/dist/esm/assertion/assertion-async.js.map +1 -1
- package/dist/esm/assertion/assertion-sync.d.ts.map +1 -1
- package/dist/esm/assertion/assertion-sync.js +32 -8
- package/dist/esm/assertion/assertion-sync.js.map +1 -1
- package/dist/esm/assertion/assertion-types.d.ts +37 -31
- package/dist/esm/assertion/assertion-types.d.ts.map +1 -1
- package/dist/esm/assertion/assertion-types.js +1 -31
- package/dist/esm/assertion/assertion-types.js.map +1 -1
- package/dist/esm/assertion/assertion.d.ts +3 -21
- package/dist/esm/assertion/assertion.d.ts.map +1 -1
- package/dist/esm/assertion/assertion.js +42 -27
- package/dist/esm/assertion/assertion.js.map +1 -1
- package/dist/esm/assertion/create.d.ts +2 -0
- package/dist/esm/assertion/create.d.ts.map +1 -1
- package/dist/esm/assertion/create.js +37 -41
- package/dist/esm/assertion/create.js.map +1 -1
- package/dist/esm/assertion/impl/assertion-util.d.ts +16 -4
- package/dist/esm/assertion/impl/assertion-util.d.ts.map +1 -1
- package/dist/esm/assertion/impl/assertion-util.js +20 -15
- package/dist/esm/assertion/impl/assertion-util.js.map +1 -1
- package/dist/esm/assertion/impl/async-parametric.d.ts +63 -11
- package/dist/esm/assertion/impl/async-parametric.d.ts.map +1 -1
- package/dist/esm/assertion/impl/async-parametric.js +89 -52
- package/dist/esm/assertion/impl/async-parametric.js.map +1 -1
- package/dist/esm/assertion/impl/async.d.ts +116 -12
- package/dist/esm/assertion/impl/async.d.ts.map +1 -1
- package/dist/esm/assertion/impl/async.js +2 -2
- package/dist/esm/assertion/impl/async.js.map +1 -1
- package/dist/esm/assertion/impl/sync-basic.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync-basic.js +6 -4
- package/dist/esm/assertion/impl/sync-basic.js.map +1 -1
- package/dist/esm/assertion/impl/sync-collection.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync-collection.js +24 -14
- package/dist/esm/assertion/impl/sync-collection.js.map +1 -1
- package/dist/esm/assertion/impl/sync-esoteric.d.ts +1 -5
- package/dist/esm/assertion/impl/sync-esoteric.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync-esoteric.js +11 -13
- package/dist/esm/assertion/impl/sync-esoteric.js.map +1 -1
- package/dist/esm/assertion/impl/sync-parametric.d.ts +27 -7
- package/dist/esm/assertion/impl/sync-parametric.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync-parametric.js +75 -51
- package/dist/esm/assertion/impl/sync-parametric.js.map +1 -1
- package/dist/esm/assertion/impl/sync.d.ts +54 -22
- package/dist/esm/assertion/impl/sync.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync.js +2 -2
- package/dist/esm/assertion/impl/sync.js.map +1 -1
- package/dist/esm/assertion/index.d.ts +1 -1
- package/dist/esm/assertion/index.d.ts.map +1 -1
- package/dist/esm/assertion/index.js +0 -1
- package/dist/esm/assertion/index.js.map +1 -1
- package/dist/esm/assertion/slotify.d.ts +1 -13
- package/dist/esm/assertion/slotify.d.ts.map +1 -1
- package/dist/esm/assertion/slotify.js +50 -17
- package/dist/esm/assertion/slotify.js.map +1 -1
- package/dist/esm/bootstrap.d.ts +85 -17
- package/dist/esm/bootstrap.d.ts.map +1 -1
- package/dist/esm/bootstrap.js +1 -0
- package/dist/esm/bootstrap.js.map +1 -1
- package/dist/esm/diff.d.ts +51 -0
- package/dist/esm/diff.d.ts.map +1 -0
- package/dist/esm/diff.js +273 -0
- package/dist/esm/diff.js.map +1 -0
- package/dist/esm/error.d.ts +37 -18
- package/dist/esm/error.d.ts.map +1 -1
- package/dist/esm/error.js +41 -27
- package/dist/esm/error.js.map +1 -1
- package/dist/esm/expect.d.ts.map +1 -1
- package/dist/esm/expect.js +133 -80
- package/dist/esm/expect.js.map +1 -1
- package/dist/esm/guards.d.ts +24 -10
- package/dist/esm/guards.d.ts.map +1 -1
- package/dist/esm/guards.js +52 -36
- package/dist/esm/guards.js.map +1 -1
- package/dist/esm/index.d.ts +85 -17
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/internal-schema.d.ts +25 -0
- package/dist/esm/internal-schema.d.ts.map +1 -0
- package/dist/esm/internal-schema.js +203 -0
- package/dist/esm/internal-schema.js.map +1 -0
- package/dist/esm/schema.d.ts.map +1 -1
- package/dist/esm/schema.js +3 -2
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/use.js +19 -6
- package/dist/esm/use.js.map +1 -1
- package/dist/esm/util.d.ts +1 -0
- package/dist/esm/util.d.ts.map +1 -1
- package/dist/esm/util.js +14 -10
- package/dist/esm/util.js.map +1 -1
- package/dist/esm/value-to-schema.d.ts +1 -0
- package/dist/esm/value-to-schema.d.ts.map +1 -1
- package/dist/esm/value-to-schema.js +20 -13
- package/dist/esm/value-to-schema.js.map +1 -1
- package/package.json +29 -11
- package/src/assertion/assertion-async.ts +42 -14
- package/src/assertion/assertion-sync.ts +40 -17
- package/src/assertion/assertion-types.ts +55 -45
- package/src/assertion/assertion.ts +49 -32
- package/src/assertion/create.ts +46 -65
- package/src/assertion/impl/assertion-util.ts +31 -18
- package/src/assertion/impl/async-parametric.ts +93 -52
- package/src/assertion/impl/async.ts +2 -2
- package/src/assertion/impl/sync-basic.ts +7 -4
- package/src/assertion/impl/sync-collection.ts +34 -14
- package/src/assertion/impl/sync-esoteric.ts +17 -13
- package/src/assertion/impl/sync-parametric.ts +79 -52
- package/src/assertion/impl/sync.ts +2 -2
- package/src/assertion/index.ts +1 -1
- package/src/assertion/slotify.ts +67 -21
- package/src/bootstrap.ts +1 -0
- package/src/diff.ts +343 -0
- package/src/error.ts +66 -31
- package/src/expect.ts +195 -129
- package/src/guards.ts +74 -48
- package/src/internal-schema.ts +246 -0
- package/src/schema.ts +4 -2
- package/src/use.ts +21 -7
- package/src/util.ts +15 -12
- package/src/value-to-schema.ts +21 -13
package/dist/commonjs/expect.js
CHANGED
|
@@ -77,27 +77,33 @@ const debug = (0, debug_1.default)('bupkis:expect');
|
|
|
77
77
|
*/
|
|
78
78
|
function createExpectAsyncFunction(assertions, expect) {
|
|
79
79
|
debug('ℹ Creating expectAsync function with %d new assertions and %d existing assertions (%d total)', assertions.length, expect?.assertions.length ?? 0, assertions.length + (expect?.assertions.length ?? 0));
|
|
80
|
+
/**
|
|
81
|
+
* @function
|
|
82
|
+
*/
|
|
80
83
|
const expectAsyncFunction = async (...args) => {
|
|
81
84
|
await Promise.resolve();
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
const argsMatrix = conjunctify(args);
|
|
86
|
+
for (const args of argsMatrix) {
|
|
87
|
+
const { isNegated, processedArgs } = maybeProcessNegation(args);
|
|
88
|
+
const candidates = [];
|
|
89
|
+
for (const assertion of [...(expect?.assertions ?? []), ...assertions]) {
|
|
90
|
+
const parseResult = await assertion.parseValuesAsync(processedArgs);
|
|
91
|
+
const { exactMatch, parsedValues, success } = parseResult;
|
|
92
|
+
if (success) {
|
|
93
|
+
if (exactMatch) {
|
|
94
|
+
return executeAsync(assertion, parsedValues, [...args], expectAsyncFunction, isNegated, parseResult);
|
|
95
|
+
}
|
|
96
|
+
candidates.push({ assertion, parseResult });
|
|
90
97
|
}
|
|
91
|
-
candidates.push({ assertion, parseResult });
|
|
92
98
|
}
|
|
99
|
+
if (candidates.length) {
|
|
100
|
+
const { assertion, parseResult } = candidates[0];
|
|
101
|
+
return executeAsync(assertion,
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
103
|
+
parseResult.parsedValues, [...args], expectAsyncFunction, isNegated, parseResult);
|
|
104
|
+
}
|
|
105
|
+
throwInvalidParametersError(args);
|
|
93
106
|
}
|
|
94
|
-
if (candidates.length) {
|
|
95
|
-
const { assertion, parseResult } = candidates[0];
|
|
96
|
-
return executeAsync(assertion,
|
|
97
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
98
|
-
parseResult.parsedValues, [...args], expectAsyncFunction, isNegated, parseResult);
|
|
99
|
-
}
|
|
100
|
-
throwInvalidParametersError(args);
|
|
101
107
|
};
|
|
102
108
|
return expectAsyncFunction;
|
|
103
109
|
}
|
|
@@ -156,26 +162,32 @@ function createExpectAsyncFunction(assertions, expect) {
|
|
|
156
162
|
*/
|
|
157
163
|
function createExpectSyncFunction(assertions, expect) {
|
|
158
164
|
debug('ℹ Creating expect function with %d new assertions and %d existing assertions (%d total)', assertions.length, expect?.assertions.length ?? 0, assertions.length + (expect?.assertions.length ?? 0));
|
|
165
|
+
/**
|
|
166
|
+
* @function
|
|
167
|
+
*/
|
|
159
168
|
const expectFunction = (...args) => {
|
|
160
|
-
const
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
169
|
+
const argsMatrix = conjunctify(args);
|
|
170
|
+
for (const args of argsMatrix) {
|
|
171
|
+
const { isNegated, processedArgs } = maybeProcessNegation(args);
|
|
172
|
+
const candidates = [];
|
|
173
|
+
for (const assertion of [...(expect?.assertions ?? []), ...assertions]) {
|
|
174
|
+
const parseResult = assertion.parseValues(processedArgs);
|
|
175
|
+
const { exactMatch, parsedValues, success } = parseResult;
|
|
176
|
+
if (success) {
|
|
177
|
+
if (exactMatch) {
|
|
178
|
+
return execute(assertion, parsedValues, [...args], expectFunction, isNegated, parseResult);
|
|
179
|
+
}
|
|
180
|
+
candidates.push({ assertion, parseResult });
|
|
168
181
|
}
|
|
169
|
-
candidates.push({ assertion, parseResult });
|
|
170
182
|
}
|
|
183
|
+
if (candidates.length) {
|
|
184
|
+
const { assertion, parseResult } = candidates[0];
|
|
185
|
+
return execute(assertion,
|
|
186
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
187
|
+
parseResult.parsedValues, [...args], expectFunction, isNegated, parseResult);
|
|
188
|
+
}
|
|
189
|
+
throwInvalidParametersError(args);
|
|
171
190
|
}
|
|
172
|
-
if (candidates.length) {
|
|
173
|
-
const { assertion, parseResult } = candidates[0];
|
|
174
|
-
return execute(assertion,
|
|
175
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
176
|
-
parseResult.parsedValues, [...args], expectFunction, isNegated, parseResult);
|
|
177
|
-
}
|
|
178
|
-
throwInvalidParametersError(args);
|
|
179
191
|
};
|
|
180
192
|
return expectFunction;
|
|
181
193
|
}
|
|
@@ -185,6 +197,7 @@ function createExpectSyncFunction(assertions, expect) {
|
|
|
185
197
|
* @privateRemarks
|
|
186
198
|
* This is here because `Assertion` doesn't know anything about negation and
|
|
187
199
|
* probably shouldn't.
|
|
200
|
+
* @function
|
|
188
201
|
* @param assertion - The assertion to execute
|
|
189
202
|
* @param parsedValues - Parsed values for the assertion
|
|
190
203
|
* @param args - Original arguments passed to expect
|
|
@@ -192,39 +205,37 @@ function createExpectSyncFunction(assertions, expect) {
|
|
|
192
205
|
* @param isNegated - Whether the assertion should be negated
|
|
193
206
|
*/
|
|
194
207
|
const execute = (assertion, parsedValues, args, stackStartFn, isNegated, parseResult) => {
|
|
195
|
-
if (
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
+
if (isNegated) {
|
|
209
|
+
// negation logic
|
|
210
|
+
try {
|
|
211
|
+
assertion.execute(parsedValues, args, stackStartFn, parseResult);
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
// success!
|
|
215
|
+
if (error_js_1.AssertionError.isAssertionError(error)) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (error_js_1.AssertionImplementationError.isAssertionImplementationError(error)) {
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
throw new error_js_1.AssertionImplementationError(`Assertion ${assertion} threw a non-AssertionError`, { cause: error });
|
|
208
222
|
}
|
|
209
|
-
//
|
|
223
|
+
// if we reach here, then the assertion passed when it should have failed, so:
|
|
210
224
|
throw new error_js_1.NegatedAssertionError({
|
|
211
|
-
message: `Expected assertion to fail (due to negation), but it passed
|
|
225
|
+
message: `Expected assertion ${assertion} to fail (due to negation), but it passed`,
|
|
212
226
|
stackStartFn,
|
|
213
227
|
});
|
|
214
228
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
// This is our negation error, re-throw it
|
|
219
|
-
throw error;
|
|
229
|
+
else {
|
|
230
|
+
try {
|
|
231
|
+
assertion.execute(parsedValues, args, stackStartFn, parseResult);
|
|
220
232
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
233
|
+
catch (error) {
|
|
234
|
+
if (error_js_1.AssertionError.isAssertionError(error)) {
|
|
235
|
+
throw error;
|
|
236
|
+
}
|
|
237
|
+
throw new error_js_1.AssertionImplementationError(`Assertion ${assertion} threw a non-AssertionError`, { cause: error });
|
|
224
238
|
}
|
|
225
|
-
debug('Non-assertion error thrown during negated assertion: %O', error);
|
|
226
|
-
// Re-throw non-assertion errors (like TypeErrors, etc.)
|
|
227
|
-
throw error;
|
|
228
239
|
}
|
|
229
240
|
};
|
|
230
241
|
/**
|
|
@@ -233,6 +244,7 @@ const execute = (assertion, parsedValues, args, stackStartFn, isNegated, parseRe
|
|
|
233
244
|
* @privateRemarks
|
|
234
245
|
* This is here because `Assertion` doesn't know anything about negation and
|
|
235
246
|
* probably shouldn't.
|
|
247
|
+
* @function
|
|
236
248
|
* @param assertion - The assertion to execute
|
|
237
249
|
* @param parsedValues - Parsed values for the assertion
|
|
238
250
|
* @param args - Original arguments passed to expectAsync
|
|
@@ -240,30 +252,34 @@ const execute = (assertion, parsedValues, args, stackStartFn, isNegated, parseRe
|
|
|
240
252
|
* @param isNegated - Whether the assertion should be negated
|
|
241
253
|
*/
|
|
242
254
|
const executeAsync = async (assertion, parsedValues, args, stackStartFn, isNegated, parseResult) => {
|
|
243
|
-
if (
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
255
|
+
if (isNegated) {
|
|
256
|
+
// negation logic
|
|
257
|
+
try {
|
|
258
|
+
await assertion.executeAsync(parsedValues, args, stackStartFn, parseResult);
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
// success!
|
|
262
|
+
if (error_js_1.AssertionError.isAssertionError(error)) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
throw new error_js_1.AssertionImplementationError(`Assertion ${assertion} threw a non-AssertionError`, { cause: error });
|
|
266
|
+
}
|
|
267
|
+
// if we reach here, then the assertion passed when it should have failed, so:
|
|
249
268
|
throw new error_js_1.NegatedAssertionError({
|
|
250
|
-
message: `Expected assertion to fail (due to negation), but it passed
|
|
269
|
+
message: `Expected assertion ${assertion} to fail (due to negation), but it passed`,
|
|
251
270
|
stackStartFn,
|
|
252
271
|
});
|
|
253
272
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
// This is our negation error, re-throw it
|
|
258
|
-
throw error;
|
|
273
|
+
else {
|
|
274
|
+
try {
|
|
275
|
+
await assertion.executeAsync(parsedValues, args, stackStartFn, parseResult);
|
|
259
276
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
277
|
+
catch (error) {
|
|
278
|
+
if (error_js_1.AssertionError.isAssertionError(error)) {
|
|
279
|
+
throw error;
|
|
280
|
+
}
|
|
281
|
+
throw new error_js_1.AssertionImplementationError(`Assertion ${assertion} threw a non-AssertionError`, { cause: error });
|
|
263
282
|
}
|
|
264
|
-
debug('Non-assertion error thrown during negated async assertion: %O', error);
|
|
265
|
-
// Re-throw non-assertion errors (like TypeErrors, etc.)
|
|
266
|
-
throw error;
|
|
267
283
|
}
|
|
268
284
|
};
|
|
269
285
|
/**
|
|
@@ -271,11 +287,13 @@ const executeAsync = async (assertion, parsedValues, args, stackStartFn, isNegat
|
|
|
271
287
|
* requested along with arguments stripped of the leading negation (to enable
|
|
272
288
|
* assertion matching).
|
|
273
289
|
*
|
|
290
|
+
* @function
|
|
274
291
|
* @internal
|
|
275
292
|
*/
|
|
276
293
|
const maybeProcessNegation = (args) => {
|
|
277
294
|
let isNegated = false;
|
|
278
295
|
let processedArgs = args;
|
|
296
|
+
// note: args[1] should always be a string
|
|
279
297
|
if (args.length >= 2 && (0, guards_js_1.isString)(args[1])) {
|
|
280
298
|
const { cleanedPhrase, isNegated: detected } = detectNegation(args[1]);
|
|
281
299
|
if (detected) {
|
|
@@ -283,12 +301,44 @@ const maybeProcessNegation = (args) => {
|
|
|
283
301
|
processedArgs = [args[0], cleanedPhrase, ...args.slice(2)];
|
|
284
302
|
}
|
|
285
303
|
}
|
|
286
|
-
return
|
|
304
|
+
return { isNegated, processedArgs };
|
|
305
|
+
};
|
|
306
|
+
/**
|
|
307
|
+
* Given some args, create a matrix of args based on the presence of the
|
|
308
|
+
* conjunction operator ("and").
|
|
309
|
+
*
|
|
310
|
+
* If no "and" is present, returns the original args wrapped in an array.
|
|
311
|
+
*
|
|
312
|
+
* @function
|
|
313
|
+
*/
|
|
314
|
+
const conjunctify = (args) => {
|
|
315
|
+
let argsMatrix = [args];
|
|
316
|
+
if (args.length >= 2) {
|
|
317
|
+
// partition args by the string "and"; there may be multiple "and"s
|
|
318
|
+
const andIndices = args
|
|
319
|
+
.map((arg, index) => (arg === 'and' ? index : -1))
|
|
320
|
+
.filter((index) => index !== -1);
|
|
321
|
+
if (andIndices.length > 0) {
|
|
322
|
+
const parts = [];
|
|
323
|
+
let lastIndex = 0;
|
|
324
|
+
for (const andIndex of andIndices) {
|
|
325
|
+
const partsArgs = lastIndex > 0
|
|
326
|
+
? [args[0], ...args.slice(lastIndex, andIndex)]
|
|
327
|
+
: [...args.slice(lastIndex, andIndex)];
|
|
328
|
+
parts.push(partsArgs);
|
|
329
|
+
lastIndex = andIndex + 1;
|
|
330
|
+
}
|
|
331
|
+
parts.push([args[0], ...args.slice(lastIndex)]);
|
|
332
|
+
argsMatrix = parts;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return argsMatrix;
|
|
287
336
|
};
|
|
288
337
|
/**
|
|
289
338
|
* Throws an error indicating that no valid assertion could be found for the
|
|
290
339
|
* provided arguments.
|
|
291
340
|
*
|
|
341
|
+
* @function
|
|
292
342
|
* @param args The arguments that were passed to the expect function
|
|
293
343
|
* @internal
|
|
294
344
|
*/
|
|
@@ -301,6 +351,7 @@ const throwInvalidParametersError = (args) => {
|
|
|
301
351
|
* Detects if an assertion phrase starts with "not " and returns the cleaned
|
|
302
352
|
* phrase.
|
|
303
353
|
*
|
|
354
|
+
* @function
|
|
304
355
|
* @param phrase - The assertion phrase to check
|
|
305
356
|
* @returns Object with `isNegated` flag and `cleanedPhrase`
|
|
306
357
|
*/
|
|
@@ -317,7 +368,9 @@ const detectNegation = (phrase) => {
|
|
|
317
368
|
};
|
|
318
369
|
};
|
|
319
370
|
/**
|
|
320
|
-
* {@
|
|
371
|
+
* {@inheritDoc FailFn}
|
|
372
|
+
*
|
|
373
|
+
* @function
|
|
321
374
|
*/
|
|
322
375
|
const fail = (reason) => {
|
|
323
376
|
throw new error_js_1.FailAssertionError({ message: reason });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expect.js","sourceRoot":"","sources":["../../src/expect.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"expect.js","sourceRoot":"","sources":["../../src/expect.ts"],"names":[],"mappings":";;;;;AA8KA,8DAwDC;AAgID,4DAyDC;AA+QD,4CAmBC;AAjsBD,kDAAgC;AAChC,+BAA+B;AAgB/B,qDAA8E;AAC9E,yCAMoB;AACpB,2CAAuC;AAYvC,qCAAqC;AAErC,MAAM,KAAK,GAAG,IAAA,eAAW,EAAC,eAAe,CAAC,CAAC;AAyE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,SAAgB,yBAAyB,CAGvC,UAAa,EAAE,MAAU;IACzB,KAAK,CACH,8FAA8F,EAC9F,UAAU,CAAC,MAAM,EACjB,MAAM,EAAE,UAAU,CAAC,MAAM,IAAI,CAAC,EAC9B,UAAU,CAAC,MAAM,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,MAAM,IAAI,CAAC,CAAC,CACrD,CAAC;IACF;;OAEG;IACH,MAAM,mBAAmB,GAAG,KAAK,EAAE,GAAG,IAAwB,EAAE,EAAE;QAChE,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QACxB,MAAM,UA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EAAE,MAAM;QACrB,SAAS,EAAE,KAAK;KACjB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,IAAI,GAAW,CAAC,MAAe,EAAS,EAAE;IAC9C,MAAM,IAAI,6BAAkB,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;AACpD,CAAC,CAAC;AAgBF;;;GAGG;AACH,SAAgB,gBAAgB,CAG9B,cAAiB,EAAE,eAAkB,EAAE,IAAsB;IAC7D,OAAO,IAAI,KAAK,MAAM;QACpB,CAAC,CAAC;YACE,UAAU,EAAE,cAAc;YAC1B,eAAe,EAAf,2BAAe;YACf,oBAAoB,EAApB,gCAAoB;YACpB,IAAI;YACJ,GAAG,EAAE,IAAA,kBAAS,EAAC,cAAc,EAAE,eAAe,CAAC;SAChD;QACH,CAAC,CAAC;YACE,UAAU,EAAE,eAAe;YAC3B,eAAe,EAAf,2BAAe;YACf,oBAAoB,EAApB,gCAAoB;YACpB,IAAI;YACJ,GAAG,EAAE,IAAA,kBAAS,EAAC,cAAc,EAAE,eAAe,CAAC;SAChD,CAAC;AACR,CAAC"}
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
*
|
|
16
16
|
* @packageDocumentation
|
|
17
17
|
*/
|
|
18
|
-
import { type
|
|
19
|
-
import {
|
|
20
|
-
import type { Constructor, ExpectItExecutor, ZodTypeMap } from './types.js';
|
|
18
|
+
import { type z } from 'zod/v4';
|
|
19
|
+
import type { PhraseLiteralChoice } from './assertion/assertion-types.js';
|
|
20
|
+
import type { Constructor, ExpectItExecutor, PhraseLiteral, ZodTypeMap } from './types.js';
|
|
21
21
|
/**
|
|
22
22
|
* Returns `true` if the given value looks like a Zod v4 schema, determined by
|
|
23
23
|
* the presence of an internal {@link z.core.$ZodTypeDef} field.
|
|
@@ -44,6 +44,7 @@ export declare function isZodType(value: unknown): value is z.ZodType;
|
|
|
44
44
|
/**
|
|
45
45
|
* Type guard for a plain object.
|
|
46
46
|
*
|
|
47
|
+
* @function
|
|
47
48
|
* @param value Value to test
|
|
48
49
|
* @returns `true` if the value is a plain object, `false` otherwise
|
|
49
50
|
*/
|
|
@@ -51,6 +52,7 @@ export declare const isObject: (value: unknown) => value is NonNullable<object>;
|
|
|
51
52
|
/**
|
|
52
53
|
* Returns `true` if the given value is a {@link z.ZodPromise} schema.
|
|
53
54
|
*
|
|
55
|
+
* @function
|
|
54
56
|
* @param value - Value to test
|
|
55
57
|
* @returns `true` if the value is a `ZodPromise` schema; `false` otherwise
|
|
56
58
|
*/
|
|
@@ -58,6 +60,7 @@ export declare const isZodPromise: (value: unknown) => value is z.ZodPromise;
|
|
|
58
60
|
/**
|
|
59
61
|
* Checks if a value is "promise-like", meaning it is a "thenable" object.
|
|
60
62
|
*
|
|
63
|
+
* @function
|
|
61
64
|
* @param value - Value to test
|
|
62
65
|
* @returns `true` if the value is promise-like, `false` otherwise
|
|
63
66
|
*/
|
|
@@ -74,6 +77,7 @@ export declare const isPromiseLike: (value: unknown) => value is PromiseLike<unk
|
|
|
74
77
|
* This may be the only way we can determine, at runtime, if a function is a
|
|
75
78
|
* constructor without actually calling it. I am unsure if this only works for
|
|
76
79
|
* classes.
|
|
80
|
+
* @function
|
|
77
81
|
* @param fn - Function to test
|
|
78
82
|
* @returns Whether the function is constructable
|
|
79
83
|
*/
|
|
@@ -81,6 +85,7 @@ export declare const isConstructible: (fn: unknown) => fn is Constructor;
|
|
|
81
85
|
/**
|
|
82
86
|
* Type guard for a boolean value
|
|
83
87
|
*
|
|
88
|
+
* @function
|
|
84
89
|
* @param value Value to check
|
|
85
90
|
* @returns `true` if the value is a boolean, `false` otherwise
|
|
86
91
|
*/
|
|
@@ -88,6 +93,7 @@ export declare const isBoolean: (value: unknown) => value is boolean;
|
|
|
88
93
|
/**
|
|
89
94
|
* Type guard for a function value
|
|
90
95
|
*
|
|
96
|
+
* @function
|
|
91
97
|
* @param value Value to check
|
|
92
98
|
* @returns `true` if the value is a function, `false` otherwise
|
|
93
99
|
*/
|
|
@@ -95,6 +101,7 @@ export declare const isFunction: (value: unknown) => value is (...args: any[]) =
|
|
|
95
101
|
/**
|
|
96
102
|
* Type guard for a string value
|
|
97
103
|
*
|
|
104
|
+
* @function
|
|
98
105
|
* @param value Value to check
|
|
99
106
|
* @returns `true` if the value is a string, `false` otherwise
|
|
100
107
|
*/
|
|
@@ -102,28 +109,32 @@ export declare const isString: (value: unknown) => value is string;
|
|
|
102
109
|
/**
|
|
103
110
|
* Type guard for a non-null object value
|
|
104
111
|
*
|
|
112
|
+
* @function
|
|
105
113
|
* @param value Value to check
|
|
106
114
|
* @returns `true` if the value is an object and not null, `false` otherwise
|
|
107
115
|
*/
|
|
108
116
|
export declare const isNonNullObject: (value: unknown) => value is object;
|
|
109
|
-
/**
|
|
110
|
-
* Type guard for a null or non-object value
|
|
111
|
-
*
|
|
112
|
-
* @param value Value to check
|
|
113
|
-
* @returns `true` if the value is null or not an object, `false` otherwise
|
|
114
|
-
*/
|
|
115
|
-
export declare const isNullOrNonObject: (value: unknown) => value is null | Primitive;
|
|
116
117
|
/**
|
|
117
118
|
* Type guard for a valid WeakKey (object, function, or symbol).
|
|
118
119
|
*
|
|
119
120
|
* WeakMaps and WeakSets can only use objects (including functions) or symbols
|
|
120
121
|
* as keys, not primitives like strings, numbers, booleans, null, or undefined.
|
|
121
122
|
*
|
|
123
|
+
* @function
|
|
122
124
|
* @param value Value to check
|
|
123
125
|
* @returns `true` if the value is a valid WeakKey (object, function, or
|
|
124
126
|
* symbol), `false` otherwise
|
|
125
127
|
*/
|
|
126
128
|
export declare const isWeakKey: (value: unknown) => value is WeakKey;
|
|
129
|
+
/**
|
|
130
|
+
* Type guard for a {@link PhraseLiteral} or {@link PhraseLiteralChoice}.
|
|
131
|
+
*
|
|
132
|
+
* @function
|
|
133
|
+
* @param value Value to check
|
|
134
|
+
* @returns `true` if the value is a `PhraseLiteral` or `PhraseLiteralChoice`,
|
|
135
|
+
* `false` otherwise
|
|
136
|
+
*/
|
|
137
|
+
export declare const isPhrase: (value: unknown) => value is PhraseLiteral | PhraseLiteralChoice;
|
|
127
138
|
/**
|
|
128
139
|
* Generic type guard for instanceof checks.
|
|
129
140
|
*
|
|
@@ -143,6 +154,7 @@ export declare const isWeakKey: (value: unknown) => value is WeakKey;
|
|
|
143
154
|
* ```
|
|
144
155
|
*
|
|
145
156
|
* @template T - The constructor type to check against
|
|
157
|
+
* @function
|
|
146
158
|
* @param value - Value to test
|
|
147
159
|
* @param ctor - Constructor function to check instanceof
|
|
148
160
|
* @returns `true` if the value is an instance of the constructor, `false`
|
|
@@ -169,6 +181,7 @@ export declare const isA: <T extends Constructor>(value: unknown, ctor: T) => va
|
|
|
169
181
|
* }
|
|
170
182
|
* ```
|
|
171
183
|
*
|
|
184
|
+
* @function
|
|
172
185
|
* @param value - Value to test
|
|
173
186
|
* @returns `true` if the value is an Error instance, `false` otherwise
|
|
174
187
|
*/
|
|
@@ -194,6 +207,7 @@ export declare const isError: (value: unknown) => value is Error;
|
|
|
194
207
|
* ```
|
|
195
208
|
*
|
|
196
209
|
* @template Subject - The subject type that the executor function operates on
|
|
210
|
+
* @function
|
|
197
211
|
* @param value - Value to test
|
|
198
212
|
* @returns `true` if the value is an ExpectItExecutor function, `false`
|
|
199
213
|
* otherwise
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/guards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/guards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EAEV,mBAAmB,EACpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAEV,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,UAAU,E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