bupkis 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +35 -11
  3. package/dist/commonjs/assertion/assertion-async.d.ts +2 -1
  4. package/dist/commonjs/assertion/assertion-async.d.ts.map +1 -1
  5. package/dist/commonjs/assertion/assertion-async.js +84 -2
  6. package/dist/commonjs/assertion/assertion-async.js.map +1 -1
  7. package/dist/commonjs/assertion/assertion-sync.d.ts +1 -1
  8. package/dist/commonjs/assertion/assertion-sync.d.ts.map +1 -1
  9. package/dist/commonjs/assertion/assertion-sync.js +5 -1
  10. package/dist/commonjs/assertion/assertion-sync.js.map +1 -1
  11. package/dist/commonjs/assertion/assertion-types.d.ts +6 -2
  12. package/dist/commonjs/assertion/assertion-types.d.ts.map +1 -1
  13. package/dist/commonjs/assertion/assertion.d.ts +1 -1
  14. package/dist/commonjs/assertion/assertion.d.ts.map +1 -1
  15. package/dist/commonjs/assertion/assertion.js +1 -14
  16. package/dist/commonjs/assertion/assertion.js.map +1 -1
  17. package/dist/commonjs/assertion/impl/async.d.ts +122 -21
  18. package/dist/commonjs/assertion/impl/async.d.ts.map +1 -1
  19. package/dist/commonjs/assertion/impl/async.js +118 -90
  20. package/dist/commonjs/assertion/impl/async.js.map +1 -1
  21. package/dist/commonjs/assertion/impl/callback.d.ts +104 -0
  22. package/dist/commonjs/assertion/impl/callback.d.ts.map +1 -0
  23. package/dist/commonjs/assertion/impl/callback.js +694 -0
  24. package/dist/commonjs/assertion/impl/callback.js.map +1 -0
  25. package/dist/commonjs/assertion/impl/index.d.ts +1 -1
  26. package/dist/commonjs/assertion/impl/index.d.ts.map +1 -1
  27. package/dist/commonjs/assertion/impl/index.js.map +1 -1
  28. package/dist/commonjs/assertion/impl/sync-basic.d.ts.map +1 -1
  29. package/dist/commonjs/assertion/impl/sync-basic.js +1 -1
  30. package/dist/commonjs/assertion/impl/sync-basic.js.map +1 -1
  31. package/dist/commonjs/assertion/impl/sync-collection.d.ts +1 -1
  32. package/dist/commonjs/assertion/impl/sync-collection.js +3 -3
  33. package/dist/commonjs/assertion/impl/sync-collection.js.map +1 -1
  34. package/dist/commonjs/assertion/impl/sync-esoteric.js +1 -1
  35. package/dist/commonjs/assertion/impl/sync-esoteric.js.map +1 -1
  36. package/dist/commonjs/assertion/impl/sync-parametric.d.ts +22 -28
  37. package/dist/commonjs/assertion/impl/sync-parametric.d.ts.map +1 -1
  38. package/dist/commonjs/assertion/impl/sync-parametric.js +35 -50
  39. package/dist/commonjs/assertion/impl/sync-parametric.js.map +1 -1
  40. package/dist/commonjs/assertion/impl/sync.d.ts +68 -30
  41. package/dist/commonjs/assertion/impl/sync.d.ts.map +1 -1
  42. package/dist/commonjs/assertion/impl/sync.js +4 -1
  43. package/dist/commonjs/assertion/impl/sync.js.map +1 -1
  44. package/dist/commonjs/bootstrap.d.ts +147 -52
  45. package/dist/commonjs/bootstrap.d.ts.map +1 -1
  46. package/dist/commonjs/bootstrap.js +2 -3
  47. package/dist/commonjs/bootstrap.js.map +1 -1
  48. package/dist/commonjs/constant.d.ts +1 -1
  49. package/dist/commonjs/constant.d.ts.map +1 -1
  50. package/dist/commonjs/constant.js +8 -1
  51. package/dist/commonjs/constant.js.map +1 -1
  52. package/dist/commonjs/error.d.ts +22 -2
  53. package/dist/commonjs/error.d.ts.map +1 -1
  54. package/dist/commonjs/error.js +44 -4
  55. package/dist/commonjs/error.js.map +1 -1
  56. package/dist/commonjs/expect.d.ts.map +1 -1
  57. package/dist/commonjs/expect.js +1 -1
  58. package/dist/commonjs/expect.js.map +1 -1
  59. package/dist/commonjs/guards.d.ts +96 -5
  60. package/dist/commonjs/guards.d.ts.map +1 -1
  61. package/dist/commonjs/guards.js +104 -25
  62. package/dist/commonjs/guards.js.map +1 -1
  63. package/dist/commonjs/index.d.ts +146 -51
  64. package/dist/commonjs/index.d.ts.map +1 -1
  65. package/dist/commonjs/index.js.map +1 -1
  66. package/dist/commonjs/schema.d.ts +84 -18
  67. package/dist/commonjs/schema.d.ts.map +1 -1
  68. package/dist/commonjs/schema.js +107 -22
  69. package/dist/commonjs/schema.js.map +1 -1
  70. package/dist/commonjs/types.d.ts +171 -9
  71. package/dist/commonjs/types.d.ts.map +1 -1
  72. package/dist/commonjs/use.d.ts.map +1 -1
  73. package/dist/commonjs/use.js +15 -1
  74. package/dist/commonjs/use.js.map +1 -1
  75. package/dist/commonjs/util.d.ts +66 -50
  76. package/dist/commonjs/util.d.ts.map +1 -1
  77. package/dist/commonjs/util.js +169 -156
  78. package/dist/commonjs/util.js.map +1 -1
  79. package/dist/commonjs/value-to-schema.d.ts +122 -0
  80. package/dist/commonjs/value-to-schema.d.ts.map +1 -0
  81. package/dist/commonjs/value-to-schema.js +329 -0
  82. package/dist/commonjs/value-to-schema.js.map +1 -0
  83. package/dist/esm/assertion/assertion-async.d.ts +2 -1
  84. package/dist/esm/assertion/assertion-async.d.ts.map +1 -1
  85. package/dist/esm/assertion/assertion-async.js +85 -3
  86. package/dist/esm/assertion/assertion-async.js.map +1 -1
  87. package/dist/esm/assertion/assertion-sync.d.ts +1 -1
  88. package/dist/esm/assertion/assertion-sync.d.ts.map +1 -1
  89. package/dist/esm/assertion/assertion-sync.js +6 -2
  90. package/dist/esm/assertion/assertion-sync.js.map +1 -1
  91. package/dist/esm/assertion/assertion-types.d.ts +6 -2
  92. package/dist/esm/assertion/assertion-types.d.ts.map +1 -1
  93. package/dist/esm/assertion/assertion.d.ts +1 -1
  94. package/dist/esm/assertion/assertion.d.ts.map +1 -1
  95. package/dist/esm/assertion/assertion.js +1 -14
  96. package/dist/esm/assertion/assertion.js.map +1 -1
  97. package/dist/esm/assertion/impl/async.d.ts +122 -21
  98. package/dist/esm/assertion/impl/async.d.ts.map +1 -1
  99. package/dist/esm/assertion/impl/async.js +118 -90
  100. package/dist/esm/assertion/impl/async.js.map +1 -1
  101. package/dist/esm/assertion/impl/callback.d.ts +104 -0
  102. package/dist/esm/assertion/impl/callback.d.ts.map +1 -0
  103. package/dist/esm/assertion/impl/callback.js +691 -0
  104. package/dist/esm/assertion/impl/callback.js.map +1 -0
  105. package/dist/esm/assertion/impl/index.d.ts +1 -1
  106. package/dist/esm/assertion/impl/index.d.ts.map +1 -1
  107. package/dist/esm/assertion/impl/index.js +1 -1
  108. package/dist/esm/assertion/impl/index.js.map +1 -1
  109. package/dist/esm/assertion/impl/sync-basic.d.ts.map +1 -1
  110. package/dist/esm/assertion/impl/sync-basic.js +2 -2
  111. package/dist/esm/assertion/impl/sync-basic.js.map +1 -1
  112. package/dist/esm/assertion/impl/sync-collection.d.ts +1 -1
  113. package/dist/esm/assertion/impl/sync-collection.js +3 -3
  114. package/dist/esm/assertion/impl/sync-collection.js.map +1 -1
  115. package/dist/esm/assertion/impl/sync-esoteric.js +2 -2
  116. package/dist/esm/assertion/impl/sync-esoteric.js.map +1 -1
  117. package/dist/esm/assertion/impl/sync-parametric.d.ts +22 -28
  118. package/dist/esm/assertion/impl/sync-parametric.d.ts.map +1 -1
  119. package/dist/esm/assertion/impl/sync-parametric.js +36 -51
  120. package/dist/esm/assertion/impl/sync-parametric.js.map +1 -1
  121. package/dist/esm/assertion/impl/sync.d.ts +68 -30
  122. package/dist/esm/assertion/impl/sync.d.ts.map +1 -1
  123. package/dist/esm/assertion/impl/sync.js +3 -1
  124. package/dist/esm/assertion/impl/sync.js.map +1 -1
  125. package/dist/esm/bootstrap.d.ts +147 -52
  126. package/dist/esm/bootstrap.d.ts.map +1 -1
  127. package/dist/esm/bootstrap.js +1 -2
  128. package/dist/esm/bootstrap.js.map +1 -1
  129. package/dist/esm/constant.d.ts +1 -1
  130. package/dist/esm/constant.d.ts.map +1 -1
  131. package/dist/esm/constant.js +7 -0
  132. package/dist/esm/constant.js.map +1 -1
  133. package/dist/esm/error.d.ts +22 -2
  134. package/dist/esm/error.d.ts.map +1 -1
  135. package/dist/esm/error.js +43 -4
  136. package/dist/esm/error.js.map +1 -1
  137. package/dist/esm/expect.d.ts.map +1 -1
  138. package/dist/esm/expect.js +2 -2
  139. package/dist/esm/expect.js.map +1 -1
  140. package/dist/esm/guards.d.ts +96 -5
  141. package/dist/esm/guards.d.ts.map +1 -1
  142. package/dist/esm/guards.js +98 -21
  143. package/dist/esm/guards.js.map +1 -1
  144. package/dist/esm/index.d.ts +146 -51
  145. package/dist/esm/index.d.ts.map +1 -1
  146. package/dist/esm/index.js.map +1 -1
  147. package/dist/esm/schema.d.ts +84 -18
  148. package/dist/esm/schema.d.ts.map +1 -1
  149. package/dist/esm/schema.js +107 -22
  150. package/dist/esm/schema.js.map +1 -1
  151. package/dist/esm/types.d.ts +171 -9
  152. package/dist/esm/types.d.ts.map +1 -1
  153. package/dist/esm/use.d.ts.map +1 -1
  154. package/dist/esm/use.js +15 -1
  155. package/dist/esm/use.js.map +1 -1
  156. package/dist/esm/util.d.ts +66 -50
  157. package/dist/esm/util.d.ts.map +1 -1
  158. package/dist/esm/util.js +153 -154
  159. package/dist/esm/util.js.map +1 -1
  160. package/dist/esm/value-to-schema.d.ts +122 -0
  161. package/dist/esm/value-to-schema.d.ts.map +1 -0
  162. package/dist/esm/value-to-schema.js +325 -0
  163. package/dist/esm/value-to-schema.js.map +1 -0
  164. package/package.json +16 -13
  165. package/src/assertion/assertion-async.ts +113 -3
  166. package/src/assertion/assertion-sync.ts +5 -2
  167. package/src/assertion/assertion-types.ts +14 -4
  168. package/src/assertion/assertion.ts +2 -17
  169. package/src/assertion/impl/async.ts +137 -93
  170. package/src/assertion/impl/callback.ts +882 -0
  171. package/src/assertion/impl/index.ts +1 -1
  172. package/src/assertion/impl/sync-basic.ts +5 -2
  173. package/src/assertion/impl/sync-collection.ts +3 -3
  174. package/src/assertion/impl/sync-esoteric.ts +2 -2
  175. package/src/assertion/impl/sync-parametric.ts +47 -54
  176. package/src/assertion/impl/sync.ts +3 -0
  177. package/src/bootstrap.ts +1 -2
  178. package/src/constant.ts +10 -0
  179. package/src/error.ts +57 -3
  180. package/src/expect.ts +6 -2
  181. package/src/guards.ts +125 -18
  182. package/src/index.ts +3 -0
  183. package/src/schema.ts +121 -23
  184. package/src/types.ts +205 -10
  185. package/src/use.ts +22 -0
  186. package/src/util.ts +168 -223
  187. package/src/value-to-schema.ts +489 -0
@@ -0,0 +1,694 @@
1
+ "use strict";
2
+ /**
3
+ * Callback-based assertion implementations.
4
+ *
5
+ * For callback invocation, error handling, and value validation in both
6
+ * synchronous and asynchronous contexts.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.CallbackAsyncAssertions = exports.CallbackSyncAssertions = void 0;
12
+ const node_util_1 = require("node:util");
13
+ const v4_1 = require("zod/v4");
14
+ const guards_js_1 = require("../../guards.js");
15
+ const schema_js_1 = require("../../schema.js");
16
+ const value_to_schema_js_1 = require("../../value-to-schema.js");
17
+ const create_js_1 = require("../create.js");
18
+ /**
19
+ * Creates a standardized error object for when a callback or nodeback is not
20
+ * called.
21
+ *
22
+ * @param type - The type of callback ('callback' or 'nodeback')
23
+ * @returns Error object with consistent structure for sync assertions
24
+ */
25
+ /* c8 ignore next */
26
+ const createNotCalledError = (type) => ({
27
+ actual: 'not called',
28
+ expected: `${type} to be called`,
29
+ message: `Expected ${type} to be called, but it was not called`,
30
+ });
31
+ /**
32
+ * Creates a standardized error object for when a callback or nodeback is not
33
+ * called in async contexts. Uses consistent field naming for async assertions.
34
+ *
35
+ * @param type - The type of callback ('callback' or 'nodeback')
36
+ * @returns Error object with consistent structure for async assertions
37
+ */
38
+ /* c8 ignore next */
39
+ const createAsyncNotCalledError = (type) => ({
40
+ actual: `${type} not called`,
41
+ expected: `${type} to be called`,
42
+ message: `Expected ${type} to be called, but it was not`,
43
+ });
44
+ /**
45
+ * Creates error objects for nodeback error state mismatches in sync contexts.
46
+ * Handles cases where an error is expected but not present, or vice versa.
47
+ *
48
+ * @param hasError - Whether the nodeback was called with an error
49
+ * @param expectError - Whether an error was expected
50
+ * @param error - The actual error value (if any)
51
+ * @returns Error object if there's a mismatch, undefined if the state matches
52
+ * expectations
53
+ */
54
+ const createErrorMismatchError = (hasError, expectError, error) => {
55
+ if (hasError && !expectError) {
56
+ return {
57
+ actual: 'called with error',
58
+ expected: 'called without error',
59
+ message: `Expected nodeback to be called without error, but it was called with error: ${(0, node_util_1.inspect)(error, { depth: 2 })}`,
60
+ };
61
+ }
62
+ if (!hasError && expectError) {
63
+ return {
64
+ actual: 'called without error',
65
+ expected: 'called with error',
66
+ message: 'Expected nodeback to be called with an error, but it was called without error',
67
+ };
68
+ }
69
+ return undefined;
70
+ };
71
+ /**
72
+ * Creates error objects for nodeback error state mismatches in async contexts.
73
+ * Handles cases where an error is expected but not present, or vice versa. Uses
74
+ * consistent field naming and messaging for async assertions.
75
+ *
76
+ * @param hasError - Whether the nodeback was called with an error
77
+ * @param expectError - Whether an error was expected
78
+ * @param error - The actual error value (if any)
79
+ * @returns Error object if there's a mismatch, undefined if the state matches
80
+ * expectations
81
+ */
82
+ const createAsyncErrorMismatchError = (hasError, expectError, error) => {
83
+ if (hasError && !expectError) {
84
+ return {
85
+ actual: 'called with error',
86
+ expected: 'called without error',
87
+ message: `Expected nodeback to be called without error, but it was called with error: ${(0, node_util_1.inspect)(error, { depth: 2 })}`,
88
+ };
89
+ }
90
+ if (!hasError && expectError) {
91
+ return {
92
+ actual: 'called without error',
93
+ expected: 'called with error',
94
+ message: 'Expected nodeback to be called with an error, but it was called without an error',
95
+ };
96
+ }
97
+ return undefined;
98
+ };
99
+ /**
100
+ * Creates a standardized error object for exact value comparison failures. Used
101
+ * when a callback/nodeback is called with a value that doesn't match the
102
+ * expected value using Object.is() strict equality.
103
+ *
104
+ * @param actual - The actual value the callback was called with
105
+ * @param expected - The expected value
106
+ * @param callbackType - The type of callback for error messaging
107
+ * @returns Error object with formatted comparison message
108
+ */
109
+ const createValueMismatchError = (actual, expected, callbackType) => ({
110
+ actual,
111
+ expected,
112
+ message: `Expected ${callbackType} to be called with exactly ${(0, node_util_1.inspect)(expected, { depth: 2 })}, but it was called with ${(0, node_util_1.inspect)(actual, { depth: 2 })}`,
113
+ });
114
+ /**
115
+ * Creates a Zod schema for validating error parameters in callback assertions.
116
+ * Handles string literals, RegExp patterns, and object structures for error
117
+ * matching.
118
+ *
119
+ * @param param - The error parameter to create a schema for
120
+ * @returns Zod schema that can validate the error against the parameter
121
+ * @throws TypeError if the parameter type is not supported
122
+ */
123
+ const createErrorSchema = (param) => {
124
+ if ((0, guards_js_1.isString)(param)) {
125
+ return v4_1.z
126
+ .looseObject({
127
+ message: v4_1.z.coerce.string().pipe(v4_1.z.literal(param)),
128
+ })
129
+ .or(v4_1.z.coerce.string().pipe(v4_1.z.literal(param)));
130
+ }
131
+ if ((0, guards_js_1.isA)(param, RegExp)) {
132
+ return v4_1.z
133
+ .looseObject({
134
+ message: v4_1.z.coerce.string().regex(param),
135
+ })
136
+ .or(v4_1.z.coerce.string().regex(param));
137
+ }
138
+ if ((0, guards_js_1.isNonNullObject)(param)) {
139
+ return (0, value_to_schema_js_1.valueToSchema)(param, value_to_schema_js_1.valueToSchemaOptionsForDeepEqual);
140
+ }
141
+ throw new TypeError(`Invalid parameter schema: ${(0, node_util_1.inspect)(param, { depth: 2 })}`);
142
+ };
143
+ /**
144
+ * Validates a value against a parameter using valueToSchema with specified
145
+ * options. Centralizes the common pattern of schema creation and validation
146
+ * used across many callback assertions.
147
+ *
148
+ * @param value - The value to validate
149
+ * @param param - The parameter to validate against
150
+ * @param options - Options to pass to valueToSchema
151
+ * @returns Undefined if validation succeeds, ZodError if validation fails
152
+ */
153
+ const validateValue = (value, param, options = {}) => {
154
+ const schema = (0, value_to_schema_js_1.valueToSchema)(param, options);
155
+ const result = schema.safeParse(value);
156
+ return result.success ? undefined : result.error;
157
+ };
158
+ /**
159
+ * Traps the invocation of a single-parameter callback function for synchronous
160
+ * testing. Executes the provided function with a callback and captures whether
161
+ * it was called, what arguments it received, and any errors thrown during
162
+ * execution.
163
+ *
164
+ * @param fn - The function to execute that should call the provided callback
165
+ * @returns Object containing invocation details: args, called, error, and value
166
+ */
167
+ const trapCallbackInvocation = (fn) => {
168
+ let called = false;
169
+ let error;
170
+ let value;
171
+ let args = [];
172
+ const callback = (...cbArgs) => {
173
+ called = true;
174
+ args = cbArgs;
175
+ if (cbArgs.length >= 1) {
176
+ value = cbArgs[0];
177
+ }
178
+ };
179
+ try {
180
+ fn(callback);
181
+ }
182
+ catch (thrownError) {
183
+ error = thrownError;
184
+ }
185
+ return { args, called, error, value };
186
+ };
187
+ /**
188
+ * Traps the invocation of a nodeback (error-first callback) function for
189
+ * synchronous testing. Executes the provided function with a nodeback and
190
+ * captures whether it was called, what arguments it received, and any errors
191
+ * thrown during execution.
192
+ *
193
+ * @param fn - The function to execute that should call the provided nodeback
194
+ * @returns Object containing invocation details: args, called, error, and value
195
+ */
196
+ const trapNodebackInvocation = (fn) => {
197
+ let called = false;
198
+ let error;
199
+ let value;
200
+ let args = [];
201
+ const nodeback = (err, val) => {
202
+ called = true;
203
+ args = [err, val];
204
+ error = err;
205
+ value = val;
206
+ };
207
+ try {
208
+ fn(nodeback);
209
+ }
210
+ catch (thrownError) {
211
+ error = thrownError;
212
+ }
213
+ return { args, called, error, value };
214
+ };
215
+ /**
216
+ * Traps the invocation of a single-parameter callback function for asynchronous
217
+ * testing. Returns a Promise that resolves with invocation details once the
218
+ * callback is called or an error occurs. Uses a Proxy to catch errors during
219
+ * function execution.
220
+ *
221
+ * @param fn - The function to execute that should call the provided callback
222
+ * @returns Promise resolving to object with invocation details: args, called,
223
+ * error, and value
224
+ */
225
+ const trapAsyncCallbackInvocation = async (fn) => {
226
+ return new Promise((resolve, _reject) => {
227
+ let called = false;
228
+ let error;
229
+ let value;
230
+ let args = [];
231
+ const callback = (...cbArgs) => {
232
+ called = true;
233
+ args = cbArgs;
234
+ if (cbArgs.length >= 1) {
235
+ value = cbArgs[0];
236
+ }
237
+ resolve({ args, called, error, value });
238
+ };
239
+ const proxiedFn = new Proxy(fn, {
240
+ apply(target, thisArg, argumentsList) {
241
+ try {
242
+ return Reflect.apply(target, thisArg, argumentsList);
243
+ }
244
+ catch (thrownError) {
245
+ error = thrownError;
246
+ resolve({ args, called, error, value });
247
+ }
248
+ },
249
+ });
250
+ try {
251
+ proxiedFn(callback);
252
+ }
253
+ catch (thrownError) {
254
+ error = thrownError;
255
+ resolve({ args, called, error, value });
256
+ }
257
+ });
258
+ };
259
+ /**
260
+ * Traps the invocation of a nodeback (error-first callback) function for
261
+ * asynchronous testing. Returns a Promise that resolves with invocation details
262
+ * once the nodeback is called or an error occurs. Uses a Proxy to catch errors
263
+ * during function execution. Always resolves (never rejects) to allow assertion
264
+ * logic to handle error conditions.
265
+ *
266
+ * @param fn - The function to execute that should call the provided nodeback
267
+ * @returns Promise resolving to object with invocation details: args, called,
268
+ * error, and value
269
+ */
270
+ const trapAsyncNodebackInvocation = async (fn) => {
271
+ return new Promise((resolve, _reject) => {
272
+ let called = false;
273
+ let error;
274
+ let value;
275
+ let args = [];
276
+ const nodeback = (err, val) => {
277
+ called = true;
278
+ args = [err, val];
279
+ error = err;
280
+ value = val;
281
+ // Always resolve with the result data, don't reject on nodeback errors
282
+ // The assertion logic will check if error is truthy
283
+ resolve({ args, called, error, value });
284
+ };
285
+ const proxiedFn = new Proxy(fn, {
286
+ apply(target, thisArg, argumentsList) {
287
+ try {
288
+ return Reflect.apply(target, thisArg, argumentsList);
289
+ }
290
+ catch (thrownError) {
291
+ error = thrownError;
292
+ resolve({ args, called, error, value });
293
+ }
294
+ },
295
+ });
296
+ try {
297
+ proxiedFn(nodeback);
298
+ }
299
+ catch (thrownError) {
300
+ error = thrownError;
301
+ resolve({ args, called, error, value });
302
+ }
303
+ });
304
+ };
305
+ exports.CallbackSyncAssertions = [
306
+ // Basic callback invocation - synchronous
307
+ (0, create_js_1.createAssertion)([schema_js_1.FunctionSchema, ['to call callback', 'to invoke callback']], (subject) => {
308
+ const { called } = trapCallbackInvocation(subject);
309
+ return called;
310
+ }),
311
+ (0, create_js_1.createAssertion)([schema_js_1.FunctionSchema, ['to call nodeback', 'to invoke nodeback']], (subject) => {
312
+ const { called } = trapNodebackInvocation(subject);
313
+ return called;
314
+ }),
315
+ // Callback with value - deep equality check
316
+ (0, create_js_1.createAssertion)([
317
+ schema_js_1.FunctionSchema,
318
+ ['to call callback with', 'to invoke callback with'],
319
+ v4_1.z.unknown(),
320
+ ], (subject, param) => {
321
+ const { called, value } = trapCallbackInvocation(subject);
322
+ /* c8 ignore next */
323
+ if (!called) {
324
+ return createNotCalledError('callback');
325
+ }
326
+ return validateValue(value, param, value_to_schema_js_1.valueToSchemaOptionsForDeepEqual);
327
+ }),
328
+ // Callback with exact value - strict equality check
329
+ (0, create_js_1.createAssertion)([
330
+ schema_js_1.FunctionSchema,
331
+ [
332
+ 'to call callback with exactly',
333
+ 'to call callback with exact value',
334
+ 'to invoke callback with exactly',
335
+ 'to invoke callback with exact value',
336
+ ],
337
+ v4_1.z.unknown(),
338
+ ], (subject, expected) => {
339
+ const { called, value } = trapCallbackInvocation(subject);
340
+ /* c8 ignore next */
341
+ if (!called) {
342
+ return createNotCalledError('callback');
343
+ }
344
+ if (!Object.is(value, expected)) {
345
+ return createValueMismatchError(value, expected, 'callback');
346
+ }
347
+ }),
348
+ // Nodeback with value - deep equality check
349
+ (0, create_js_1.createAssertion)([
350
+ schema_js_1.FunctionSchema,
351
+ ['to call nodeback with', 'to invoke nodeback with'],
352
+ v4_1.z.unknown(),
353
+ ], (subject, param) => {
354
+ const { called, error, value } = trapNodebackInvocation(subject);
355
+ /* c8 ignore next */
356
+ if (!called) {
357
+ return createNotCalledError('nodeback');
358
+ }
359
+ const errorResult = createErrorMismatchError(!!error, false, error);
360
+ if (errorResult) {
361
+ return errorResult;
362
+ }
363
+ return validateValue(value, param, value_to_schema_js_1.valueToSchemaOptionsForDeepEqual);
364
+ }),
365
+ // Nodeback with exact value - strict equality check
366
+ (0, create_js_1.createAssertion)([
367
+ schema_js_1.FunctionSchema,
368
+ [
369
+ 'to call nodeback with exactly',
370
+ 'to call nodeback with exact value',
371
+ 'to invoke nodeback with exactly',
372
+ 'to invoke nodeback with exact value',
373
+ ],
374
+ v4_1.z.unknown(),
375
+ ], (subject, expected) => {
376
+ const { called, error, value } = trapNodebackInvocation(subject);
377
+ /* c8 ignore next */
378
+ if (!called) {
379
+ return createNotCalledError('nodeback');
380
+ }
381
+ const errorResult = createErrorMismatchError(!!error, false, error);
382
+ if (errorResult) {
383
+ return errorResult;
384
+ }
385
+ if (!Object.is(value, expected)) {
386
+ return createValueMismatchError(value, expected, 'nodeback');
387
+ }
388
+ }),
389
+ // Nodeback with error - synchronous
390
+ (0, create_js_1.createAssertion)([
391
+ schema_js_1.FunctionSchema,
392
+ ['to call nodeback with error', 'to invoke nodeback with error'],
393
+ ], (subject) => {
394
+ const { called, error } = trapNodebackInvocation(subject);
395
+ /* c8 ignore next */
396
+ if (!called) {
397
+ return createNotCalledError('nodeback');
398
+ }
399
+ return createErrorMismatchError(!!error, true, error);
400
+ }),
401
+ // Nodeback with specific error class - synchronous
402
+ (0, create_js_1.createAssertion)([
403
+ schema_js_1.FunctionSchema,
404
+ [
405
+ 'to call nodeback with a',
406
+ 'to call nodeback with an',
407
+ 'to invoke nodeback with a',
408
+ 'to invoke nodeback with an',
409
+ ],
410
+ schema_js_1.ConstructibleSchema,
411
+ ], (subject, ctor) => {
412
+ const { called, error } = trapNodebackInvocation(subject);
413
+ /* c8 ignore next */
414
+ if (!called) {
415
+ return createNotCalledError('nodeback');
416
+ }
417
+ const errorResult = createErrorMismatchError(!!error, true, error);
418
+ if (errorResult) {
419
+ return errorResult;
420
+ }
421
+ if (!(0, guards_js_1.isA)(error, ctor)) {
422
+ return {
423
+ actual: error,
424
+ expected: `instance of ${ctor.name}`,
425
+ message: `Expected nodeback to be called with an instance of ${ctor.name}, but it was called with ${(0, node_util_1.inspect)(error, { depth: 2 })}`,
426
+ };
427
+ }
428
+ }),
429
+ // Nodeback with specific error pattern - synchronous
430
+ (0, create_js_1.createAssertion)([
431
+ schema_js_1.FunctionSchema,
432
+ ['to call nodeback with error', 'to invoke nodeback with error'],
433
+ v4_1.z.union([v4_1.z.string(), v4_1.z.instanceof(RegExp), v4_1.z.looseObject({})]),
434
+ ], (subject, param) => {
435
+ const { called, error } = trapNodebackInvocation(subject);
436
+ /* c8 ignore next */
437
+ if (!called) {
438
+ return createNotCalledError('nodeback');
439
+ }
440
+ const errorResult = createErrorMismatchError(!!error, true, error);
441
+ if (errorResult) {
442
+ return errorResult;
443
+ }
444
+ const schema = createErrorSchema(param);
445
+ const result = schema.safeParse(error);
446
+ if (!result.success) {
447
+ return result.error;
448
+ }
449
+ }),
450
+ // Callback satisfying pattern - partial matching
451
+ (0, create_js_1.createAssertion)([
452
+ schema_js_1.FunctionSchema,
453
+ [
454
+ 'to call callback with value satisfying',
455
+ 'to invoke callback with value satisfying',
456
+ ],
457
+ v4_1.z.union([v4_1.z.string(), v4_1.z.instanceof(RegExp), v4_1.z.looseObject({})]),
458
+ ], (subject, param) => {
459
+ const { called, value } = trapCallbackInvocation(subject);
460
+ /* c8 ignore next */
461
+ if (!called) {
462
+ return createNotCalledError('callback');
463
+ }
464
+ return validateValue(value, param, value_to_schema_js_1.valueToSchemaOptionsForSatisfies);
465
+ }),
466
+ // Nodeback satisfying pattern - partial matching
467
+ (0, create_js_1.createAssertion)([
468
+ schema_js_1.FunctionSchema,
469
+ [
470
+ 'to call nodeback with value satisfying',
471
+ 'to invoke nodeback with value satisfying',
472
+ ],
473
+ v4_1.z.union([v4_1.z.string(), v4_1.z.instanceof(RegExp), v4_1.z.looseObject({})]),
474
+ ], (subject, param) => {
475
+ const { called, error, value } = trapNodebackInvocation(subject);
476
+ /* c8 ignore next */
477
+ if (!called) {
478
+ return createNotCalledError('nodeback');
479
+ }
480
+ const errorResult = createErrorMismatchError(!!error, false, error);
481
+ if (errorResult) {
482
+ return errorResult;
483
+ }
484
+ return validateValue(value, param, value_to_schema_js_1.valueToSchemaOptionsForSatisfies);
485
+ }),
486
+ ];
487
+ exports.CallbackAsyncAssertions = [
488
+ // Async versions
489
+ (0, create_js_1.createAsyncAssertion)([
490
+ schema_js_1.FunctionSchema,
491
+ ['to eventually call callback', 'to eventually invoke callback'],
492
+ ], async (subject) => {
493
+ const { called } = await trapAsyncCallbackInvocation(subject);
494
+ /* c8 ignore next */
495
+ if (!called) {
496
+ return {
497
+ actual: 'callback not called',
498
+ expected: 'callback to be called',
499
+ message: `Expected callback to be called, but it was not`,
500
+ };
501
+ }
502
+ }),
503
+ (0, create_js_1.createAsyncAssertion)([
504
+ schema_js_1.FunctionSchema,
505
+ ['to eventually call nodeback', 'to eventually invoke nodeback'],
506
+ ], async (subject) => {
507
+ const { called } = await trapAsyncNodebackInvocation(subject);
508
+ /* c8 ignore next */
509
+ if (!called) {
510
+ return {
511
+ actual: 'nodeback not called',
512
+ expected: 'nodeback to be called',
513
+ message: `Expected nodeback to be called, but it was not`,
514
+ };
515
+ }
516
+ }),
517
+ // Async callback with value - deep equality check
518
+ (0, create_js_1.createAsyncAssertion)([
519
+ schema_js_1.FunctionSchema,
520
+ [
521
+ 'to eventually call callback with',
522
+ 'to eventually invoke callback with',
523
+ ],
524
+ v4_1.z.unknown(),
525
+ ], async (subject, param) => {
526
+ const { called, value } = await trapAsyncCallbackInvocation(subject);
527
+ /* c8 ignore next */
528
+ if (!called) {
529
+ return createAsyncNotCalledError('callback');
530
+ }
531
+ return validateValue(value, param, value_to_schema_js_1.valueToSchemaOptionsForDeepEqual);
532
+ }),
533
+ // Async callback with exact value - strict equality check
534
+ (0, create_js_1.createAsyncAssertion)([
535
+ schema_js_1.FunctionSchema,
536
+ [
537
+ 'to eventually call callback with exactly',
538
+ 'to eventually call callback with exact value',
539
+ 'to eventually invoke callback with exactly',
540
+ 'to eventually invoke callback with exact value',
541
+ ],
542
+ v4_1.z.unknown(),
543
+ ], async (subject, expected) => {
544
+ const { called, value } = await trapAsyncCallbackInvocation(subject);
545
+ /* c8 ignore next */
546
+ if (!called) {
547
+ return createAsyncNotCalledError('callback');
548
+ }
549
+ return Object.is(value, expected);
550
+ }),
551
+ // Async nodeback with value - deep equality check
552
+ (0, create_js_1.createAsyncAssertion)([
553
+ schema_js_1.FunctionSchema,
554
+ [
555
+ 'to eventually call nodeback with',
556
+ 'to eventually invoke nodeback with',
557
+ ],
558
+ v4_1.z.unknown(),
559
+ ], async (subject, param) => {
560
+ const { called, error, value } = await trapAsyncNodebackInvocation(subject);
561
+ /* c8 ignore next */
562
+ if (!called) {
563
+ return createAsyncNotCalledError('nodeback');
564
+ }
565
+ const errorResult = createAsyncErrorMismatchError(!!error, false, error);
566
+ if (errorResult) {
567
+ return errorResult;
568
+ }
569
+ return validateValue(value, param, value_to_schema_js_1.valueToSchemaOptionsForDeepEqual);
570
+ }),
571
+ // Async nodeback with exact value - strict equality check
572
+ (0, create_js_1.createAsyncAssertion)([
573
+ schema_js_1.FunctionSchema,
574
+ [
575
+ 'to eventually call nodeback with exactly',
576
+ 'to eventually call nodeback with exact value',
577
+ 'to eventually invoke nodeback with exactly',
578
+ 'to eventually invoke nodeback with exact value',
579
+ ],
580
+ v4_1.z.unknown(),
581
+ ], async (subject, expected) => {
582
+ const { called, error, value } = await trapAsyncNodebackInvocation(subject);
583
+ /* c8 ignore next */
584
+ if (!called) {
585
+ return createAsyncNotCalledError('nodeback');
586
+ }
587
+ const errorResult = createAsyncErrorMismatchError(!!error, false, error);
588
+ if (errorResult) {
589
+ return errorResult;
590
+ }
591
+ return Object.is(value, expected);
592
+ }),
593
+ (0, create_js_1.createAsyncAssertion)([
594
+ schema_js_1.FunctionSchema,
595
+ [
596
+ 'to eventually call nodeback with error',
597
+ 'to eventually invoke nodeback with error',
598
+ ],
599
+ ], async (subject) => {
600
+ const { called, error } = await trapAsyncNodebackInvocation(subject);
601
+ /* c8 ignore next */
602
+ if (!called) {
603
+ return createAsyncNotCalledError('nodeback');
604
+ }
605
+ return createAsyncErrorMismatchError(!!error, true, error);
606
+ }),
607
+ (0, create_js_1.createAsyncAssertion)([
608
+ schema_js_1.FunctionSchema,
609
+ [
610
+ 'to eventually call nodeback with a',
611
+ 'to eventually call nodeback with an',
612
+ 'to eventually invoke nodeback with a',
613
+ 'to eventually invoke nodeback with an',
614
+ ],
615
+ schema_js_1.ConstructibleSchema,
616
+ ], async (subject, ctor) => {
617
+ const { called, error } = await trapAsyncNodebackInvocation(subject);
618
+ /* c8 ignore next */
619
+ if (!called) {
620
+ return createAsyncNotCalledError('nodeback');
621
+ }
622
+ const errorResult = createAsyncErrorMismatchError(!!error, true, error);
623
+ if (errorResult) {
624
+ return errorResult;
625
+ }
626
+ if (!(0, guards_js_1.isA)(error, ctor)) {
627
+ return {
628
+ actual: error,
629
+ expected: `instance of ${ctor.name}`,
630
+ message: `Expected nodeback to be called with an instance of ${ctor.name}, but it was called with ${(0, node_util_1.inspect)(error, { depth: 2 })}`,
631
+ };
632
+ }
633
+ }),
634
+ (0, create_js_1.createAsyncAssertion)([
635
+ schema_js_1.FunctionSchema,
636
+ [
637
+ 'to eventually call nodeback with error',
638
+ 'to eventually invoke nodeback with error',
639
+ ],
640
+ v4_1.z.union([v4_1.z.string(), v4_1.z.instanceof(RegExp), v4_1.z.looseObject({})]),
641
+ ], async (subject, param) => {
642
+ const { called, error } = await trapAsyncNodebackInvocation(subject);
643
+ /* c8 ignore next */
644
+ if (!called) {
645
+ return createAsyncNotCalledError('nodeback');
646
+ }
647
+ const errorResult = createAsyncErrorMismatchError(!!error, true, error);
648
+ if (errorResult) {
649
+ return errorResult;
650
+ }
651
+ const schema = createErrorSchema(param);
652
+ const result = schema.safeParse(error);
653
+ if (!result.success) {
654
+ return result.error;
655
+ }
656
+ }),
657
+ // Async callback satisfying pattern - partial matching
658
+ (0, create_js_1.createAsyncAssertion)([
659
+ schema_js_1.FunctionSchema,
660
+ [
661
+ 'to eventually call callback with value satisfying',
662
+ 'to eventually invoke callback with value satisfying',
663
+ ],
664
+ v4_1.z.union([v4_1.z.string(), v4_1.z.instanceof(RegExp), v4_1.z.looseObject({})]),
665
+ ], async (subject, param) => {
666
+ const { called, value } = await trapAsyncCallbackInvocation(subject);
667
+ /* c8 ignore next */
668
+ if (!called) {
669
+ return createAsyncNotCalledError('callback');
670
+ }
671
+ return validateValue(value, param, value_to_schema_js_1.valueToSchemaOptionsForSatisfies);
672
+ }),
673
+ // Async nodeback satisfying pattern - partial matching
674
+ (0, create_js_1.createAsyncAssertion)([
675
+ schema_js_1.FunctionSchema,
676
+ [
677
+ 'to eventually call nodeback with value satisfying',
678
+ 'to eventually invoke nodeback with value satisfying',
679
+ ],
680
+ v4_1.z.union([v4_1.z.string(), v4_1.z.instanceof(RegExp), v4_1.z.looseObject({})]),
681
+ ], async (subject, param) => {
682
+ const { called, error, value } = await trapAsyncNodebackInvocation(subject);
683
+ /* c8 ignore next */
684
+ if (!called) {
685
+ return createAsyncNotCalledError('nodeback');
686
+ }
687
+ const errorResult = createAsyncErrorMismatchError(!!error, false, error);
688
+ if (errorResult) {
689
+ return errorResult;
690
+ }
691
+ return validateValue(value, param, value_to_schema_js_1.valueToSchemaOptionsForSatisfies);
692
+ }),
693
+ ];
694
+ //# sourceMappingURL=callback.js.map