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/esm/expect.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import createDebug from 'debug';
|
|
2
2
|
import { inspect } from 'util';
|
|
3
3
|
import { createAssertion, createAsyncAssertion } from './assertion/create.js';
|
|
4
|
-
import { AssertionError, FailAssertionError, NegatedAssertionError, UnknownAssertionError, } from './error.js';
|
|
5
|
-
import {
|
|
4
|
+
import { AssertionError, AssertionImplementationError, FailAssertionError, NegatedAssertionError, UnknownAssertionError, } from './error.js';
|
|
5
|
+
import { isString } from './guards.js';
|
|
6
6
|
import { createUse } from './use.js';
|
|
7
7
|
const debug = createDebug('bupkis:expect');
|
|
8
8
|
/**
|
|
@@ -69,27 +69,33 @@ const debug = createDebug('bupkis:expect');
|
|
|
69
69
|
*/
|
|
70
70
|
export function createExpectAsyncFunction(assertions, expect) {
|
|
71
71
|
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));
|
|
72
|
+
/**
|
|
73
|
+
* @function
|
|
74
|
+
*/
|
|
72
75
|
const expectAsyncFunction = async (...args) => {
|
|
73
76
|
await Promise.resolve();
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
const argsMatrix = conjunctify(args);
|
|
78
|
+
for (const args of argsMatrix) {
|
|
79
|
+
const { isNegated, processedArgs } = maybeProcessNegation(args);
|
|
80
|
+
const candidates = [];
|
|
81
|
+
for (const assertion of [...(expect?.assertions ?? []), ...assertions]) {
|
|
82
|
+
const parseResult = await assertion.parseValuesAsync(processedArgs);
|
|
83
|
+
const { exactMatch, parsedValues, success } = parseResult;
|
|
84
|
+
if (success) {
|
|
85
|
+
if (exactMatch) {
|
|
86
|
+
return executeAsync(assertion, parsedValues, [...args], expectAsyncFunction, isNegated, parseResult);
|
|
87
|
+
}
|
|
88
|
+
candidates.push({ assertion, parseResult });
|
|
82
89
|
}
|
|
83
|
-
candidates.push({ assertion, parseResult });
|
|
84
90
|
}
|
|
91
|
+
if (candidates.length) {
|
|
92
|
+
const { assertion, parseResult } = candidates[0];
|
|
93
|
+
return executeAsync(assertion,
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
95
|
+
parseResult.parsedValues, [...args], expectAsyncFunction, isNegated, parseResult);
|
|
96
|
+
}
|
|
97
|
+
throwInvalidParametersError(args);
|
|
85
98
|
}
|
|
86
|
-
if (candidates.length) {
|
|
87
|
-
const { assertion, parseResult } = candidates[0];
|
|
88
|
-
return executeAsync(assertion,
|
|
89
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
90
|
-
parseResult.parsedValues, [...args], expectAsyncFunction, isNegated, parseResult);
|
|
91
|
-
}
|
|
92
|
-
throwInvalidParametersError(args);
|
|
93
99
|
};
|
|
94
100
|
return expectAsyncFunction;
|
|
95
101
|
}
|
|
@@ -148,26 +154,32 @@ export function createExpectAsyncFunction(assertions, expect) {
|
|
|
148
154
|
*/
|
|
149
155
|
export function createExpectSyncFunction(assertions, expect) {
|
|
150
156
|
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));
|
|
157
|
+
/**
|
|
158
|
+
* @function
|
|
159
|
+
*/
|
|
151
160
|
const expectFunction = (...args) => {
|
|
152
|
-
const
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
161
|
+
const argsMatrix = conjunctify(args);
|
|
162
|
+
for (const args of argsMatrix) {
|
|
163
|
+
const { isNegated, processedArgs } = maybeProcessNegation(args);
|
|
164
|
+
const candidates = [];
|
|
165
|
+
for (const assertion of [...(expect?.assertions ?? []), ...assertions]) {
|
|
166
|
+
const parseResult = assertion.parseValues(processedArgs);
|
|
167
|
+
const { exactMatch, parsedValues, success } = parseResult;
|
|
168
|
+
if (success) {
|
|
169
|
+
if (exactMatch) {
|
|
170
|
+
return execute(assertion, parsedValues, [...args], expectFunction, isNegated, parseResult);
|
|
171
|
+
}
|
|
172
|
+
candidates.push({ assertion, parseResult });
|
|
160
173
|
}
|
|
161
|
-
candidates.push({ assertion, parseResult });
|
|
162
174
|
}
|
|
175
|
+
if (candidates.length) {
|
|
176
|
+
const { assertion, parseResult } = candidates[0];
|
|
177
|
+
return execute(assertion,
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
179
|
+
parseResult.parsedValues, [...args], expectFunction, isNegated, parseResult);
|
|
180
|
+
}
|
|
181
|
+
throwInvalidParametersError(args);
|
|
163
182
|
}
|
|
164
|
-
if (candidates.length) {
|
|
165
|
-
const { assertion, parseResult } = candidates[0];
|
|
166
|
-
return execute(assertion,
|
|
167
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
168
|
-
parseResult.parsedValues, [...args], expectFunction, isNegated, parseResult);
|
|
169
|
-
}
|
|
170
|
-
throwInvalidParametersError(args);
|
|
171
183
|
};
|
|
172
184
|
return expectFunction;
|
|
173
185
|
}
|
|
@@ -177,6 +189,7 @@ export function createExpectSyncFunction(assertions, expect) {
|
|
|
177
189
|
* @privateRemarks
|
|
178
190
|
* This is here because `Assertion` doesn't know anything about negation and
|
|
179
191
|
* probably shouldn't.
|
|
192
|
+
* @function
|
|
180
193
|
* @param assertion - The assertion to execute
|
|
181
194
|
* @param parsedValues - Parsed values for the assertion
|
|
182
195
|
* @param args - Original arguments passed to expect
|
|
@@ -184,39 +197,37 @@ export function createExpectSyncFunction(assertions, expect) {
|
|
|
184
197
|
* @param isNegated - Whether the assertion should be negated
|
|
185
198
|
*/
|
|
186
199
|
const execute = (assertion, parsedValues, args, stackStartFn, isNegated, parseResult) => {
|
|
187
|
-
if (
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
+
if (isNegated) {
|
|
201
|
+
// negation logic
|
|
202
|
+
try {
|
|
203
|
+
assertion.execute(parsedValues, args, stackStartFn, parseResult);
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
// success!
|
|
207
|
+
if (AssertionError.isAssertionError(error)) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (AssertionImplementationError.isAssertionImplementationError(error)) {
|
|
211
|
+
throw error;
|
|
212
|
+
}
|
|
213
|
+
throw new AssertionImplementationError(`Assertion ${assertion} threw a non-AssertionError`, { cause: error });
|
|
200
214
|
}
|
|
201
|
-
//
|
|
215
|
+
// if we reach here, then the assertion passed when it should have failed, so:
|
|
202
216
|
throw new NegatedAssertionError({
|
|
203
|
-
message: `Expected assertion to fail (due to negation), but it passed
|
|
217
|
+
message: `Expected assertion ${assertion} to fail (due to negation), but it passed`,
|
|
204
218
|
stackStartFn,
|
|
205
219
|
});
|
|
206
220
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
// This is our negation error, re-throw it
|
|
211
|
-
throw error;
|
|
221
|
+
else {
|
|
222
|
+
try {
|
|
223
|
+
assertion.execute(parsedValues, args, stackStartFn, parseResult);
|
|
212
224
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
225
|
+
catch (error) {
|
|
226
|
+
if (AssertionError.isAssertionError(error)) {
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
throw new AssertionImplementationError(`Assertion ${assertion} threw a non-AssertionError`, { cause: error });
|
|
216
230
|
}
|
|
217
|
-
debug('Non-assertion error thrown during negated assertion: %O', error);
|
|
218
|
-
// Re-throw non-assertion errors (like TypeErrors, etc.)
|
|
219
|
-
throw error;
|
|
220
231
|
}
|
|
221
232
|
};
|
|
222
233
|
/**
|
|
@@ -225,6 +236,7 @@ const execute = (assertion, parsedValues, args, stackStartFn, isNegated, parseRe
|
|
|
225
236
|
* @privateRemarks
|
|
226
237
|
* This is here because `Assertion` doesn't know anything about negation and
|
|
227
238
|
* probably shouldn't.
|
|
239
|
+
* @function
|
|
228
240
|
* @param assertion - The assertion to execute
|
|
229
241
|
* @param parsedValues - Parsed values for the assertion
|
|
230
242
|
* @param args - Original arguments passed to expectAsync
|
|
@@ -232,30 +244,34 @@ const execute = (assertion, parsedValues, args, stackStartFn, isNegated, parseRe
|
|
|
232
244
|
* @param isNegated - Whether the assertion should be negated
|
|
233
245
|
*/
|
|
234
246
|
const executeAsync = async (assertion, parsedValues, args, stackStartFn, isNegated, parseResult) => {
|
|
235
|
-
if (
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
247
|
+
if (isNegated) {
|
|
248
|
+
// negation logic
|
|
249
|
+
try {
|
|
250
|
+
await assertion.executeAsync(parsedValues, args, stackStartFn, parseResult);
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
// success!
|
|
254
|
+
if (AssertionError.isAssertionError(error)) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
throw new AssertionImplementationError(`Assertion ${assertion} threw a non-AssertionError`, { cause: error });
|
|
258
|
+
}
|
|
259
|
+
// if we reach here, then the assertion passed when it should have failed, so:
|
|
241
260
|
throw new NegatedAssertionError({
|
|
242
|
-
message: `Expected assertion to fail (due to negation), but it passed
|
|
261
|
+
message: `Expected assertion ${assertion} to fail (due to negation), but it passed`,
|
|
243
262
|
stackStartFn,
|
|
244
263
|
});
|
|
245
264
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
// This is our negation error, re-throw it
|
|
250
|
-
throw error;
|
|
265
|
+
else {
|
|
266
|
+
try {
|
|
267
|
+
await assertion.executeAsync(parsedValues, args, stackStartFn, parseResult);
|
|
251
268
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
269
|
+
catch (error) {
|
|
270
|
+
if (AssertionError.isAssertionError(error)) {
|
|
271
|
+
throw error;
|
|
272
|
+
}
|
|
273
|
+
throw new AssertionImplementationError(`Assertion ${assertion} threw a non-AssertionError`, { cause: error });
|
|
255
274
|
}
|
|
256
|
-
debug('Non-assertion error thrown during negated async assertion: %O', error);
|
|
257
|
-
// Re-throw non-assertion errors (like TypeErrors, etc.)
|
|
258
|
-
throw error;
|
|
259
275
|
}
|
|
260
276
|
};
|
|
261
277
|
/**
|
|
@@ -263,11 +279,13 @@ const executeAsync = async (assertion, parsedValues, args, stackStartFn, isNegat
|
|
|
263
279
|
* requested along with arguments stripped of the leading negation (to enable
|
|
264
280
|
* assertion matching).
|
|
265
281
|
*
|
|
282
|
+
* @function
|
|
266
283
|
* @internal
|
|
267
284
|
*/
|
|
268
285
|
const maybeProcessNegation = (args) => {
|
|
269
286
|
let isNegated = false;
|
|
270
287
|
let processedArgs = args;
|
|
288
|
+
// note: args[1] should always be a string
|
|
271
289
|
if (args.length >= 2 && isString(args[1])) {
|
|
272
290
|
const { cleanedPhrase, isNegated: detected } = detectNegation(args[1]);
|
|
273
291
|
if (detected) {
|
|
@@ -275,12 +293,44 @@ const maybeProcessNegation = (args) => {
|
|
|
275
293
|
processedArgs = [args[0], cleanedPhrase, ...args.slice(2)];
|
|
276
294
|
}
|
|
277
295
|
}
|
|
278
|
-
return
|
|
296
|
+
return { isNegated, processedArgs };
|
|
297
|
+
};
|
|
298
|
+
/**
|
|
299
|
+
* Given some args, create a matrix of args based on the presence of the
|
|
300
|
+
* conjunction operator ("and").
|
|
301
|
+
*
|
|
302
|
+
* If no "and" is present, returns the original args wrapped in an array.
|
|
303
|
+
*
|
|
304
|
+
* @function
|
|
305
|
+
*/
|
|
306
|
+
const conjunctify = (args) => {
|
|
307
|
+
let argsMatrix = [args];
|
|
308
|
+
if (args.length >= 2) {
|
|
309
|
+
// partition args by the string "and"; there may be multiple "and"s
|
|
310
|
+
const andIndices = args
|
|
311
|
+
.map((arg, index) => (arg === 'and' ? index : -1))
|
|
312
|
+
.filter((index) => index !== -1);
|
|
313
|
+
if (andIndices.length > 0) {
|
|
314
|
+
const parts = [];
|
|
315
|
+
let lastIndex = 0;
|
|
316
|
+
for (const andIndex of andIndices) {
|
|
317
|
+
const partsArgs = lastIndex > 0
|
|
318
|
+
? [args[0], ...args.slice(lastIndex, andIndex)]
|
|
319
|
+
: [...args.slice(lastIndex, andIndex)];
|
|
320
|
+
parts.push(partsArgs);
|
|
321
|
+
lastIndex = andIndex + 1;
|
|
322
|
+
}
|
|
323
|
+
parts.push([args[0], ...args.slice(lastIndex)]);
|
|
324
|
+
argsMatrix = parts;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return argsMatrix;
|
|
279
328
|
};
|
|
280
329
|
/**
|
|
281
330
|
* Throws an error indicating that no valid assertion could be found for the
|
|
282
331
|
* provided arguments.
|
|
283
332
|
*
|
|
333
|
+
* @function
|
|
284
334
|
* @param args The arguments that were passed to the expect function
|
|
285
335
|
* @internal
|
|
286
336
|
*/
|
|
@@ -293,6 +343,7 @@ const throwInvalidParametersError = (args) => {
|
|
|
293
343
|
* Detects if an assertion phrase starts with "not " and returns the cleaned
|
|
294
344
|
* phrase.
|
|
295
345
|
*
|
|
346
|
+
* @function
|
|
296
347
|
* @param phrase - The assertion phrase to check
|
|
297
348
|
* @returns Object with `isNegated` flag and `cleanedPhrase`
|
|
298
349
|
*/
|
|
@@ -309,7 +360,9 @@ const detectNegation = (phrase) => {
|
|
|
309
360
|
};
|
|
310
361
|
};
|
|
311
362
|
/**
|
|
312
|
-
* {@
|
|
363
|
+
* {@inheritDoc FailFn}
|
|
364
|
+
*
|
|
365
|
+
* @function
|
|
313
366
|
*/
|
|
314
367
|
const fail = (reason) => {
|
|
315
368
|
throw new FailAssertionError({ message: reason });
|
package/dist/esm/expect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expect.js","sourceRoot":"","sources":["../../src/expect.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAgB/B,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"expect.js","sourceRoot":"","sources":["../../src/expect.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAgB/B,OAAO,E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SAChD;QACH,CAAC,CAAC;YACE,UAAU,EAAE,eAAe;YAC3B,eAAe;YACf,oBAAoB;YACpB,IAAI;YACJ,GAAG,EAAE,SAAS,CAAC,cAAc,EAAE,eAAe,CAAC;SAChD,CAAC;AACR,CAAC"}
|
package/dist/esm/guards.d.ts
CHANGED
|
@@ -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
|
package/dist/esm/guards.d.ts.map
CHANGED
|
@@ -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,EACX,MAAM,YAAY,CAAC;AAMpB;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,UAAU,EAClD,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,CAAC,GACN,KAAK,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;AAE1B;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC,OAAO,CAAC;AAsB9D;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,WAAW,CAAC,MAAM,CAEpE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,KAAK,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