@dereekb/util 13.0.0 → 13.0.2

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/test/index.esm.js CHANGED
@@ -1,36 +1,249 @@
1
1
  import { promiseReference, forwardFunction, mapObjectMap, isPromise, build } from '@dereekb/util';
2
+ import { BaseError } from 'make-error';
2
3
 
4
+ function _assert_this_initialized$4(self) {
5
+ if (self === void 0) {
6
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
7
+ }
8
+ return self;
9
+ }
10
+ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
11
+ try {
12
+ var info = gen[key](arg);
13
+ var value = info.value;
14
+ } catch (error) {
15
+ reject(error);
16
+ return;
17
+ }
18
+ if (info.done) {
19
+ resolve(value);
20
+ } else {
21
+ Promise.resolve(value).then(_next, _throw);
22
+ }
23
+ }
24
+ function _async_to_generator$2(fn) {
25
+ return function() {
26
+ var self = this, args = arguments;
27
+ return new Promise(function(resolve, reject) {
28
+ var gen = fn.apply(self, args);
29
+ function _next(value) {
30
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
31
+ }
32
+ function _throw(err) {
33
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
34
+ }
35
+ _next(undefined);
36
+ });
37
+ };
38
+ }
39
+ function _call_super$4(_this, derived, args) {
40
+ derived = _get_prototype_of$4(derived);
41
+ return _possible_constructor_return$4(_this, _is_native_reflect_construct$4() ? Reflect.construct(derived, [], _get_prototype_of$4(_this).constructor) : derived.apply(_this, args));
42
+ }
43
+ function _class_call_check$4(instance, Constructor) {
44
+ if (!(instance instanceof Constructor)) {
45
+ throw new TypeError("Cannot call a class as a function");
46
+ }
47
+ }
48
+ function _defineProperties(target, props) {
49
+ for(var i = 0; i < props.length; i++){
50
+ var descriptor = props[i];
51
+ descriptor.enumerable = descriptor.enumerable || false;
52
+ descriptor.configurable = true;
53
+ if ("value" in descriptor) descriptor.writable = true;
54
+ Object.defineProperty(target, descriptor.key, descriptor);
55
+ }
56
+ }
57
+ function _create_class(Constructor, protoProps, staticProps) {
58
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
59
+ return Constructor;
60
+ }
61
+ function _define_property$2(obj, key, value) {
62
+ if (key in obj) {
63
+ Object.defineProperty(obj, key, {
64
+ value: value,
65
+ enumerable: true,
66
+ configurable: true,
67
+ writable: true
68
+ });
69
+ } else {
70
+ obj[key] = value;
71
+ }
72
+ return obj;
73
+ }
74
+ function _get_prototype_of$4(o) {
75
+ _get_prototype_of$4 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
76
+ return o.__proto__ || Object.getPrototypeOf(o);
77
+ };
78
+ return _get_prototype_of$4(o);
79
+ }
80
+ function _inherits$4(subClass, superClass) {
81
+ if (typeof superClass !== "function" && superClass !== null) {
82
+ throw new TypeError("Super expression must either be null or a function");
83
+ }
84
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
85
+ constructor: {
86
+ value: subClass,
87
+ writable: true,
88
+ configurable: true
89
+ }
90
+ });
91
+ if (superClass) _set_prototype_of$4(subClass, superClass);
92
+ }
93
+ function _possible_constructor_return$4(self, call) {
94
+ if (call && (_type_of$4(call) === "object" || typeof call === "function")) {
95
+ return call;
96
+ }
97
+ return _assert_this_initialized$4(self);
98
+ }
99
+ function _set_prototype_of$4(o, p) {
100
+ _set_prototype_of$4 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
101
+ o.__proto__ = p;
102
+ return o;
103
+ };
104
+ return _set_prototype_of$4(o, p);
105
+ }
106
+ function _type_of$4(obj) {
107
+ "@swc/helpers - typeof";
108
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
109
+ }
110
+ function _is_native_reflect_construct$4() {
111
+ try {
112
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
113
+ } catch (_) {}
114
+ return (_is_native_reflect_construct$4 = function() {
115
+ return !!result;
116
+ })();
117
+ }
118
+ function _ts_generator$2(thisArg, body) {
119
+ var f, y, t, _ = {
120
+ label: 0,
121
+ sent: function() {
122
+ if (t[0] & 1) throw t[1];
123
+ return t[1];
124
+ },
125
+ trys: [],
126
+ ops: []
127
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
128
+ return d(g, "next", {
129
+ value: verb(0)
130
+ }), d(g, "throw", {
131
+ value: verb(1)
132
+ }), d(g, "return", {
133
+ value: verb(2)
134
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
135
+ value: function() {
136
+ return this;
137
+ }
138
+ }), g;
139
+ function verb(n) {
140
+ return function(v) {
141
+ return step([
142
+ n,
143
+ v
144
+ ]);
145
+ };
146
+ }
147
+ function step(op) {
148
+ if (f) throw new TypeError("Generator is already executing.");
149
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
150
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
151
+ if (y = 0, t) op = [
152
+ op[0] & 2,
153
+ t.value
154
+ ];
155
+ switch(op[0]){
156
+ case 0:
157
+ case 1:
158
+ t = op;
159
+ break;
160
+ case 4:
161
+ _.label++;
162
+ return {
163
+ value: op[1],
164
+ done: false
165
+ };
166
+ case 5:
167
+ _.label++;
168
+ y = op[1];
169
+ op = [
170
+ 0
171
+ ];
172
+ continue;
173
+ case 7:
174
+ op = _.ops.pop();
175
+ _.trys.pop();
176
+ continue;
177
+ default:
178
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
179
+ _ = 0;
180
+ continue;
181
+ }
182
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
183
+ _.label = op[1];
184
+ break;
185
+ }
186
+ if (op[0] === 6 && _.label < t[1]) {
187
+ _.label = t[1];
188
+ t = op;
189
+ break;
190
+ }
191
+ if (t && _.label < t[2]) {
192
+ _.label = t[2];
193
+ _.ops.push(op);
194
+ break;
195
+ }
196
+ if (t[2]) _.ops.pop();
197
+ _.trys.pop();
198
+ continue;
199
+ }
200
+ op = body.call(thisArg, _);
201
+ } catch (e) {
202
+ op = [
203
+ 6,
204
+ e
205
+ ];
206
+ y = 0;
207
+ } finally{
208
+ f = t = 0;
209
+ }
210
+ if (op[0] & 5) throw op[1];
211
+ return {
212
+ value: op[0] ? op[1] : void 0,
213
+ done: true
214
+ };
215
+ }
216
+ }
3
217
  /**
4
218
  * Passes the error to the TestDoneCallback.
5
219
  * @param done
6
220
  * @param e
7
- */
8
- function failWithTestDoneCallback(done, e = new Error('failed test')) {
9
- if (done.fail != null) {
10
- done.fail(e);
11
- } else {
12
- done(e);
13
- }
221
+ */ function failWithTestDoneCallback(done) {
222
+ var e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : new Error('failed test');
223
+ if (done.fail != null) {
224
+ done.fail(e);
225
+ } else {
226
+ done(e);
227
+ }
14
228
  }
15
229
  /**
16
230
  * Creates a new TestDoneCallbackRef.
17
231
  *
18
232
  * Used to create a promise reference that can be used to assert that a test function was called.
19
- */
20
- function testDoneCallbackRef() {
21
- const _promise = promiseReference();
22
- const done = e => {
23
- if (e) {
24
- _promise.reject(e);
25
- } else {
26
- _promise.resolve();
27
- }
28
- };
29
- done.fail = done;
30
- return {
31
- _promise,
32
- done
33
- };
233
+ */ function testDoneCallbackRef() {
234
+ var _promise = promiseReference();
235
+ var done = function done(e) {
236
+ if (e) {
237
+ _promise.reject(e);
238
+ } else {
239
+ _promise.resolve();
240
+ }
241
+ };
242
+ done.fail = done;
243
+ return {
244
+ _promise: _promise,
245
+ done: done
246
+ };
34
247
  }
35
248
  /**
36
249
  * Wraps a callback-based test (using done) for Vitest compatibility.
@@ -51,403 +264,822 @@ function testDoneCallbackRef() {
51
264
  * // async test code
52
265
  * done();
53
266
  * }));
54
- */
55
- function callbackTest(testFn) {
56
- return async () => {
57
- const done = testDoneCallbackRef();
58
- await testFn(done.done);
59
- return done._promise.promise;
60
- };
267
+ */ function callbackTest(testFn) {
268
+ return function() {
269
+ return _async_to_generator$2(function() {
270
+ var done;
271
+ return _ts_generator$2(this, function(_state) {
272
+ switch(_state.label){
273
+ case 0:
274
+ done = testDoneCallbackRef();
275
+ return [
276
+ 4,
277
+ testFn(done.done)
278
+ ];
279
+ case 1:
280
+ _state.sent();
281
+ return [
282
+ 2,
283
+ done._promise.promise
284
+ ];
285
+ }
286
+ });
287
+ })();
288
+ };
61
289
  }
62
290
  /**
63
291
  * Abstract TestContextFixture instance.
64
- */
65
- class AbstractTestContextFixture {
66
- constructor() {
67
- this._instance = void 0;
68
- }
69
- get instance() {
70
- return this._instance;
71
- }
72
- setInstance(instance) {
73
- if (this._instance != null) {
74
- throw new Error(`The testing fixture is locked. Don't call setInstance() directly.`);
75
- }
76
- this._instance = instance;
77
- return () => {
78
- delete this._instance;
79
- };
80
- }
81
- }
292
+ */ var AbstractTestContextFixture = /*#__PURE__*/ function() {
293
+ function AbstractTestContextFixture() {
294
+ _class_call_check$4(this, AbstractTestContextFixture);
295
+ _define_property$2(this, "_instance", void 0);
296
+ }
297
+ _create_class(AbstractTestContextFixture, [
298
+ {
299
+ key: "instance",
300
+ get: function get() {
301
+ return this._instance;
302
+ }
303
+ },
304
+ {
305
+ key: "setInstance",
306
+ value: function setInstance(instance) {
307
+ var _this = this;
308
+ if (this._instance != null) {
309
+ throw new Error("The testing fixture is locked. Don't call setInstance() directly.");
310
+ }
311
+ this._instance = instance;
312
+ return function() {
313
+ delete _this._instance;
314
+ };
315
+ }
316
+ }
317
+ ]);
318
+ return AbstractTestContextFixture;
319
+ }();
82
320
  /**
83
321
  * Abstract TestContextFixture instance with a parent.
84
- */
85
- class AbstractChildTestContextFixture extends AbstractTestContextFixture {
86
- constructor(parent) {
87
- super();
88
- this.parent = void 0;
89
- this.parent = parent;
90
- }
91
- }
322
+ */ var AbstractChildTestContextFixture = /*#__PURE__*/ function(AbstractTestContextFixture) {
323
+ _inherits$4(AbstractChildTestContextFixture, AbstractTestContextFixture);
324
+ function AbstractChildTestContextFixture(parent) {
325
+ _class_call_check$4(this, AbstractChildTestContextFixture);
326
+ var _this;
327
+ _this = _call_super$4(this, AbstractChildTestContextFixture), _define_property$2(_this, "parent", void 0);
328
+ _this.parent = parent;
329
+ return _this;
330
+ }
331
+ return AbstractChildTestContextFixture;
332
+ }(AbstractTestContextFixture);
92
333
  /**
93
334
  * Creates a TestContextBuilderFunction given the input builder.
94
335
  *
95
336
  * @param builder
96
337
  * @returns
97
- */
98
- function testContextBuilder(builder) {
99
- return inputConfig => {
100
- const config = builder.buildConfig(inputConfig);
101
- return buildTests => {
102
- const fixture = builder.buildFixture(config);
103
- // add before each
104
- if (builder.beforeEach != null) {
105
- beforeEach(builder.beforeEach);
106
- }
107
- // add tests
108
- useTestContextFixture({
109
- fixture,
110
- /**
111
- * Build tests by passing the fixture to the testing functions.
112
- *
113
- * This will inject all tests and sub lifecycle items.
114
- */
115
- buildTests,
116
- initInstance: () => builder.setupInstance(config),
117
- destroyInstance: instance => builder.teardownInstance(instance, config)
118
- });
119
- // add after each
120
- if (builder.afterEach != null) {
121
- afterEach(builder.afterEach);
122
- }
338
+ */ function testContextBuilder(builder) {
339
+ return function(inputConfig) {
340
+ var config = builder.buildConfig(inputConfig);
341
+ return function(buildTests) {
342
+ var fixture = builder.buildFixture(config);
343
+ // add before each
344
+ if (builder.beforeEach != null) {
345
+ beforeEach(builder.beforeEach);
346
+ }
347
+ // add tests
348
+ useTestContextFixture({
349
+ fixture: fixture,
350
+ /**
351
+ * Build tests by passing the fixture to the testing functions.
352
+ *
353
+ * This will inject all tests and sub lifecycle items.
354
+ */ buildTests: buildTests,
355
+ initInstance: function initInstance() {
356
+ return builder.setupInstance(config);
357
+ },
358
+ destroyInstance: function destroyInstance(instance) {
359
+ return builder.teardownInstance(instance, config);
360
+ }
361
+ });
362
+ // add after each
363
+ if (builder.afterEach != null) {
364
+ afterEach(builder.afterEach);
365
+ }
366
+ };
123
367
  };
124
- };
125
368
  }
126
369
  /**
127
370
  * Creates a test context and configurations that will initialize an instance
128
- */
129
- function useTestContextFixture(config) {
130
- const {
131
- buildTests,
132
- fixture,
133
- initInstance,
134
- destroyInstance
135
- } = config;
136
- let clearInstance;
137
- let instance;
138
- // Create an instance
139
- beforeEach(async () => {
371
+ */ function useTestContextFixture(config) {
372
+ var buildTests = config.buildTests, fixture = config.fixture, initInstance = config.initInstance, destroyInstance = config.destroyInstance;
373
+ var clearInstance;
374
+ var instance;
375
+ // Create an instance
376
+ beforeEach(function() {
377
+ return _async_to_generator$2(function() {
378
+ var e;
379
+ return _ts_generator$2(this, function(_state) {
380
+ switch(_state.label){
381
+ case 0:
382
+ _state.trys.push([
383
+ 0,
384
+ 2,
385
+ ,
386
+ 3
387
+ ]);
388
+ return [
389
+ 4,
390
+ initInstance()
391
+ ];
392
+ case 1:
393
+ instance = _state.sent();
394
+ clearInstance = fixture.setInstance(instance);
395
+ return [
396
+ 3,
397
+ 3
398
+ ];
399
+ case 2:
400
+ e = _state.sent();
401
+ console.error('Failed building a test instance due to an error in buildInstance(). Error: ', e);
402
+ if (clearInstance) {
403
+ clearInstance();
404
+ }
405
+ throw e;
406
+ case 3:
407
+ return [
408
+ 2
409
+ ];
410
+ }
411
+ });
412
+ })();
413
+ });
414
+ // Declare tests
415
+ buildTests(fixture);
416
+ // Cleanup
417
+ afterEach(function() {
418
+ return _async_to_generator$2(function() {
419
+ var e;
420
+ return _ts_generator$2(this, function(_state) {
421
+ switch(_state.label){
422
+ case 0:
423
+ if (clearInstance) {
424
+ clearInstance();
425
+ }
426
+ if (fixture.instance != null) {
427
+ console.warn('Expected instance to be set on fixture for cleanup but was set to something else.');
428
+ }
429
+ if (!destroyInstance) return [
430
+ 3,
431
+ 4
432
+ ];
433
+ _state.label = 1;
434
+ case 1:
435
+ _state.trys.push([
436
+ 1,
437
+ 3,
438
+ ,
439
+ 4
440
+ ]);
441
+ return [
442
+ 4,
443
+ destroyInstance(instance)
444
+ ];
445
+ case 2:
446
+ _state.sent();
447
+ instance = undefined;
448
+ return [
449
+ 3,
450
+ 4
451
+ ];
452
+ case 3:
453
+ e = _state.sent();
454
+ console.error('Failed due to error in destroyInstance()');
455
+ throw e;
456
+ case 4:
457
+ return [
458
+ 2
459
+ ];
460
+ }
461
+ });
462
+ })();
463
+ });
464
+ }
465
+
466
+ function _assert_this_initialized$3(self) {
467
+ if (self === void 0) {
468
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
469
+ }
470
+ return self;
471
+ }
472
+ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
140
473
  try {
141
- instance = await initInstance();
142
- clearInstance = fixture.setInstance(instance);
143
- } catch (e) {
144
- console.error('Failed building a test instance due to an error in buildInstance(). Error: ', e);
145
- if (clearInstance) {
146
- clearInstance();
147
- }
148
- throw e;
149
- }
150
- });
151
- // Declare tests
152
- buildTests(fixture);
153
- // Cleanup
154
- afterEach(async () => {
155
- if (clearInstance) {
156
- clearInstance();
157
- }
158
- if (fixture.instance != null) {
159
- console.warn('Expected instance to be set on fixture for cleanup but was set to something else.');
160
- }
161
- if (destroyInstance) {
162
- try {
163
- await destroyInstance(instance);
164
- instance = undefined;
165
- } catch (e) {
166
- console.error('Failed due to error in destroyInstance()');
167
- throw e;
168
- }
474
+ var info = gen[key](arg);
475
+ var value = info.value;
476
+ } catch (error) {
477
+ reject(error);
478
+ return;
479
+ }
480
+ if (info.done) {
481
+ resolve(value);
482
+ } else {
483
+ Promise.resolve(value).then(_next, _throw);
169
484
  }
170
- });
171
485
  }
172
-
173
- class AbstractWrappedFixture {
174
- constructor(fixture) {
175
- this.fixture = void 0;
176
- this.fixture = fixture;
177
- }
486
+ function _async_to_generator$1(fn) {
487
+ return function() {
488
+ var self = this, args = arguments;
489
+ return new Promise(function(resolve, reject) {
490
+ var gen = fn.apply(self, args);
491
+ function _next(value) {
492
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
493
+ }
494
+ function _throw(err) {
495
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
496
+ }
497
+ _next(undefined);
498
+ });
499
+ };
500
+ }
501
+ function _call_super$3(_this, derived, args) {
502
+ derived = _get_prototype_of$3(derived);
503
+ return _possible_constructor_return$3(_this, _is_native_reflect_construct$3() ? Reflect.construct(derived, [], _get_prototype_of$3(_this).constructor) : derived.apply(_this, args));
504
+ }
505
+ function _class_call_check$3(instance, Constructor) {
506
+ if (!(instance instanceof Constructor)) {
507
+ throw new TypeError("Cannot call a class as a function");
508
+ }
178
509
  }
179
- class AbstractWrappedFixtureWithInstance extends AbstractTestContextFixture {
180
- constructor(parent) {
181
- super();
182
- this.parent = void 0;
183
- this.parent = parent;
184
- }
510
+ function _define_property$1(obj, key, value) {
511
+ if (key in obj) {
512
+ Object.defineProperty(obj, key, {
513
+ value: value,
514
+ enumerable: true,
515
+ configurable: true,
516
+ writable: true
517
+ });
518
+ } else {
519
+ obj[key] = value;
520
+ }
521
+ return obj;
522
+ }
523
+ function _get_prototype_of$3(o) {
524
+ _get_prototype_of$3 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
525
+ return o.__proto__ || Object.getPrototypeOf(o);
526
+ };
527
+ return _get_prototype_of$3(o);
185
528
  }
529
+ function _inherits$3(subClass, superClass) {
530
+ if (typeof superClass !== "function" && superClass !== null) {
531
+ throw new TypeError("Super expression must either be null or a function");
532
+ }
533
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
534
+ constructor: {
535
+ value: subClass,
536
+ writable: true,
537
+ configurable: true
538
+ }
539
+ });
540
+ if (superClass) _set_prototype_of$3(subClass, superClass);
541
+ }
542
+ function _possible_constructor_return$3(self, call) {
543
+ if (call && (_type_of$3(call) === "object" || typeof call === "function")) {
544
+ return call;
545
+ }
546
+ return _assert_this_initialized$3(self);
547
+ }
548
+ function _set_prototype_of$3(o, p) {
549
+ _set_prototype_of$3 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
550
+ o.__proto__ = p;
551
+ return o;
552
+ };
553
+ return _set_prototype_of$3(o, p);
554
+ }
555
+ function _type_of$3(obj) {
556
+ "@swc/helpers - typeof";
557
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
558
+ }
559
+ function _is_native_reflect_construct$3() {
560
+ try {
561
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
562
+ } catch (_) {}
563
+ return (_is_native_reflect_construct$3 = function() {
564
+ return !!result;
565
+ })();
566
+ }
567
+ function _ts_generator$1(thisArg, body) {
568
+ var f, y, t, _ = {
569
+ label: 0,
570
+ sent: function() {
571
+ if (t[0] & 1) throw t[1];
572
+ return t[1];
573
+ },
574
+ trys: [],
575
+ ops: []
576
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
577
+ return d(g, "next", {
578
+ value: verb(0)
579
+ }), d(g, "throw", {
580
+ value: verb(1)
581
+ }), d(g, "return", {
582
+ value: verb(2)
583
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
584
+ value: function() {
585
+ return this;
586
+ }
587
+ }), g;
588
+ function verb(n) {
589
+ return function(v) {
590
+ return step([
591
+ n,
592
+ v
593
+ ]);
594
+ };
595
+ }
596
+ function step(op) {
597
+ if (f) throw new TypeError("Generator is already executing.");
598
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
599
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
600
+ if (y = 0, t) op = [
601
+ op[0] & 2,
602
+ t.value
603
+ ];
604
+ switch(op[0]){
605
+ case 0:
606
+ case 1:
607
+ t = op;
608
+ break;
609
+ case 4:
610
+ _.label++;
611
+ return {
612
+ value: op[1],
613
+ done: false
614
+ };
615
+ case 5:
616
+ _.label++;
617
+ y = op[1];
618
+ op = [
619
+ 0
620
+ ];
621
+ continue;
622
+ case 7:
623
+ op = _.ops.pop();
624
+ _.trys.pop();
625
+ continue;
626
+ default:
627
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
628
+ _ = 0;
629
+ continue;
630
+ }
631
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
632
+ _.label = op[1];
633
+ break;
634
+ }
635
+ if (op[0] === 6 && _.label < t[1]) {
636
+ _.label = t[1];
637
+ t = op;
638
+ break;
639
+ }
640
+ if (t && _.label < t[2]) {
641
+ _.label = t[2];
642
+ _.ops.push(op);
643
+ break;
644
+ }
645
+ if (t[2]) _.ops.pop();
646
+ _.trys.pop();
647
+ continue;
648
+ }
649
+ op = body.call(thisArg, _);
650
+ } catch (e) {
651
+ op = [
652
+ 6,
653
+ e
654
+ ];
655
+ y = 0;
656
+ } finally{
657
+ f = t = 0;
658
+ }
659
+ if (op[0] & 5) throw op[1];
660
+ return {
661
+ value: op[0] ? op[1] : void 0,
662
+ done: true
663
+ };
664
+ }
665
+ }
666
+ var AbstractWrappedFixture = function AbstractWrappedFixture(fixture) {
667
+ _class_call_check$3(this, AbstractWrappedFixture);
668
+ _define_property$1(this, "fixture", void 0);
669
+ this.fixture = fixture;
670
+ };
671
+ var AbstractWrappedFixtureWithInstance = /*#__PURE__*/ function(AbstractTestContextFixture) {
672
+ _inherits$3(AbstractWrappedFixtureWithInstance, AbstractTestContextFixture);
673
+ function AbstractWrappedFixtureWithInstance(parent) {
674
+ _class_call_check$3(this, AbstractWrappedFixtureWithInstance);
675
+ var _this;
676
+ _this = _call_super$3(this, AbstractWrappedFixtureWithInstance), _define_property$1(_this, "parent", void 0);
677
+ _this.parent = parent;
678
+ return _this;
679
+ }
680
+ return AbstractWrappedFixtureWithInstance;
681
+ }(AbstractTestContextFixture);
186
682
  /**
187
683
  * Wraps the input TestContextFactory to emit another type of Fixture for tests.
188
684
  *
189
685
  * @returns
190
- */
191
- function wrapTestContextFactory(config) {
192
- return factory => {
193
- return buildTests => {
194
- factory(inputFixture => {
195
- const wrap = config.wrapFixture(inputFixture);
196
- let effect;
197
- // add before each
198
- if (config.setupWrap != null) {
199
- beforeEach(async () => {
200
- effect = await config.setupWrap(wrap);
201
- });
202
- }
203
- // add tests
204
- buildTests(wrap);
205
- // add after each
206
- if (config.teardownWrap != null) {
207
- afterEach(async () => {
208
- await config.teardownWrap(wrap, effect);
209
- });
210
- }
211
- });
686
+ */ function wrapTestContextFactory(config) {
687
+ return function(factory) {
688
+ return function(buildTests) {
689
+ factory(function(inputFixture) {
690
+ var wrap = config.wrapFixture(inputFixture);
691
+ var effect;
692
+ // add before each
693
+ if (config.setupWrap != null) {
694
+ beforeEach(function() {
695
+ return _async_to_generator$1(function() {
696
+ return _ts_generator$1(this, function(_state) {
697
+ switch(_state.label){
698
+ case 0:
699
+ return [
700
+ 4,
701
+ config.setupWrap(wrap)
702
+ ];
703
+ case 1:
704
+ effect = _state.sent();
705
+ return [
706
+ 2
707
+ ];
708
+ }
709
+ });
710
+ })();
711
+ });
712
+ }
713
+ // add tests
714
+ buildTests(wrap);
715
+ // add after each
716
+ if (config.teardownWrap != null) {
717
+ afterEach(function() {
718
+ return _async_to_generator$1(function() {
719
+ return _ts_generator$1(this, function(_state) {
720
+ switch(_state.label){
721
+ case 0:
722
+ return [
723
+ 4,
724
+ config.teardownWrap(wrap, effect)
725
+ ];
726
+ case 1:
727
+ _state.sent();
728
+ return [
729
+ 2
730
+ ];
731
+ }
732
+ });
733
+ })();
734
+ });
735
+ }
736
+ });
737
+ };
212
738
  };
213
- };
214
739
  }
215
740
  function instanceWrapTestContextFactory(config) {
216
- return wrapTestContextFactory({
217
- wrapFixture: config.wrapFixture,
218
- setupWrap: async wrap => {
219
- const instance = await config.makeInstance(wrap);
220
- const effect = wrap.setInstance(instance);
221
- if (config.setupInstance) {
222
- await config.setupInstance(instance, wrap);
223
- }
224
- return effect;
225
- },
226
- teardownWrap: async (wrap, deleteInstanceEffect) => {
227
- deleteInstanceEffect?.();
228
- if (config.teardownInstance) {
229
- await config.teardownInstance(wrap.instance);
230
- }
231
- }
232
- });
741
+ return wrapTestContextFactory({
742
+ wrapFixture: config.wrapFixture,
743
+ setupWrap: function setupWrap(wrap) {
744
+ return _async_to_generator$1(function() {
745
+ var instance, effect;
746
+ return _ts_generator$1(this, function(_state) {
747
+ switch(_state.label){
748
+ case 0:
749
+ return [
750
+ 4,
751
+ config.makeInstance(wrap)
752
+ ];
753
+ case 1:
754
+ instance = _state.sent();
755
+ effect = wrap.setInstance(instance);
756
+ if (!config.setupInstance) return [
757
+ 3,
758
+ 3
759
+ ];
760
+ return [
761
+ 4,
762
+ config.setupInstance(instance, wrap)
763
+ ];
764
+ case 2:
765
+ _state.sent();
766
+ _state.label = 3;
767
+ case 3:
768
+ return [
769
+ 2,
770
+ effect
771
+ ];
772
+ }
773
+ });
774
+ })();
775
+ },
776
+ teardownWrap: function teardownWrap(wrap, deleteInstanceEffect) {
777
+ return _async_to_generator$1(function() {
778
+ return _ts_generator$1(this, function(_state) {
779
+ switch(_state.label){
780
+ case 0:
781
+ deleteInstanceEffect === null || deleteInstanceEffect === void 0 ? void 0 : deleteInstanceEffect();
782
+ if (!config.teardownInstance) return [
783
+ 3,
784
+ 2
785
+ ];
786
+ return [
787
+ 4,
788
+ config.teardownInstance(wrap.instance)
789
+ ];
790
+ case 1:
791
+ _state.sent();
792
+ _state.label = 2;
793
+ case 2:
794
+ return [
795
+ 2
796
+ ];
797
+ }
798
+ });
799
+ })();
800
+ }
801
+ });
233
802
  }
234
803
 
235
804
  /**
236
805
  * Creates a test context and configurations that provides a function to build tests based on the configuration.
237
- */
238
- function useTestFunctionFixture(config, buildTests) {
239
- const {
240
- fn
241
- } = config;
242
- const forward = forwardFunction(fn);
243
- buildTests(forward);
806
+ */ function useTestFunctionFixture(config, buildTests) {
807
+ var fn = config.fn;
808
+ var forward = forwardFunction(fn);
809
+ buildTests(forward);
244
810
  }
245
811
  /**
246
812
  * Creates a test context and configurations that provides a function to build tests based on the configuration.
247
- */
248
- function useTestFunctionMapFixture(config, buildTests) {
249
- const forwardedFunctions = mapObjectMap(config.fns, fn => forwardFunction(fn));
250
- buildTests(forwardedFunctions);
813
+ */ function useTestFunctionMapFixture(config, buildTests) {
814
+ var forwardedFunctions = mapObjectMap(config.fns, function(fn) {
815
+ return forwardFunction(fn);
816
+ });
817
+ buildTests(forwardedFunctions);
251
818
  }
252
819
 
253
- var makeError = {exports: {}};
254
-
255
- (function (module, exports$1) {
256
-
257
- // ===================================================================
258
-
259
- var construct = typeof Reflect !== "undefined" ? Reflect.construct : undefined;
260
- var defineProperty = Object.defineProperty;
261
-
262
- // -------------------------------------------------------------------
263
-
264
- var captureStackTrace = Error.captureStackTrace;
265
- if (captureStackTrace === undefined) {
266
- captureStackTrace = function captureStackTrace(error) {
267
- var container = new Error();
268
-
269
- defineProperty(error, "stack", {
270
- configurable: true,
271
- get: function getStack() {
272
- var stack = container.stack;
273
-
274
- // Replace property with value for faster future accesses.
275
- defineProperty(this, "stack", {
276
- configurable: true,
277
- value: stack,
278
- writable: true,
279
- });
280
-
281
- return stack;
282
- },
283
- set: function setStack(stack) {
284
- defineProperty(error, "stack", {
285
- configurable: true,
286
- value: stack,
287
- writable: true,
288
- });
289
- },
290
- });
291
- };
292
- }
293
-
294
- // -------------------------------------------------------------------
295
-
296
- function BaseError(message) {
297
- if (message !== undefined) {
298
- defineProperty(this, "message", {
299
- configurable: true,
300
- value: message,
301
- writable: true,
302
- });
303
- }
304
-
305
- var cname = this.constructor.name;
306
- if (cname !== undefined && cname !== this.name) {
307
- defineProperty(this, "name", {
308
- configurable: true,
309
- value: cname,
310
- writable: true,
311
- });
312
- }
313
-
314
- captureStackTrace(this, this.constructor);
315
- }
316
-
317
- BaseError.prototype = Object.create(Error.prototype, {
318
- // See: https://github.com/JsCommunity/make-error/issues/4
319
- constructor: {
320
- configurable: true,
321
- value: BaseError,
322
- writable: true,
323
- },
324
- });
325
-
326
- // -------------------------------------------------------------------
327
-
328
- // Sets the name of a function if possible (depends of the JS engine).
329
- var setFunctionName = (function() {
330
- function setFunctionName(fn, name) {
331
- return defineProperty(fn, "name", {
332
- configurable: true,
333
- value: name,
334
- });
335
- }
336
- try {
337
- var f = function() {};
338
- setFunctionName(f, "foo");
339
- if (f.name === "foo") {
340
- return setFunctionName;
341
- }
342
- } catch (_) {}
343
- })();
344
-
345
- // -------------------------------------------------------------------
346
-
347
- function makeError(constructor, super_) {
348
- if (super_ == null || super_ === Error) {
349
- super_ = BaseError;
350
- } else if (typeof super_ !== "function") {
351
- throw new TypeError("super_ should be a function");
352
- }
353
-
354
- var name;
355
- if (typeof constructor === "string") {
356
- name = constructor;
357
- constructor =
358
- construct !== undefined
359
- ? function() {
360
- return construct(super_, arguments, this.constructor);
361
- }
362
- : function() {
363
- super_.apply(this, arguments);
364
- };
365
-
366
- // If the name can be set, do it once and for all.
367
- if (setFunctionName !== undefined) {
368
- setFunctionName(constructor, name);
369
- name = undefined;
370
- }
371
- } else if (typeof constructor !== "function") {
372
- throw new TypeError("constructor should be either a string or a function");
373
- }
374
-
375
- // Also register the super constructor also as `constructor.super_` just
376
- // like Node's `util.inherits()`.
377
- //
378
- // eslint-disable-next-line dot-notation
379
- constructor.super_ = constructor["super"] = super_;
380
-
381
- var properties = {
382
- constructor: {
383
- configurable: true,
384
- value: constructor,
385
- writable: true,
386
- },
387
- };
388
-
389
- // If the name could not be set on the constructor, set it on the
390
- // prototype.
391
- if (name !== undefined) {
392
- properties.name = {
393
- configurable: true,
394
- value: name,
395
- writable: true,
396
- };
397
- }
398
- constructor.prototype = Object.create(super_.prototype, properties);
399
-
400
- return constructor;
401
- }
402
- exports$1 = module.exports = makeError;
403
- exports$1.BaseError = BaseError;
404
- } (makeError, makeError.exports));
405
-
406
- var makeErrorExports = makeError.exports;
407
-
408
- /**
409
- * Testing utilities for handling expected failures and errors.
410
- */
820
+ function _assert_this_initialized$2(self) {
821
+ if (self === void 0) {
822
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
823
+ }
824
+ return self;
825
+ }
826
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
827
+ try {
828
+ var info = gen[key](arg);
829
+ var value = info.value;
830
+ } catch (error) {
831
+ reject(error);
832
+ return;
833
+ }
834
+ if (info.done) {
835
+ resolve(value);
836
+ } else {
837
+ Promise.resolve(value).then(_next, _throw);
838
+ }
839
+ }
840
+ function _async_to_generator(fn) {
841
+ return function() {
842
+ var self = this, args = arguments;
843
+ return new Promise(function(resolve, reject) {
844
+ var gen = fn.apply(self, args);
845
+ function _next(value) {
846
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
847
+ }
848
+ function _throw(err) {
849
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
850
+ }
851
+ _next(undefined);
852
+ });
853
+ };
854
+ }
855
+ function _call_super$2(_this, derived, args) {
856
+ derived = _get_prototype_of$2(derived);
857
+ return _possible_constructor_return$2(_this, _is_native_reflect_construct$2() ? Reflect.construct(derived, args || [], _get_prototype_of$2(_this).constructor) : derived.apply(_this, args));
858
+ }
859
+ function _class_call_check$2(instance, Constructor) {
860
+ if (!(instance instanceof Constructor)) {
861
+ throw new TypeError("Cannot call a class as a function");
862
+ }
863
+ }
864
+ function _define_property(obj, key, value) {
865
+ if (key in obj) {
866
+ Object.defineProperty(obj, key, {
867
+ value: value,
868
+ enumerable: true,
869
+ configurable: true,
870
+ writable: true
871
+ });
872
+ } else {
873
+ obj[key] = value;
874
+ }
875
+ return obj;
876
+ }
877
+ function _get_prototype_of$2(o) {
878
+ _get_prototype_of$2 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
879
+ return o.__proto__ || Object.getPrototypeOf(o);
880
+ };
881
+ return _get_prototype_of$2(o);
882
+ }
883
+ function _inherits$2(subClass, superClass) {
884
+ if (typeof superClass !== "function" && superClass !== null) {
885
+ throw new TypeError("Super expression must either be null or a function");
886
+ }
887
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
888
+ constructor: {
889
+ value: subClass,
890
+ writable: true,
891
+ configurable: true
892
+ }
893
+ });
894
+ if (superClass) _set_prototype_of$2(subClass, superClass);
895
+ }
896
+ function _instanceof(left, right) {
897
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
898
+ return !!right[Symbol.hasInstance](left);
899
+ } else {
900
+ return left instanceof right;
901
+ }
902
+ }
903
+ function _possible_constructor_return$2(self, call) {
904
+ if (call && (_type_of$2(call) === "object" || typeof call === "function")) {
905
+ return call;
906
+ }
907
+ return _assert_this_initialized$2(self);
908
+ }
909
+ function _set_prototype_of$2(o, p) {
910
+ _set_prototype_of$2 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
911
+ o.__proto__ = p;
912
+ return o;
913
+ };
914
+ return _set_prototype_of$2(o, p);
915
+ }
916
+ function _type_of$2(obj) {
917
+ "@swc/helpers - typeof";
918
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
919
+ }
920
+ function _is_native_reflect_construct$2() {
921
+ try {
922
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
923
+ } catch (_) {}
924
+ return (_is_native_reflect_construct$2 = function() {
925
+ return !!result;
926
+ })();
927
+ }
928
+ function _ts_generator(thisArg, body) {
929
+ var f, y, t, _ = {
930
+ label: 0,
931
+ sent: function() {
932
+ if (t[0] & 1) throw t[1];
933
+ return t[1];
934
+ },
935
+ trys: [],
936
+ ops: []
937
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
938
+ return d(g, "next", {
939
+ value: verb(0)
940
+ }), d(g, "throw", {
941
+ value: verb(1)
942
+ }), d(g, "return", {
943
+ value: verb(2)
944
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
945
+ value: function() {
946
+ return this;
947
+ }
948
+ }), g;
949
+ function verb(n) {
950
+ return function(v) {
951
+ return step([
952
+ n,
953
+ v
954
+ ]);
955
+ };
956
+ }
957
+ function step(op) {
958
+ if (f) throw new TypeError("Generator is already executing.");
959
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
960
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
961
+ if (y = 0, t) op = [
962
+ op[0] & 2,
963
+ t.value
964
+ ];
965
+ switch(op[0]){
966
+ case 0:
967
+ case 1:
968
+ t = op;
969
+ break;
970
+ case 4:
971
+ _.label++;
972
+ return {
973
+ value: op[1],
974
+ done: false
975
+ };
976
+ case 5:
977
+ _.label++;
978
+ y = op[1];
979
+ op = [
980
+ 0
981
+ ];
982
+ continue;
983
+ case 7:
984
+ op = _.ops.pop();
985
+ _.trys.pop();
986
+ continue;
987
+ default:
988
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
989
+ _ = 0;
990
+ continue;
991
+ }
992
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
993
+ _.label = op[1];
994
+ break;
995
+ }
996
+ if (op[0] === 6 && _.label < t[1]) {
997
+ _.label = t[1];
998
+ t = op;
999
+ break;
1000
+ }
1001
+ if (t && _.label < t[2]) {
1002
+ _.label = t[2];
1003
+ _.ops.push(op);
1004
+ break;
1005
+ }
1006
+ if (t[2]) _.ops.pop();
1007
+ _.trys.pop();
1008
+ continue;
1009
+ }
1010
+ op = body.call(thisArg, _);
1011
+ } catch (e) {
1012
+ op = [
1013
+ 6,
1014
+ e
1015
+ ];
1016
+ y = 0;
1017
+ } finally{
1018
+ f = t = 0;
1019
+ }
1020
+ if (op[0] & 5) throw op[1];
1021
+ return {
1022
+ value: op[0] ? op[1] : void 0,
1023
+ done: true
1024
+ };
1025
+ }
1026
+ }
411
1027
  // MARK: Errors
412
1028
  /**
413
1029
  * Error thrown by fail() and used by expectError()
414
- */
415
- class ExpectedFailError extends makeErrorExports.BaseError {}
1030
+ */ var ExpectedFailError = /*#__PURE__*/ function(BaseError) {
1031
+ _inherits$2(ExpectedFailError, BaseError);
1032
+ function ExpectedFailError() {
1033
+ _class_call_check$2(this, ExpectedFailError);
1034
+ return _call_super$2(this, ExpectedFailError, arguments);
1035
+ }
1036
+ return ExpectedFailError;
1037
+ }(BaseError);
416
1038
  function failSuccessfullyError(message) {
417
- return new ExpectedFailError(message);
1039
+ return new ExpectedFailError(message);
418
1040
  }
419
1041
  function failSuccessfully(message) {
420
- throw failSuccessfullyError(message);
1042
+ throw failSuccessfullyError(message);
421
1043
  }
422
1044
  /**
423
1045
  * Error thrown when success occurs when it should not have.
424
- */
425
- class UnexpectedSuccessFailureError extends makeErrorExports.BaseError {}
1046
+ */ var UnexpectedSuccessFailureError = /*#__PURE__*/ function(BaseError) {
1047
+ _inherits$2(UnexpectedSuccessFailureError, BaseError);
1048
+ function UnexpectedSuccessFailureError() {
1049
+ _class_call_check$2(this, UnexpectedSuccessFailureError);
1050
+ return _call_super$2(this, UnexpectedSuccessFailureError, arguments);
1051
+ }
1052
+ return UnexpectedSuccessFailureError;
1053
+ }(BaseError);
426
1054
  function failDueToSuccessError(message) {
427
- return new UnexpectedSuccessFailureError(message ?? 'expected an error to occur but was successful instead');
1055
+ return new UnexpectedSuccessFailureError(message !== null && message !== void 0 ? message : 'expected an error to occur but was successful instead');
428
1056
  }
429
1057
  /**
430
1058
  * Error thrown when the error type was different than the expected type.
431
- */
432
- class ExpectedErrorOfSpecificTypeError extends makeErrorExports.BaseError {
433
- constructor(encounteredType, expectedType) {
434
- super(`The error encountered was not of the expected type. Expected: ${expectedType ?? 'n/a'}, but encountered: ${encounteredType} `);
435
- this.encounteredType = void 0;
436
- this.expectedType = void 0;
437
- this.encounteredType = encounteredType;
438
- this.expectedType = expectedType;
439
- }
440
- }
1059
+ */ var ExpectedErrorOfSpecificTypeError = /*#__PURE__*/ function(BaseError) {
1060
+ _inherits$2(ExpectedErrorOfSpecificTypeError, BaseError);
1061
+ function ExpectedErrorOfSpecificTypeError(encounteredType, expectedType) {
1062
+ _class_call_check$2(this, ExpectedErrorOfSpecificTypeError);
1063
+ var _this;
1064
+ _this = _call_super$2(this, ExpectedErrorOfSpecificTypeError, [
1065
+ "The error encountered was not of the expected type. Expected: ".concat(expectedType !== null && expectedType !== void 0 ? expectedType : 'n/a', ", but encountered: ").concat(encounteredType, " ")
1066
+ ]), _define_property(_this, "encounteredType", void 0), _define_property(_this, "expectedType", void 0);
1067
+ _this.encounteredType = encounteredType;
1068
+ _this.expectedType = expectedType;
1069
+ return _this;
1070
+ }
1071
+ return ExpectedErrorOfSpecificTypeError;
1072
+ }(BaseError);
441
1073
  function failTest(message) {
442
- throw failDueToSuccessError(message);
1074
+ throw failDueToSuccessError(message);
443
1075
  }
444
1076
  function failDueToSuccess() {
445
- throw failDueToSuccessError();
1077
+ throw failDueToSuccessError();
446
1078
  }
447
1079
  function EXPECT_ERROR_DEFAULT_HANDLER(e) {
448
- if (e instanceof ExpectedFailError) ; else {
449
- throw e;
450
- }
1080
+ if (_instanceof(e, ExpectedFailError)) ; else {
1081
+ throw e;
1082
+ }
451
1083
  }
452
1084
  /**
453
1085
  * Creates an ExpectFailAssertionFunction that asserts the encountered error is of the expected type using the instanceof keyword.
@@ -456,48 +1088,48 @@ function EXPECT_ERROR_DEFAULT_HANDLER(e) {
456
1088
  *
457
1089
  * @param expectedType
458
1090
  * @returns
459
- */
460
- function expectFailAssertErrorType(expectedType) {
461
- return error => {
462
- if (!(error instanceof expectedType)) {
463
- throw new ExpectedErrorOfSpecificTypeError(error, expectedType);
464
- }
465
- };
1091
+ */ function expectFailAssertErrorType(expectedType) {
1092
+ return function(error) {
1093
+ if (!_instanceof(error, expectedType)) {
1094
+ throw new ExpectedErrorOfSpecificTypeError(error, expectedType);
1095
+ }
1096
+ };
466
1097
  }
467
1098
  function expectFail(errorFn, assertFailType) {
468
- function handleError(e) {
469
- if (e instanceof UnexpectedSuccessFailureError) {
470
- throw e;
471
- } else {
472
- const assertionResult = assertFailType?.(e);
473
- if (assertionResult === false) {
474
- throw new ExpectedErrorOfSpecificTypeError(e);
475
- }
476
- failSuccessfully();
477
- }
478
- }
479
- try {
480
- const result = errorFn();
481
- if (isPromise(result)) {
482
- return result.then(failDueToSuccess).catch(handleError);
483
- } else {
484
- failDueToSuccess();
1099
+ function handleError(e) {
1100
+ if (_instanceof(e, UnexpectedSuccessFailureError)) {
1101
+ throw e;
1102
+ } else {
1103
+ var assertionResult = assertFailType === null || assertFailType === void 0 ? void 0 : assertFailType(e);
1104
+ if (assertionResult === false) {
1105
+ throw new ExpectedErrorOfSpecificTypeError(e);
1106
+ }
1107
+ failSuccessfully();
1108
+ }
1109
+ }
1110
+ try {
1111
+ var result = errorFn();
1112
+ if (isPromise(result)) {
1113
+ return result.then(failDueToSuccess).catch(handleError);
1114
+ } else {
1115
+ failDueToSuccess();
1116
+ }
1117
+ } catch (e) {
1118
+ handleError(e);
485
1119
  }
486
- } catch (e) {
487
- handleError(e);
488
- }
489
1120
  }
490
- function expectSuccessfulFail(errorFn, handleError = EXPECT_ERROR_DEFAULT_HANDLER) {
491
- try {
492
- const result = errorFn();
493
- if (isPromise(result)) {
494
- return result.then(failDueToSuccess).catch(handleError);
495
- } else {
496
- failDueToSuccess();
1121
+ function expectSuccessfulFail(errorFn) {
1122
+ var handleError = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : EXPECT_ERROR_DEFAULT_HANDLER;
1123
+ try {
1124
+ var result = errorFn();
1125
+ if (isPromise(result)) {
1126
+ return result.then(failDueToSuccess).catch(handleError);
1127
+ } else {
1128
+ failDueToSuccess();
1129
+ }
1130
+ } catch (e) {
1131
+ handleError(e);
497
1132
  }
498
- } catch (e) {
499
- handleError(e);
500
- }
501
1133
  }
502
1134
  /**
503
1135
  * Used to wrap a testing function and watch for ExpectedFailError errors in order to pass the test. Other exceptions are treated normally as failures.
@@ -507,158 +1139,296 @@ function expectSuccessfulFail(errorFn, handleError = EXPECT_ERROR_DEFAULT_HANDLE
507
1139
  * @param fn
508
1140
  * @param strict
509
1141
  * @returns
510
- */
511
- function shouldFail(fn) {
512
- const usesDoneCallback = fn.length > 0;
513
- // Return a function that checks arguments at runtime to avoid done callback deprecation warning
514
- return async function () {
515
- const {
516
- done,
517
- _promise
518
- } = testDoneCallbackRef();
519
- function handleError(e) {
520
- if (!(e instanceof ExpectedFailError)) {
521
- failWithTestDoneCallback(done, e);
522
- } else {
523
- done();
524
- }
525
- }
526
- try {
527
- const result = expectSuccessfulFail(() => {
528
- let result;
529
- if (usesDoneCallback) {
530
- const fakeDone = build({
531
- base: fakeDoneHandler(),
532
- build: x => {
533
- x.failSuccessfully = () => {
534
- fakeDone(failSuccessfullyError());
535
- };
1142
+ */ function shouldFail(fn) {
1143
+ var usesDoneCallback = fn.length > 0;
1144
+ // Return a function that checks arguments at runtime to avoid done callback deprecation warning
1145
+ return function() {
1146
+ return _async_to_generator(function() {
1147
+ var _testDoneCallbackRef, done, _promise, result;
1148
+ function handleError(e) {
1149
+ if (!_instanceof(e, ExpectedFailError)) {
1150
+ failWithTestDoneCallback(done, e);
1151
+ } else {
1152
+ done();
1153
+ }
536
1154
  }
537
- });
538
- const callbackWithDoneResult = fn(fakeDone);
539
- if (isPromise(callbackWithDoneResult)) {
540
- fakeDone.reject(new Error('Configured to use "done" value while returning a promise. Configure your test to use one or the other.'));
541
- }
542
- // return the fake done promise. Done/fail will resolve as a promise.
543
- result = fakeDone._ref.promise;
544
- } else {
545
- result = fn();
546
- }
547
- return result;
548
- }, handleError);
549
- // If expectSuccessfulFail returns a promise, handle it
550
- if (isPromise(result)) {
551
- result.catch(handleError);
552
- }
553
- } catch (e) {
554
- // Handle synchronous errors
555
- handleError(e);
556
- }
557
- return _promise.promise;
558
- };
1155
+ return _ts_generator(this, function(_state) {
1156
+ _testDoneCallbackRef = testDoneCallbackRef(), done = _testDoneCallbackRef.done, _promise = _testDoneCallbackRef._promise;
1157
+ try {
1158
+ result = expectSuccessfulFail(function() {
1159
+ var result;
1160
+ if (usesDoneCallback) {
1161
+ var fakeDone = build({
1162
+ base: fakeDoneHandler(),
1163
+ build: function build(x) {
1164
+ x.failSuccessfully = function() {
1165
+ fakeDone(failSuccessfullyError());
1166
+ };
1167
+ }
1168
+ });
1169
+ var callbackWithDoneResult = fn(fakeDone);
1170
+ if (isPromise(callbackWithDoneResult)) {
1171
+ fakeDone.reject(new Error('Configured to use "done" value while returning a promise. Configure your test to use one or the other.'));
1172
+ }
1173
+ // return the fake done promise. Done/fail will resolve as a promise.
1174
+ result = fakeDone._ref.promise;
1175
+ } else {
1176
+ result = fn();
1177
+ }
1178
+ return result;
1179
+ }, handleError);
1180
+ // If expectSuccessfulFail returns a promise, handle it
1181
+ if (isPromise(result)) {
1182
+ result.catch(handleError);
1183
+ }
1184
+ } catch (e) {
1185
+ // Handle synchronous errors
1186
+ handleError(e);
1187
+ }
1188
+ return [
1189
+ 2,
1190
+ _promise.promise
1191
+ ];
1192
+ });
1193
+ })();
1194
+ };
559
1195
  }
560
1196
  function itShouldFail(describeOrFn, fn) {
561
- let description;
562
- if (typeof describeOrFn === 'string') {
563
- description = `should fail ${describeOrFn}`;
564
- } else {
565
- fn = describeOrFn;
566
- description = 'should fail';
567
- }
568
- it(description, shouldFail(fn));
1197
+ var description;
1198
+ if (typeof describeOrFn === 'string') {
1199
+ description = "should fail ".concat(describeOrFn);
1200
+ } else {
1201
+ fn = describeOrFn;
1202
+ description = 'should fail';
1203
+ }
1204
+ it(description, shouldFail(fn));
569
1205
  }
570
1206
  function fakeDoneHandler() {
571
- const promiseRef = promiseReference();
572
- const doneHandler = promiseRef.resolve;
573
- const failHandler = e => {
574
- promiseRef.reject(e);
575
- };
576
- const fakeDone = error => {
577
- if (error) {
578
- failHandler(error);
579
- } else {
580
- doneHandler(0);
581
- }
582
- };
583
- fakeDone.fail = error => {
584
- failHandler(error);
585
- };
586
- fakeDone._ref = promiseRef;
587
- fakeDone.promise = promiseRef.promise;
588
- fakeDone.resolve = promiseRef.resolve;
589
- fakeDone.reject = promiseRef.reject;
590
- return fakeDone;
1207
+ var promiseRef = promiseReference();
1208
+ var doneHandler = promiseRef.resolve;
1209
+ var failHandler = function failHandler(e) {
1210
+ promiseRef.reject(e);
1211
+ };
1212
+ var fakeDone = function fakeDone(error) {
1213
+ if (error) {
1214
+ failHandler(error);
1215
+ } else {
1216
+ doneHandler(0);
1217
+ }
1218
+ };
1219
+ fakeDone.fail = function(error) {
1220
+ failHandler(error);
1221
+ };
1222
+ fakeDone._ref = promiseRef;
1223
+ fakeDone.promise = promiseRef.promise;
1224
+ fakeDone.resolve = promiseRef.resolve;
1225
+ fakeDone.reject = promiseRef.reject;
1226
+ return fakeDone;
591
1227
  }
592
1228
 
1229
+ function _assert_this_initialized$1(self) {
1230
+ if (self === void 0) {
1231
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
1232
+ }
1233
+ return self;
1234
+ }
1235
+ function _call_super$1(_this, derived, args) {
1236
+ derived = _get_prototype_of$1(derived);
1237
+ return _possible_constructor_return$1(_this, _is_native_reflect_construct$1() ? Reflect.construct(derived, args || [], _get_prototype_of$1(_this).constructor) : derived.apply(_this, args));
1238
+ }
1239
+ function _class_call_check$1(instance, Constructor) {
1240
+ if (!(instance instanceof Constructor)) {
1241
+ throw new TypeError("Cannot call a class as a function");
1242
+ }
1243
+ }
1244
+ function _get_prototype_of$1(o) {
1245
+ _get_prototype_of$1 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
1246
+ return o.__proto__ || Object.getPrototypeOf(o);
1247
+ };
1248
+ return _get_prototype_of$1(o);
1249
+ }
1250
+ function _inherits$1(subClass, superClass) {
1251
+ if (typeof superClass !== "function" && superClass !== null) {
1252
+ throw new TypeError("Super expression must either be null or a function");
1253
+ }
1254
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
1255
+ constructor: {
1256
+ value: subClass,
1257
+ writable: true,
1258
+ configurable: true
1259
+ }
1260
+ });
1261
+ if (superClass) _set_prototype_of$1(subClass, superClass);
1262
+ }
1263
+ function _possible_constructor_return$1(self, call) {
1264
+ if (call && (_type_of$1(call) === "object" || typeof call === "function")) {
1265
+ return call;
1266
+ }
1267
+ return _assert_this_initialized$1(self);
1268
+ }
1269
+ function _set_prototype_of$1(o, p) {
1270
+ _set_prototype_of$1 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
1271
+ o.__proto__ = p;
1272
+ return o;
1273
+ };
1274
+ return _set_prototype_of$1(o, p);
1275
+ }
1276
+ function _type_of$1(obj) {
1277
+ "@swc/helpers - typeof";
1278
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
1279
+ }
1280
+ function _is_native_reflect_construct$1() {
1281
+ try {
1282
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
1283
+ } catch (_) {}
1284
+ return (_is_native_reflect_construct$1 = function() {
1285
+ return !!result;
1286
+ })();
1287
+ }
593
1288
  /**
594
1289
  * @deprecated Use AbstractTestContextFixture from shared instead. This is kept for backwards compatibility.
595
- */
596
- class AbstractJestTestContextFixture extends AbstractTestContextFixture {}
1290
+ */ var AbstractJestTestContextFixture = /*#__PURE__*/ function(AbstractTestContextFixture) {
1291
+ _inherits$1(AbstractJestTestContextFixture, AbstractTestContextFixture);
1292
+ function AbstractJestTestContextFixture() {
1293
+ _class_call_check$1(this, AbstractJestTestContextFixture);
1294
+ return _call_super$1(this, AbstractJestTestContextFixture, arguments);
1295
+ }
1296
+ return AbstractJestTestContextFixture;
1297
+ }(AbstractTestContextFixture);
597
1298
  /**
598
1299
  * @deprecated Use AbstractChildTestContextFixture from shared instead. This is kept for backwards compatibility.
599
- */
600
- class AbstractChildJestTestContextFixture extends AbstractChildTestContextFixture {}
1300
+ */ var AbstractChildJestTestContextFixture = /*#__PURE__*/ function(AbstractChildTestContextFixture) {
1301
+ _inherits$1(AbstractChildJestTestContextFixture, AbstractChildTestContextFixture);
1302
+ function AbstractChildJestTestContextFixture() {
1303
+ _class_call_check$1(this, AbstractChildJestTestContextFixture);
1304
+ return _call_super$1(this, AbstractChildJestTestContextFixture, arguments);
1305
+ }
1306
+ return AbstractChildJestTestContextFixture;
1307
+ }(AbstractChildTestContextFixture);
601
1308
  /**
602
1309
  * @deprecated Use testContextBuilder from shared instead. This is kept for backwards compatibility.
603
- */
604
- const jestTestContextBuilder = testContextBuilder;
1310
+ */ var jestTestContextBuilder = testContextBuilder;
605
1311
  /**
606
1312
  * @deprecated Use useContextFixture from shared instead. This is kept for backwards compatibility.
607
- */
608
- const useJestContextFixture = useTestContextFixture;
1313
+ */ var useJestContextFixture = useTestContextFixture;
609
1314
 
610
- /**
611
- * https://github.com/facebook/jest/issues/11698
612
- *
613
- * Since fail() was silently removed, we redefine it.
614
- */
1315
+ function _assert_this_initialized(self) {
1316
+ if (self === void 0) {
1317
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
1318
+ }
1319
+ return self;
1320
+ }
1321
+ function _call_super(_this, derived, args) {
1322
+ derived = _get_prototype_of(derived);
1323
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
1324
+ }
1325
+ function _class_call_check(instance, Constructor) {
1326
+ if (!(instance instanceof Constructor)) {
1327
+ throw new TypeError("Cannot call a class as a function");
1328
+ }
1329
+ }
1330
+ function _get_prototype_of(o) {
1331
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
1332
+ return o.__proto__ || Object.getPrototypeOf(o);
1333
+ };
1334
+ return _get_prototype_of(o);
1335
+ }
1336
+ function _inherits(subClass, superClass) {
1337
+ if (typeof superClass !== "function" && superClass !== null) {
1338
+ throw new TypeError("Super expression must either be null or a function");
1339
+ }
1340
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
1341
+ constructor: {
1342
+ value: subClass,
1343
+ writable: true,
1344
+ configurable: true
1345
+ }
1346
+ });
1347
+ if (superClass) _set_prototype_of(subClass, superClass);
1348
+ }
1349
+ function _possible_constructor_return(self, call) {
1350
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
1351
+ return call;
1352
+ }
1353
+ return _assert_this_initialized(self);
1354
+ }
1355
+ function _set_prototype_of(o, p) {
1356
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
1357
+ o.__proto__ = p;
1358
+ return o;
1359
+ };
1360
+ return _set_prototype_of(o, p);
1361
+ }
1362
+ function _type_of(obj) {
1363
+ "@swc/helpers - typeof";
1364
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
1365
+ }
1366
+ function _is_native_reflect_construct() {
1367
+ try {
1368
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
1369
+ } catch (_) {}
1370
+ return (_is_native_reflect_construct = function() {
1371
+ return !!result;
1372
+ })();
1373
+ }
615
1374
  /**
616
1375
  * @deprecated Use failWithTestDoneCallback from shared instead. This is kept for backwards compatibility.
617
- */
618
- const failWithJestDoneCallback = failWithTestDoneCallback;
1376
+ */ var failWithJestDoneCallback = failWithTestDoneCallback;
619
1377
  // MARK: Errors
620
1378
  /**
621
1379
  * @deprecated Use ExpectedFailError from shared instead. This is kept for backwards compatibility.
622
- */
623
- class JestExpectedFailError extends ExpectedFailError {}
1380
+ */ var JestExpectedFailError = /*#__PURE__*/ function(ExpectedFailError) {
1381
+ _inherits(JestExpectedFailError, ExpectedFailError);
1382
+ function JestExpectedFailError() {
1383
+ _class_call_check(this, JestExpectedFailError);
1384
+ return _call_super(this, JestExpectedFailError, arguments);
1385
+ }
1386
+ return JestExpectedFailError;
1387
+ }(ExpectedFailError);
624
1388
  /**
625
1389
  * @deprecated Use UnexpectedSuccessFailureError from shared instead. This is kept for backwards compatibility.
626
- */
627
- class JestUnexpectedSuccessFailureError extends UnexpectedSuccessFailureError {}
1390
+ */ var JestUnexpectedSuccessFailureError = /*#__PURE__*/ function(UnexpectedSuccessFailureError) {
1391
+ _inherits(JestUnexpectedSuccessFailureError, UnexpectedSuccessFailureError);
1392
+ function JestUnexpectedSuccessFailureError() {
1393
+ _class_call_check(this, JestUnexpectedSuccessFailureError);
1394
+ return _call_super(this, JestUnexpectedSuccessFailureError, arguments);
1395
+ }
1396
+ return JestUnexpectedSuccessFailureError;
1397
+ }(UnexpectedSuccessFailureError);
628
1398
  /**
629
1399
  * @deprecated Use ExpectedErrorOfSpecificTypeError from shared instead. This is kept for backwards compatibility.
630
- */
631
- class JestExpectedErrorOfSpecificTypeError extends ExpectedErrorOfSpecificTypeError {}
1400
+ */ var JestExpectedErrorOfSpecificTypeError = /*#__PURE__*/ function(ExpectedErrorOfSpecificTypeError) {
1401
+ _inherits(JestExpectedErrorOfSpecificTypeError, ExpectedErrorOfSpecificTypeError);
1402
+ function JestExpectedErrorOfSpecificTypeError() {
1403
+ _class_call_check(this, JestExpectedErrorOfSpecificTypeError);
1404
+ return _call_super(this, JestExpectedErrorOfSpecificTypeError, arguments);
1405
+ }
1406
+ return JestExpectedErrorOfSpecificTypeError;
1407
+ }(ExpectedErrorOfSpecificTypeError);
632
1408
  /**
633
1409
  * @deprecated Use failWithTestDoneCallback with failDueToSuccessError from shared instead. This is kept for backwards compatibility.
634
- */
635
- function failWithDoneDueToSuccess(done) {
636
- failWithTestDoneCallback(done, failDueToSuccessError());
1410
+ */ function failWithDoneDueToSuccess(done) {
1411
+ failWithTestDoneCallback(done, failDueToSuccessError());
637
1412
  }
638
1413
  /**
639
1414
  * @deprecated Use expectFailAssertErrorType from shared instead. This is kept for backwards compatibility.
640
- */
641
- const jestExpectFailAssertErrorType = expectFailAssertErrorType;
1415
+ */ var jestExpectFailAssertErrorType = expectFailAssertErrorType;
642
1416
 
643
1417
  /**
644
1418
  * Wraps the input JestTestContextFactory to emit another type of Fixture for tests.
645
1419
  *
646
1420
  * @deprecated Use wrapTestContextFactory from shared instead. This is kept for backwards compatibility.
647
1421
  * @returns
648
- */
649
- const wrapJestTestContextFactory = wrapTestContextFactory;
1422
+ */ var wrapJestTestContextFactory = wrapTestContextFactory;
650
1423
  /**
651
1424
  * @deprecated Use instanceWrapTestContextFactory from shared instead. This is kept for backwards compatibility.
652
- */
653
- const instanceWrapJestTestContextFactory = instanceWrapTestContextFactory;
1425
+ */ var instanceWrapJestTestContextFactory = instanceWrapTestContextFactory;
654
1426
 
655
1427
  /**
656
1428
  * @deprecated Use useTestFunctionFixture from shared instead. This is kept for backwards compatibility.
657
- */
658
- const useJestFunctionFixture = useTestFunctionFixture;
1429
+ */ var useJestFunctionFixture = useTestFunctionFixture;
659
1430
  /**
660
1431
  * @deprecated Use useTestFunctionMapFixture from shared instead. This is kept for backwards compatibility.
661
- */
662
- const useJestFunctionMapFixture = useTestFunctionMapFixture;
1432
+ */ var useJestFunctionMapFixture = useTestFunctionMapFixture;
663
1433
 
664
1434
  export { AbstractChildJestTestContextFixture, AbstractChildTestContextFixture, AbstractJestTestContextFixture, AbstractTestContextFixture, AbstractWrappedFixture, AbstractWrappedFixtureWithInstance, EXPECT_ERROR_DEFAULT_HANDLER, ExpectedErrorOfSpecificTypeError, ExpectedFailError, JestExpectedErrorOfSpecificTypeError, JestExpectedFailError, JestUnexpectedSuccessFailureError, UnexpectedSuccessFailureError, callbackTest, expectFail, expectFailAssertErrorType, expectSuccessfulFail, failDueToSuccess, failDueToSuccessError, failSuccessfully, failSuccessfullyError, failTest, failWithDoneDueToSuccess, failWithJestDoneCallback, failWithTestDoneCallback, fakeDoneHandler, instanceWrapJestTestContextFactory, instanceWrapTestContextFactory, itShouldFail, jestExpectFailAssertErrorType, jestTestContextBuilder, shouldFail, testContextBuilder, testDoneCallbackRef, useJestContextFixture, useJestFunctionFixture, useJestFunctionMapFixture, useTestContextFixture, useTestFunctionFixture, useTestFunctionMapFixture, wrapJestTestContextFactory, wrapTestContextFactory };