bupkis 0.1.2 → 0.3.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 +28 -0
- package/README.md +16 -16
- package/dist/commonjs/assertion/assertion-async.d.ts +2 -1
- package/dist/commonjs/assertion/assertion-async.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion-async.js +84 -2
- package/dist/commonjs/assertion/assertion-async.js.map +1 -1
- package/dist/commonjs/assertion/assertion-sync.d.ts +1 -1
- package/dist/commonjs/assertion/assertion-sync.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion-sync.js +5 -1
- package/dist/commonjs/assertion/assertion-sync.js.map +1 -1
- package/dist/commonjs/assertion/assertion-types.d.ts +39 -84
- package/dist/commonjs/assertion/assertion-types.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion.d.ts +1 -1
- package/dist/commonjs/assertion/assertion.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion.js +1 -14
- package/dist/commonjs/assertion/assertion.js.map +1 -1
- package/dist/commonjs/assertion/create.d.ts +5 -33
- package/dist/commonjs/assertion/create.d.ts.map +1 -1
- package/dist/commonjs/assertion/create.js +17 -6
- package/dist/commonjs/assertion/create.js.map +1 -1
- package/dist/commonjs/assertion/impl/async.d.ts +122 -21
- package/dist/commonjs/assertion/impl/async.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/async.js +114 -90
- package/dist/commonjs/assertion/impl/async.js.map +1 -1
- package/dist/commonjs/assertion/impl/callback.d.ts +104 -0
- package/dist/commonjs/assertion/impl/callback.d.ts.map +1 -0
- package/dist/commonjs/assertion/impl/callback.js +694 -0
- package/dist/commonjs/assertion/impl/callback.js.map +1 -0
- package/dist/commonjs/assertion/impl/index.d.ts +1 -1
- package/dist/commonjs/assertion/impl/index.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/index.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync-esoteric.js +1 -1
- package/dist/commonjs/assertion/impl/sync-esoteric.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync-parametric.d.ts +37 -34
- package/dist/commonjs/assertion/impl/sync-parametric.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync-parametric.js +32 -47
- package/dist/commonjs/assertion/impl/sync-parametric.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync.d.ts +105 -58
- package/dist/commonjs/assertion/impl/sync.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync.js +4 -1
- package/dist/commonjs/assertion/impl/sync.js.map +1 -1
- package/dist/commonjs/bootstrap.d.ts +199 -85
- package/dist/commonjs/bootstrap.d.ts.map +1 -1
- package/dist/commonjs/bootstrap.js +19 -10
- package/dist/commonjs/bootstrap.js.map +1 -1
- package/dist/commonjs/constant.js +7 -1
- package/dist/commonjs/constant.js.map +1 -1
- package/dist/commonjs/error.d.ts +32 -5
- package/dist/commonjs/error.d.ts.map +1 -1
- package/dist/commonjs/error.js +60 -5
- package/dist/commonjs/error.js.map +1 -1
- package/dist/commonjs/expect.d.ts +130 -3
- package/dist/commonjs/expect.d.ts.map +1 -1
- package/dist/commonjs/expect.js +116 -1
- package/dist/commonjs/expect.js.map +1 -1
- package/dist/commonjs/guards.d.ts +45 -20
- package/dist/commonjs/guards.d.ts.map +1 -1
- package/dist/commonjs/guards.js +56 -40
- package/dist/commonjs/guards.js.map +1 -1
- package/dist/commonjs/index.d.ts +241 -86
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +44 -42
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/metadata.d.ts +1 -27
- package/dist/commonjs/metadata.d.ts.map +1 -1
- package/dist/commonjs/metadata.js +16 -15
- package/dist/commonjs/metadata.js.map +1 -1
- package/dist/commonjs/schema.d.ts +76 -33
- package/dist/commonjs/schema.d.ts.map +1 -1
- package/dist/commonjs/schema.js +77 -34
- package/dist/commonjs/schema.js.map +1 -1
- package/dist/commonjs/types.d.ts +480 -39
- package/dist/commonjs/types.d.ts.map +1 -1
- package/dist/commonjs/types.js +12 -2
- package/dist/commonjs/types.js.map +1 -1
- package/dist/commonjs/util.d.ts +72 -49
- package/dist/commonjs/util.d.ts.map +1 -1
- package/dist/commonjs/util.js +175 -155
- package/dist/commonjs/util.js.map +1 -1
- package/dist/commonjs/value-to-schema.d.ts +122 -0
- package/dist/commonjs/value-to-schema.d.ts.map +1 -0
- package/dist/commonjs/value-to-schema.js +309 -0
- package/dist/commonjs/value-to-schema.js.map +1 -0
- package/dist/esm/assertion/assertion-async.d.ts +2 -1
- package/dist/esm/assertion/assertion-async.d.ts.map +1 -1
- package/dist/esm/assertion/assertion-async.js +85 -3
- package/dist/esm/assertion/assertion-async.js.map +1 -1
- package/dist/esm/assertion/assertion-sync.d.ts +1 -1
- package/dist/esm/assertion/assertion-sync.d.ts.map +1 -1
- package/dist/esm/assertion/assertion-sync.js +6 -2
- package/dist/esm/assertion/assertion-sync.js.map +1 -1
- package/dist/esm/assertion/assertion-types.d.ts +39 -84
- package/dist/esm/assertion/assertion-types.d.ts.map +1 -1
- package/dist/esm/assertion/assertion.d.ts +1 -1
- package/dist/esm/assertion/assertion.d.ts.map +1 -1
- package/dist/esm/assertion/assertion.js +1 -14
- package/dist/esm/assertion/assertion.js.map +1 -1
- package/dist/esm/assertion/create.d.ts +5 -33
- package/dist/esm/assertion/create.d.ts.map +1 -1
- package/dist/esm/assertion/create.js +14 -4
- package/dist/esm/assertion/create.js.map +1 -1
- package/dist/esm/assertion/impl/async.d.ts +122 -21
- package/dist/esm/assertion/impl/async.d.ts.map +1 -1
- package/dist/esm/assertion/impl/async.js +113 -89
- package/dist/esm/assertion/impl/async.js.map +1 -1
- package/dist/esm/assertion/impl/callback.d.ts +104 -0
- package/dist/esm/assertion/impl/callback.d.ts.map +1 -0
- package/dist/esm/assertion/impl/callback.js +691 -0
- package/dist/esm/assertion/impl/callback.js.map +1 -0
- package/dist/esm/assertion/impl/index.d.ts +1 -1
- package/dist/esm/assertion/impl/index.d.ts.map +1 -1
- package/dist/esm/assertion/impl/index.js +1 -1
- package/dist/esm/assertion/impl/index.js.map +1 -1
- package/dist/esm/assertion/impl/sync-esoteric.js +2 -2
- package/dist/esm/assertion/impl/sync-esoteric.js.map +1 -1
- package/dist/esm/assertion/impl/sync-parametric.d.ts +37 -34
- package/dist/esm/assertion/impl/sync-parametric.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync-parametric.js +32 -47
- package/dist/esm/assertion/impl/sync-parametric.js.map +1 -1
- package/dist/esm/assertion/impl/sync.d.ts +105 -58
- package/dist/esm/assertion/impl/sync.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync.js +3 -1
- package/dist/esm/assertion/impl/sync.js.map +1 -1
- package/dist/esm/bootstrap.d.ts +199 -85
- package/dist/esm/bootstrap.d.ts.map +1 -1
- package/dist/esm/bootstrap.js +19 -10
- package/dist/esm/bootstrap.js.map +1 -1
- package/dist/esm/constant.js +6 -0
- package/dist/esm/constant.js.map +1 -1
- package/dist/esm/error.d.ts +32 -5
- package/dist/esm/error.d.ts.map +1 -1
- package/dist/esm/error.js +59 -5
- package/dist/esm/error.js.map +1 -1
- package/dist/esm/expect.d.ts +130 -3
- package/dist/esm/expect.d.ts.map +1 -1
- package/dist/esm/expect.js +117 -2
- package/dist/esm/expect.js.map +1 -1
- package/dist/esm/guards.d.ts +45 -20
- package/dist/esm/guards.d.ts.map +1 -1
- package/dist/esm/guards.js +48 -31
- package/dist/esm/guards.js.map +1 -1
- package/dist/esm/index.d.ts +241 -86
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +46 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/metadata.d.ts +1 -27
- package/dist/esm/metadata.d.ts.map +1 -1
- package/dist/esm/metadata.js +2 -1
- package/dist/esm/metadata.js.map +1 -1
- package/dist/esm/schema.d.ts +76 -33
- package/dist/esm/schema.d.ts.map +1 -1
- package/dist/esm/schema.js +77 -34
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/types.d.ts +480 -39
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +12 -2
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/util.d.ts +72 -49
- package/dist/esm/util.d.ts.map +1 -1
- package/dist/esm/util.js +159 -153
- package/dist/esm/util.js.map +1 -1
- package/dist/esm/value-to-schema.d.ts +122 -0
- package/dist/esm/value-to-schema.d.ts.map +1 -0
- package/dist/esm/value-to-schema.js +305 -0
- package/dist/esm/value-to-schema.js.map +1 -0
- package/package.json +94 -17
- package/src/assertion/assertion-async.ts +113 -3
- package/src/assertion/assertion-sync.ts +5 -2
- package/src/assertion/assertion-types.ts +52 -45
- package/src/assertion/assertion.ts +2 -17
- package/src/assertion/create.ts +16 -65
- package/src/assertion/impl/async.ts +132 -92
- package/src/assertion/impl/callback.ts +882 -0
- package/src/assertion/impl/index.ts +1 -1
- package/src/assertion/impl/sync-esoteric.ts +2 -2
- package/src/assertion/impl/sync-parametric.ts +41 -49
- package/src/assertion/impl/sync.ts +3 -0
- package/src/bootstrap.ts +21 -11
- package/src/constant.ts +8 -0
- package/src/error.ts +75 -4
- package/src/expect.ts +275 -20
- package/src/guards.ts +74 -69
- package/src/index.ts +72 -11
- package/src/metadata.ts +3 -4
- package/src/schema.ts +80 -36
- package/src/types.ts +625 -72
- package/src/util.ts +174 -222
- package/src/value-to-schema.ts +464 -0
- package/dist/commonjs/api.d.ts +0 -93
- package/dist/commonjs/api.d.ts.map +0 -1
- package/dist/commonjs/api.js +0 -8
- package/dist/commonjs/api.js.map +0 -1
- package/dist/esm/api.d.ts +0 -93
- package/dist/esm/api.d.ts.map +0 -1
- package/dist/esm/api.js +0 -7
- package/dist/esm/api.js.map +0 -1
- package/src/api.ts +0 -149
- package/src/schema.md +0 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/bootstrap.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/bootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAwB3D,QAAA;AACE;;;;;GAKG;AACH,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACN;;;;;GAKG;AACH,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2hBACN,CAAC;AAER,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -2,33 +2,42 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Factory function for creating the main assertion functions.
|
|
4
4
|
*
|
|
5
|
-
* This module provides the
|
|
6
|
-
* and asynchronous assertion engines.
|
|
7
|
-
* previously split between `expect.ts` and `expect-async.ts`.
|
|
5
|
+
* This module provides the {@link bootstrap} function that creates both
|
|
6
|
+
* synchronous and asynchronous assertion engines.
|
|
8
7
|
*
|
|
9
8
|
* @packageDocumentation
|
|
10
9
|
*/
|
|
11
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
11
|
exports.expectAsync = exports.expect = void 0;
|
|
13
|
-
const sync_js_1 = require("./assertion/impl/sync.js");
|
|
14
12
|
const index_js_1 = require("./assertion/index.js");
|
|
15
13
|
const use_js_1 = require("./use.js");
|
|
16
14
|
/**
|
|
17
15
|
* Factory function that creates both synchronous and asynchronous assertion
|
|
18
16
|
* engines.
|
|
19
17
|
*
|
|
20
|
-
* @returns Object containing
|
|
18
|
+
* @returns Object containing {@link expect} and {@link expectAsync} functions
|
|
21
19
|
* @internal
|
|
22
20
|
*/
|
|
23
21
|
const bootstrap = () => {
|
|
24
|
-
const { expect, expectAsync } = (0, use_js_1.createUse)(
|
|
22
|
+
const { expect, expectAsync } = (0, use_js_1.createUse)(index_js_1.SyncAssertions, index_js_1.AsyncAssertions)([...index_js_1.SyncAssertions, ...index_js_1.AsyncAssertions]);
|
|
25
23
|
return { expect, expectAsync };
|
|
26
24
|
};
|
|
27
25
|
const api = bootstrap();
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const {
|
|
27
|
+
/**
|
|
28
|
+
* The main synchronous assertion function which can execute only built-in
|
|
29
|
+
* assertions.
|
|
30
|
+
*
|
|
31
|
+
* @function
|
|
32
|
+
*/
|
|
33
|
+
expect,
|
|
34
|
+
/**
|
|
35
|
+
* The main asynchronous assertion function which can execute only built-in
|
|
36
|
+
* assertions.
|
|
37
|
+
*
|
|
38
|
+
* @function
|
|
39
|
+
*/
|
|
40
|
+
expectAsync, } = api;
|
|
30
41
|
exports.expect = expect;
|
|
31
|
-
/** {@inheritDoc ExpectAsync} */
|
|
32
|
-
const { expectAsync } = api;
|
|
33
42
|
exports.expectAsync = expectAsync;
|
|
34
43
|
//# sourceMappingURL=bootstrap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/bootstrap.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/bootstrap.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,mDAAuE;AAEvE,qCAAqC;AAErC;;;;;;GAMG;AACH,MAAM,SAAS,GAAG,GAGhB,EAAE;IACF,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAA,kBAAS,EACvC,yBAAc,EACd,0BAAe,CAChB,CAAC,CAAC,GAAG,yBAAc,EAAE,GAAG,0BAAe,CAAC,CAAC,CAAC;IAE3C,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;AACjC,CAAC,CAAC;AAEF,MAAM,GAAG,GAAG,SAAS,EAAE,CAAC;AAExB,MAAM;AACJ;;;;;GAKG;AACH,MAAM;AACN;;;;;GAKG;AACH,WAAW,GACZ,GAAG,GAAG,CAAC;AAEC,wBAAM;AAAE,kCAAW"}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.kBupkisNegatedAssertionError = exports.kBupkisAssertionError = exports.kStringLiteral = void 0;
|
|
13
|
+
exports.kBupkisNegatedAssertionError = exports.kBupkisFailAssertionError = exports.kBupkisAssertionError = exports.kStringLiteral = void 0;
|
|
14
14
|
/**
|
|
15
15
|
* Symbol flagging the value as a Bupkis-created string literal, which will be
|
|
16
16
|
* omitted from the parameters to an `AssertionImpl`.
|
|
@@ -24,6 +24,12 @@ exports.kStringLiteral = Symbol('bupkis:string-literal');
|
|
|
24
24
|
* @internal
|
|
25
25
|
*/
|
|
26
26
|
exports.kBupkisAssertionError = Symbol('bupkis-error');
|
|
27
|
+
/**
|
|
28
|
+
* Symbol used to flag a `FailAssertionError`
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
exports.kBupkisFailAssertionError = Symbol('bupkis-fail-error');
|
|
27
33
|
/**
|
|
28
34
|
* Symbol used to flag a `NegatedAssertionError`
|
|
29
35
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constant.js","sourceRoot":"","sources":["../../src/constant.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH;;;;;GAKG;AAEU,QAAA,cAAc,GAAkB,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAE7E;;;;GAIG;AAEU,QAAA,qBAAqB,GAAkB,MAAM,CAAC,cAAc,CAAC,CAAC;AAE3E;;;;GAIG;AAEU,QAAA,4BAA4B,GAAkB,MAAM,CAC/D,sBAAsB,CACvB,CAAC"}
|
|
1
|
+
{"version":3,"file":"constant.js","sourceRoot":"","sources":["../../src/constant.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH;;;;;GAKG;AAEU,QAAA,cAAc,GAAkB,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAE7E;;;;GAIG;AAEU,QAAA,qBAAqB,GAAkB,MAAM,CAAC,cAAc,CAAC,CAAC;AAE3E;;;;GAIG;AACU,QAAA,yBAAyB,GACpC,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAE9B;;;;GAIG;AAEU,QAAA,4BAA4B,GAAkB,MAAM,CAC/D,sBAAsB,CACvB,CAAC"}
|
package/dist/commonjs/error.d.ts
CHANGED
|
@@ -6,15 +6,42 @@
|
|
|
6
6
|
* @packageDocumentation
|
|
7
7
|
*/
|
|
8
8
|
import { AssertionError as NodeAssertionError } from 'node:assert';
|
|
9
|
-
import {
|
|
9
|
+
import { z } from 'zod/v4';
|
|
10
|
+
import { type AssertionParts, type ParsedValues } from './types.js';
|
|
10
11
|
/**
|
|
11
12
|
* _BUPKIS_' s custom `AssertionError` class, which is just a thin wrapper
|
|
12
13
|
* around Node.js' {@link NodeAssertionError AssertionError}.
|
|
13
|
-
*
|
|
14
|
-
* @public
|
|
15
14
|
*/
|
|
16
15
|
export declare class AssertionError extends NodeAssertionError {
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
name: string;
|
|
17
|
+
/**
|
|
18
|
+
* Translates a {@link z.ZodError} into an {@link AssertionError} with a
|
|
19
|
+
* human-friendly message.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* This does not handle parameterized assertions with more than one parameter
|
|
23
|
+
* too cleanly; it's unclear how a test runner would display the expected
|
|
24
|
+
* values. This will probably need a fix in the future.
|
|
25
|
+
* @param stackStartFn The function to start the stack trace from
|
|
26
|
+
* @param zodError The original `ZodError`
|
|
27
|
+
* @param values Values which caused the error
|
|
28
|
+
* @returns New `AssertionError`
|
|
29
|
+
*/
|
|
30
|
+
static fromZodError<Parts extends AssertionParts>(zodError: z.ZodError, stackStartFn: (...args: any[]) => any, values: ParsedValues<Parts>): AssertionError;
|
|
31
|
+
/**
|
|
32
|
+
* Type guard for an instance of this error.
|
|
33
|
+
*
|
|
34
|
+
* @param value Some value
|
|
35
|
+
* @returns `true` if `value` is an instance of `AssertionError`
|
|
36
|
+
*/
|
|
37
|
+
static isAssertionError(value: unknown): value is AssertionError;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Variant of an {@link AssertionError} that is thrown when
|
|
41
|
+
* {@link bupkis!expect.fail} is called.
|
|
42
|
+
*/
|
|
43
|
+
export declare class FailAssertionError extends AssertionError {
|
|
44
|
+
name: string;
|
|
45
|
+
static isFailAssertionError(err: unknown): err is FailAssertionError;
|
|
19
46
|
}
|
|
20
47
|
//# sourceMappingURL=error.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAQ3B,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAEpE;;;GAGG;AACH,qBAAa,cAAe,SAAQ,kBAAkB;IAM3C,IAAI,SAAoB;IAEjC;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,YAAY,CAAC,KAAK,SAAS,cAAc,EAC9C,QAAQ,EAAE,CAAC,CAAC,QAAQ,EACpB,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACrC,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,GAC1B,cAAc;IAmBjB;;;;;OAKG;IACH,MAAM,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc;CAMjE;AAED;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,cAAc;IAM3C,IAAI,SAAwB;IAErC,MAAM,CAAC,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,kBAAkB;CAMrE"}
|
package/dist/commonjs/error.js
CHANGED
|
@@ -7,23 +7,77 @@
|
|
|
7
7
|
* @packageDocumentation
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.NegatedAssertionError = exports.AssertionError = void 0;
|
|
10
|
+
exports.NegatedAssertionError = exports.FailAssertionError = exports.AssertionError = void 0;
|
|
11
11
|
const node_assert_1 = require("node:assert");
|
|
12
|
+
const v4_1 = require("zod/v4");
|
|
12
13
|
const constant_js_1 = require("./constant.js");
|
|
13
14
|
const guards_js_1 = require("./guards.js");
|
|
14
15
|
/**
|
|
15
16
|
* _BUPKIS_' s custom `AssertionError` class, which is just a thin wrapper
|
|
16
17
|
* around Node.js' {@link NodeAssertionError AssertionError}.
|
|
17
|
-
*
|
|
18
|
-
* @public
|
|
19
18
|
*/
|
|
20
19
|
class AssertionError extends node_assert_1.AssertionError {
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
21
23
|
[constant_js_1.kBupkisAssertionError] = true;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
name = 'AssertionError';
|
|
25
|
+
/**
|
|
26
|
+
* Translates a {@link z.ZodError} into an {@link AssertionError} with a
|
|
27
|
+
* human-friendly message.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* This does not handle parameterized assertions with more than one parameter
|
|
31
|
+
* too cleanly; it's unclear how a test runner would display the expected
|
|
32
|
+
* values. This will probably need a fix in the future.
|
|
33
|
+
* @param stackStartFn The function to start the stack trace from
|
|
34
|
+
* @param zodError The original `ZodError`
|
|
35
|
+
* @param values Values which caused the error
|
|
36
|
+
* @returns New `AssertionError`
|
|
37
|
+
*/
|
|
38
|
+
static fromZodError(zodError, stackStartFn, values) {
|
|
39
|
+
const flat = v4_1.z.flattenError(zodError);
|
|
40
|
+
let pretty = flat.formErrors.join('; ');
|
|
41
|
+
for (const [keypath, errors] of Object.entries(flat.fieldErrors)) {
|
|
42
|
+
pretty += `; ${keypath}: ${errors.join('; ')}`;
|
|
43
|
+
}
|
|
44
|
+
const [actual, ...expected] = values;
|
|
45
|
+
return new AssertionError({
|
|
46
|
+
actual,
|
|
47
|
+
expected: expected.length === 1 ? expected[0] : expected,
|
|
48
|
+
message: `Assertion ${this} failed: ${pretty}`,
|
|
49
|
+
operator: `${this}`,
|
|
50
|
+
stackStartFn,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Type guard for an instance of this error.
|
|
55
|
+
*
|
|
56
|
+
* @param value Some value
|
|
57
|
+
* @returns `true` if `value` is an instance of `AssertionError`
|
|
58
|
+
*/
|
|
59
|
+
static isAssertionError(value) {
|
|
60
|
+
return ((0, guards_js_1.isA)(value, node_assert_1.AssertionError) &&
|
|
61
|
+
Object.hasOwn(value, constant_js_1.kBupkisAssertionError));
|
|
24
62
|
}
|
|
25
63
|
}
|
|
26
64
|
exports.AssertionError = AssertionError;
|
|
65
|
+
/**
|
|
66
|
+
* Variant of an {@link AssertionError} that is thrown when
|
|
67
|
+
* {@link bupkis!expect.fail} is called.
|
|
68
|
+
*/
|
|
69
|
+
class FailAssertionError extends AssertionError {
|
|
70
|
+
/**
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
[constant_js_1.kBupkisFailAssertionError] = true;
|
|
74
|
+
name = 'FailAssertionError';
|
|
75
|
+
static isFailAssertionError(err) {
|
|
76
|
+
return ((0, guards_js_1.isA)(err, FailAssertionError) &&
|
|
77
|
+
Object.hasOwn(err, constant_js_1.kBupkisFailAssertionError));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.FailAssertionError = FailAssertionError;
|
|
27
81
|
/**
|
|
28
82
|
* Error type used internally to catch failed negated assertions.
|
|
29
83
|
*
|
|
@@ -31,6 +85,7 @@ exports.AssertionError = AssertionError;
|
|
|
31
85
|
*/
|
|
32
86
|
class NegatedAssertionError extends AssertionError {
|
|
33
87
|
[constant_js_1.kBupkisNegatedAssertionError] = true;
|
|
88
|
+
name = 'NegatedAssertionError';
|
|
34
89
|
static isNegatedAssertionError(err) {
|
|
35
90
|
return ((0, guards_js_1.isA)(err, AssertionError) &&
|
|
36
91
|
Object.hasOwn(err, constant_js_1.kBupkisNegatedAssertionError));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,6CAAmE;
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,6CAAmE;AACnE,+BAA2B;AAE3B,+CAIuB;AACvB,2CAAkC;AAGlC;;;GAGG;AACH,MAAa,cAAe,SAAQ,4BAAkB;IACpD;;OAEG;IACH,CAAC,mCAAqB,CAAC,GAAG,IAAI,CAAC;IAEtB,IAAI,GAAG,gBAAgB,CAAC;IAEjC;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,YAAY,CACjB,QAAoB,EACpB,YAAqC,EACrC,MAA2B;QAE3B,MAAM,IAAI,GAAG,MAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QAEtC,IAAI,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxC,KAAK,MAAM,CAAC,OAAO,EAAE,MAAM,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AAC,GAAY;QACzC,OAAO,CACL,IAAA,eAAG,EAAC,GAAG,EAAE,cAAc,CAAC;YACxB,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,0CAA4B,CAAC,CACjD,CAAC;IACJ,CAAC;CACF;AAXD,sDAWC"}
|
|
@@ -1,9 +1,136 @@
|
|
|
1
|
-
import { type Expect, type ExpectAsync, type ExpectAsyncFunction, type ExpectAsyncProps, type ExpectFunction, type ExpectSyncProps } from './api.js';
|
|
2
1
|
import { type AnyAsyncAssertions, type AnySyncAssertions } from './assertion/assertion-types.js';
|
|
2
|
+
import { type Expect, type ExpectAsync, type ExpectAsyncFunction, type ExpectAsyncProps, type ExpectFunction, type ExpectSyncProps } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates an asynchronous expect function by extending a parent expectAsync
|
|
5
|
+
* function with additional assertions.
|
|
6
|
+
*
|
|
7
|
+
* This overload combines assertions from an existing parent expectAsync
|
|
8
|
+
* function with new assertions, creating a unified expectAsync function that
|
|
9
|
+
* supports both sets of assertions. The resulting function inherits all type
|
|
10
|
+
* information from both the parent and new assertions, providing complete
|
|
11
|
+
* TypeScript intellisense and type safety for Promise-based testing scenarios.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const baseExpectAsync = createExpectAsyncFunction(basicAsyncAssertions);
|
|
17
|
+
* const extendedExpectAsync = createExpectAsyncFunction(
|
|
18
|
+
* customAsyncAssertions,
|
|
19
|
+
* baseExpectAsync,
|
|
20
|
+
* );
|
|
21
|
+
*
|
|
22
|
+
* // Can use both basic and custom async assertions
|
|
23
|
+
* await extendedExpectAsync(promise, 'to resolve'); // From basic assertions
|
|
24
|
+
* await extendedExpectAsync(promise, 'to resolve with custom data'); // From custom assertions
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param assertions - Array of new asynchronous assertion objects to add
|
|
28
|
+
* @param expect - Parent expectAsync function whose assertions will be
|
|
29
|
+
* inherited
|
|
30
|
+
* @returns ExpectAsync function with combined assertion types from both parent
|
|
31
|
+
* and new assertions
|
|
32
|
+
* @throws {@link AssertionError} When an assertion fails in normal
|
|
33
|
+
* (non-negated) mode
|
|
34
|
+
* @throws {@link NegatedAssertionError} When a negated assertion fails
|
|
35
|
+
* @throws {Error} When no matching assertion can be found for the provided
|
|
36
|
+
* arguments
|
|
37
|
+
*/
|
|
3
38
|
export declare function createExpectAsyncFunction<T extends AnyAsyncAssertions, U extends ExpectAsync<AnyAsyncAssertions>>(assertions: T, expect: U): ExpectAsyncFunction<T & U['assertions']>;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new asynchronous expect function with the provided assertions.
|
|
41
|
+
*
|
|
42
|
+
* This overload creates a standalone expectAsync function from the provided
|
|
43
|
+
* assertions without inheriting from any parent function. This is typically
|
|
44
|
+
* used to create the initial expectAsync function or when you want a clean
|
|
45
|
+
* slate without any inherited assertions for Promise-based testing.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
*
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const expectAsync = createExpectAsyncFunction(asyncAssertions);
|
|
51
|
+
* await expectAsync(promise, 'to resolve');
|
|
52
|
+
* await expectAsync(rejectedPromise, 'to reject');
|
|
53
|
+
* await expectAsync(promise, 'to resolve to', expectedValue);
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @param assertions - Array of asynchronous assertion objects that define the
|
|
57
|
+
* available assertion phrases and Promise-based logic
|
|
58
|
+
* @returns An asynchronous expect function that can execute the provided
|
|
59
|
+
* assertions using natural language syntax
|
|
60
|
+
* @throws {@link AssertionError} When an assertion fails in normal
|
|
61
|
+
* (non-negated) mode
|
|
62
|
+
* @throws {@link NegatedAssertionError} When a negated assertion fails
|
|
63
|
+
* @throws {Error} When no matching assertion can be found for the provided
|
|
64
|
+
* arguments
|
|
65
|
+
*/
|
|
4
66
|
export declare function createExpectAsyncFunction<T extends AnyAsyncAssertions>(assertions: T): ExpectAsyncFunction<T>;
|
|
5
|
-
|
|
6
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Creates a synchronous expect function by extending a parent expect function
|
|
69
|
+
* with additional assertions.
|
|
70
|
+
*
|
|
71
|
+
* This overload combines assertions from an existing parent expect function
|
|
72
|
+
* with new assertions, creating a unified expect function that supports both
|
|
73
|
+
* sets of assertions. The resulting function inherits all type information from
|
|
74
|
+
* both the parent and new assertions, providing complete TypeScript
|
|
75
|
+
* intellisense and type safety.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
*
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const baseExpect = createExpectSyncFunction(basicAssertions);
|
|
81
|
+
* const extendedExpect = createExpectSyncFunction(
|
|
82
|
+
* customAssertions,
|
|
83
|
+
* baseExpect,
|
|
84
|
+
* );
|
|
85
|
+
*
|
|
86
|
+
* // Can use both basic and custom assertions
|
|
87
|
+
* extendedExpect(42, 'to be a number'); // From basic assertions
|
|
88
|
+
* extendedExpect(obj, 'to have custom prop'); // From custom assertions
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @param assertions - Array of new synchronous assertion objects to add
|
|
92
|
+
* @param expect - Parent expect function whose assertions will be inherited
|
|
93
|
+
* @returns Expect function with combined assertion types from both parent and
|
|
94
|
+
* new assertions
|
|
95
|
+
* @throws {@link AssertionError} When an assertion fails in normal
|
|
96
|
+
* (non-negated) mode
|
|
97
|
+
* @throws {@link NegatedAssertionError} When a negated assertion fails
|
|
98
|
+
* @throws {Error} When no matching assertion can be found for the provided
|
|
99
|
+
* arguments
|
|
100
|
+
*/
|
|
101
|
+
export declare function createExpectSyncFunction<Assertions extends AnySyncAssertions, ParentExpect extends Expect<AnySyncAssertions>>(assertions: Assertions, expect: ParentExpect): ExpectFunction<Assertions & ParentExpect['assertions']>;
|
|
102
|
+
/**
|
|
103
|
+
* Creates a new synchronous expect function with the provided assertions.
|
|
104
|
+
*
|
|
105
|
+
* This overload creates a standalone expect function from the provided
|
|
106
|
+
* assertions without inheriting from any parent function. This is typically
|
|
107
|
+
* used to create the initial expect function or when you want a clean slate
|
|
108
|
+
* without any inherited assertions.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
*
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const expect = createExpectSyncFunction(basicAssertions);
|
|
114
|
+
* expect(42, 'to be a number');
|
|
115
|
+
* expect('hello', 'to be a string');
|
|
116
|
+
* expect([], 'to be empty');
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @param assertions - Array of synchronous assertion objects that define the
|
|
120
|
+
* available assertion phrases and logic
|
|
121
|
+
* @returns A synchronous expect function that can execute the provided
|
|
122
|
+
* assertions using natural language syntax
|
|
123
|
+
* @throws {@link AssertionError} When an assertion fails in normal
|
|
124
|
+
* (non-negated) mode
|
|
125
|
+
* @throws {@link NegatedAssertionError} When a negated assertion fails
|
|
126
|
+
* @throws {Error} When no matching assertion can be found for the provided
|
|
127
|
+
* arguments
|
|
128
|
+
*/
|
|
129
|
+
export declare function createExpectSyncFunction<Assertions extends AnySyncAssertions>(assertions: Assertions): ExpectFunction<Assertions>;
|
|
130
|
+
/**
|
|
131
|
+
* Used by a {@link UseFn} to create base properties of the {@link Expect} and
|
|
132
|
+
* {@link ExpectAsync} functions.
|
|
133
|
+
*/
|
|
7
134
|
export declare function createBaseExpect<T extends AnySyncAssertions, U extends AnyAsyncAssertions>(syncAssertions: T, asyncAssertions: U, type: 'sync'): ExpectSyncProps<T, U>;
|
|
8
135
|
export declare function createBaseExpect<T extends AnySyncAssertions, U extends AnyAsyncAssertions>(syncAssertions: T, asyncAssertions: U, type: 'async'): ExpectAsyncProps<U, T>;
|
|
9
136
|
//# sourceMappingURL=expect.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/expect.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,WAAW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GAGG;AACH,wBAAgB,gBAAgB,CAC9B,CAAC,SAAS,iBAAiB,EAC3B,CAAC,SAAS,kBAAkB,EAC5B,cAAc,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC9E,wBAAgB,gBAAgB,CAC9B,CAAC,SAAS,iBAAiB,EAC3B,CAAC,SAAS,kBAAkB,EAC5B,cAAc,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,GAAG,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
package/dist/commonjs/expect.js
CHANGED
|
@@ -13,6 +13,68 @@ const error_js_1 = require("./error.js");
|
|
|
13
13
|
const guards_js_1 = require("./guards.js");
|
|
14
14
|
const use_js_1 = require("./use.js");
|
|
15
15
|
const debug = (0, debug_1.default)('bupkis:expect');
|
|
16
|
+
/**
|
|
17
|
+
* Implementation function that creates an asynchronous expect function with
|
|
18
|
+
* optional parent inheritance.
|
|
19
|
+
*
|
|
20
|
+
* This is the concrete implementation that handles both overload cases for
|
|
21
|
+
* Promise-based assertions. It creates an expectAsync function that uses a
|
|
22
|
+
* two-phase matching algorithm: first seeking exact phrase matches for optimal
|
|
23
|
+
* performance, then falling back to partial matches if needed. The function
|
|
24
|
+
* processes negation keywords, combines parent assertions with new ones, and
|
|
25
|
+
* ensures all operations are properly awaited.
|
|
26
|
+
*
|
|
27
|
+
* The matching algorithm prioritizes exact matches to minimize performance
|
|
28
|
+
* overhead, but provides flexibility through partial matching when exact
|
|
29
|
+
* phrases don't align. This enables natural language flexibility while
|
|
30
|
+
* maintaining execution speed for common async assertion patterns.
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* The function performs async assertion matching in the following order:
|
|
34
|
+
*
|
|
35
|
+
* 1. Awaits `Promise.resolve()` to ensure the function is always asynchronous
|
|
36
|
+
* 2. Processes negation keywords ('not', 'to not') to determine assertion mode
|
|
37
|
+
* 3. Combines parent assertions (if provided) with new assertions in execution
|
|
38
|
+
* order
|
|
39
|
+
* 4. Attempts to parse arguments against each assertion's expected phrase pattern
|
|
40
|
+
* using `parseValuesAsync`
|
|
41
|
+
* 5. Prioritizes exact phrase matches over partial matches for performance
|
|
42
|
+
* 6. Executes the first successful match using {@link executeAsync} or throws an
|
|
43
|
+
* error if none found
|
|
44
|
+
*
|
|
45
|
+
* Performance considerations: The function loops through all available
|
|
46
|
+
* assertions for each call, but uses early termination when exact matches are
|
|
47
|
+
* found. For performance-critical code, consider using assertion functions with
|
|
48
|
+
* fewer total assertions or more specific phrase patterns to reduce matching
|
|
49
|
+
* overhead.
|
|
50
|
+
*
|
|
51
|
+
* All assertion execution is properly awaited to handle Promise-based
|
|
52
|
+
* validation logic, error handling, and negation scenarios in asynchronous
|
|
53
|
+
* contexts.
|
|
54
|
+
* @example
|
|
55
|
+
*
|
|
56
|
+
* ```typescript
|
|
57
|
+
* // Used internally by both public overloads
|
|
58
|
+
* const expectAsync1 = createExpectAsyncFunction(assertions); // No parent
|
|
59
|
+
* const expectAsync2 = createExpectAsyncFunction(assertions, parent); // With parent
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @param assertions - Array of asynchronous assertion objects to make available
|
|
63
|
+
* @param expect - Optional parent expectAsync function to inherit assertions
|
|
64
|
+
* from
|
|
65
|
+
* @returns Asynchronous expect function that processes natural language
|
|
66
|
+
* assertions with Promise support
|
|
67
|
+
* @throws {@link AssertionError} When an assertion fails in normal
|
|
68
|
+
* (non-negated) mode
|
|
69
|
+
* @throws {@link NegatedAssertionError} When a negated assertion fails (e.g.,
|
|
70
|
+
* `await expectAsync(promise, 'not to resolve')`)
|
|
71
|
+
* @throws {Error} When no matching assertion can be found for the provided
|
|
72
|
+
* arguments
|
|
73
|
+
* @internal This is the concrete implementation used by the public overloads
|
|
74
|
+
* @see {@link createExpectSyncFunction} for creating synchronous expect functions
|
|
75
|
+
* @see {@link createAsyncAssertion} for creating individual async assertion objects
|
|
76
|
+
* @see {@link ExpectAsync} for the main expectAsync interface
|
|
77
|
+
*/
|
|
16
78
|
function createExpectAsyncFunction(assertions, expect) {
|
|
17
79
|
debug('Creating expectAsync function with %d assertions', assertions.length + (expect?.assertions.length ?? 0));
|
|
18
80
|
const expectAsyncFunction = async (...args) => {
|
|
@@ -39,6 +101,59 @@ function createExpectAsyncFunction(assertions, expect) {
|
|
|
39
101
|
};
|
|
40
102
|
return expectAsyncFunction;
|
|
41
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Implementation function that creates a synchronous expect function with
|
|
106
|
+
* optional parent inheritance.
|
|
107
|
+
*
|
|
108
|
+
* This is the concrete implementation that handles both overload cases. It
|
|
109
|
+
* creates an expect function that uses a two-phase matching algorithm: first
|
|
110
|
+
* seeking exact phrase matches for optimal performance, then falling back to
|
|
111
|
+
* partial matches if needed. The function processes negation keywords and
|
|
112
|
+
* combines parent assertions with new ones.
|
|
113
|
+
*
|
|
114
|
+
* The matching algorithm prioritizes exact matches to minimize performance
|
|
115
|
+
* overhead, but provides flexibility through partial matching when exact
|
|
116
|
+
* phrases don't align. This enables natural language flexibility while
|
|
117
|
+
* maintaining execution speed for common assertion patterns.
|
|
118
|
+
*
|
|
119
|
+
* @remarks
|
|
120
|
+
* The function performs assertion matching in the following order:
|
|
121
|
+
*
|
|
122
|
+
* 1. Processes negation keywords ('not', 'to not') to determine assertion mode
|
|
123
|
+
* 2. Combines parent assertions (if provided) with new assertions in execution
|
|
124
|
+
* order
|
|
125
|
+
* 3. Attempts to parse arguments against each assertion's expected phrase pattern
|
|
126
|
+
* 4. Prioritizes exact phrase matches over partial matches for performance
|
|
127
|
+
* 5. Executes the first successful match or throws an error if none found
|
|
128
|
+
*
|
|
129
|
+
* Performance considerations: The function loops through all available
|
|
130
|
+
* assertions for each call, but uses early termination when exact matches are
|
|
131
|
+
* found. For performance-critical code, consider using assertion functions with
|
|
132
|
+
* fewer total assertions or more specific phrase patterns to reduce matching
|
|
133
|
+
* overhead.
|
|
134
|
+
* @example
|
|
135
|
+
*
|
|
136
|
+
* ```typescript
|
|
137
|
+
* // Used internally by both public overloads
|
|
138
|
+
* const expect1 = createExpectSyncFunction(assertions); // No parent
|
|
139
|
+
* const expect2 = createExpectSyncFunction(assertions, parent); // With parent
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @param assertions - Array of synchronous assertion objects to make available
|
|
143
|
+
* @param expect - Optional parent expect function to inherit assertions from
|
|
144
|
+
* @returns Synchronous expect function that processes natural language
|
|
145
|
+
* assertions
|
|
146
|
+
* @throws {@link AssertionError} When an assertion fails in normal
|
|
147
|
+
* (non-negated) mode
|
|
148
|
+
* @throws {@link NegatedAssertionError} When a negated assertion fails (e.g.,
|
|
149
|
+
* `expect(42, 'not to be a number')`)
|
|
150
|
+
* @throws {Error} When no matching assertion can be found for the provided
|
|
151
|
+
* arguments
|
|
152
|
+
* @internal This is the concrete implementation used by the public overloads
|
|
153
|
+
* @see {@link createExpectAsyncFunction} for creating asynchronous expect functions
|
|
154
|
+
* @see {@link createAssertion} for creating individual assertion objects
|
|
155
|
+
* @see {@link Expect} for the main expect interface
|
|
156
|
+
*/
|
|
42
157
|
function createExpectSyncFunction(assertions, expect) {
|
|
43
158
|
debug('Creating expect function with %d assertions', assertions.length + (expect?.assertions.length ?? 0));
|
|
44
159
|
const expectFunction = (...args) => {
|
|
@@ -196,7 +311,7 @@ const detectNegation = (phrase) => {
|
|
|
196
311
|
};
|
|
197
312
|
};
|
|
198
313
|
const fail = (reason) => {
|
|
199
|
-
throw new error_js_1.
|
|
314
|
+
throw new error_js_1.FailAssertionError({ message: reason });
|
|
200
315
|
};
|
|
201
316
|
function createBaseExpect(syncAssertions, asyncAssertions, type) {
|
|
202
317
|
return type === 'sync'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expect.js","sourceRoot":"","sources":["../../src/expect.ts"],"names":[],"mappings":";;;;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