@locustjs/test 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.esm.js CHANGED
@@ -21,14 +21,21 @@ import { Exception } from "@locustjs/exception";
21
21
  import fs from "fs";
22
22
  import path from "path";
23
23
 
24
+ class TestException extends Exception {}
24
25
  class Expect {
25
26
  constructor(value) {
26
27
  this.value = value;
28
+ this._expected = false;
29
+ }
30
+ get expected() {
31
+ return this._expected;
27
32
  }
28
33
  toBe(value) {
34
+ this._expected = true;
35
+
29
36
  if (this.value === value) {
30
37
  } else {
31
- throw new Exception({
38
+ throw new TestException({
32
39
  message: `${this.value} is not equal to ${value}`,
33
40
  code: 1000,
34
41
  status: "not-eq",
@@ -38,8 +45,10 @@ class Expect {
38
45
  return this;
39
46
  }
40
47
  toBeGt(value) {
48
+ this._expected = true;
49
+
41
50
  if (this.value <= value) {
42
- throw new Exception({
51
+ throw new TestException({
43
52
  message: `${this.value} is not greater than ${value}`,
44
53
  code: 1001,
45
54
  status: "lte",
@@ -52,8 +61,10 @@ class Expect {
52
61
  return this.toBeGt(value);
53
62
  }
54
63
  toBeGte(value) {
64
+ this._expected = true;
65
+
55
66
  if (this.value < value) {
56
- throw new Exception({
67
+ throw new TestException({
57
68
  message: `${this.value} is not greater than or equal to ${value}`,
58
69
  code: 1002,
59
70
  status: "lt",
@@ -66,8 +77,10 @@ class Expect {
66
77
  return this.toBeGte(value);
67
78
  }
68
79
  toBeLt(value) {
80
+ this._expected = true;
81
+
69
82
  if (this.value >= value) {
70
- throw new Exception({
83
+ throw new TestException({
71
84
  message: `${this.value} is not less than ${value}`,
72
85
  code: 1003,
73
86
  status: "gte",
@@ -80,8 +93,10 @@ class Expect {
80
93
  return this.toBeLt(value);
81
94
  }
82
95
  toBeLte(value) {
96
+ this._expected = true;
97
+
83
98
  if (this.value > value) {
84
- throw new Exception({
99
+ throw new TestException({
85
100
  message: `${this.value} is not less than or equal to ${value}`,
86
101
  code: 1004,
87
102
  status: "gt",
@@ -94,8 +109,10 @@ class Expect {
94
109
  return this.toBeLte(value);
95
110
  }
96
111
  toBeBetween(n, m) {
112
+ this._expected = true;
113
+
97
114
  if (!(this.value >= n && this.value < m)) {
98
- throw new Exception({
115
+ throw new TestException({
99
116
  message: `${this.value} is not between ${n} and ${m}`,
100
117
  code: 1024,
101
118
  status: "between",
@@ -105,8 +122,10 @@ class Expect {
105
122
  return this;
106
123
  }
107
124
  toBeOfType(type) {
125
+ this._expected = true;
126
+
108
127
  if (typeof this.value !== type) {
109
- throw new Exception({
128
+ throw new TestException({
110
129
  message: `${this.value} is not of type ${type}`,
111
130
  code: 1025,
112
131
  status: "of-type",
@@ -116,8 +135,10 @@ class Expect {
116
135
  return this;
117
136
  }
118
137
  toBeString() {
138
+ this._expected = true;
139
+
119
140
  if (!isString(this.value)) {
120
- throw new Exception({
141
+ throw new TestException({
121
142
  message: `${this.value} is not string`,
122
143
  code: 1026,
123
144
  status: "is-string",
@@ -127,8 +148,9 @@ class Expect {
127
148
  return this;
128
149
  }
129
150
  toBeSomeString() {
151
+ this._expected = true;
130
152
  if (!isSomeString(this.value)) {
131
- throw new Exception({
153
+ throw new TestException({
132
154
  message: `${this.value} is not some string`,
133
155
  code: 1027,
134
156
  status: "is-some-string",
@@ -138,8 +160,10 @@ class Expect {
138
160
  return this;
139
161
  }
140
162
  toBeNumber() {
163
+ this._expected = true;
164
+
141
165
  if (!isNumber(this.value)) {
142
- throw new Exception({
166
+ throw new TestException({
143
167
  message: `${this.value} is not number`,
144
168
  code: 1028,
145
169
  status: "is-number",
@@ -149,8 +173,10 @@ class Expect {
149
173
  return this;
150
174
  }
151
175
  toBeDate() {
176
+ this._expected = true;
177
+
152
178
  if (!isDate(this.value)) {
153
- throw new Exception({
179
+ throw new TestException({
154
180
  message: `${this.value} is not date`,
155
181
  code: 1029,
156
182
  status: "is-date",
@@ -160,8 +186,10 @@ class Expect {
160
186
  return this;
161
187
  }
162
188
  toBeBool() {
189
+ this._expected = true;
190
+
163
191
  if (!isBool(this.value)) {
164
- throw new Exception({
192
+ throw new TestException({
165
193
  message: `${this.value} is not bool`,
166
194
  code: 1030,
167
195
  status: "is-bool",
@@ -171,8 +199,10 @@ class Expect {
171
199
  return this;
172
200
  }
173
201
  toBeBasicType() {
202
+ this._expected = true;
203
+
174
204
  if (!isBasic(this.value)) {
175
- throw new Exception({
205
+ throw new TestException({
176
206
  message: `${this.value} is not basic type`,
177
207
  code: 1031,
178
208
  status: "is-basic-type",
@@ -182,8 +212,10 @@ class Expect {
182
212
  return this;
183
213
  }
184
214
  toBePrimitive() {
215
+ this._expected = true;
216
+
185
217
  if (!isPrimitive(this.value)) {
186
- throw new Exception({
218
+ throw new TestException({
187
219
  message: `${this.value} is not primitive type`,
188
220
  code: 1032,
189
221
  status: "is-primitive",
@@ -193,8 +225,10 @@ class Expect {
193
225
  return this;
194
226
  }
195
227
  toBeEmpty() {
228
+ this._expected = true;
229
+
196
230
  if (!isEmpty(this.value)) {
197
- throw new Exception({
231
+ throw new TestException({
198
232
  message: `${this.value} is not empty`,
199
233
  code: 1033,
200
234
  status: "is-empty",
@@ -204,8 +238,10 @@ class Expect {
204
238
  return this;
205
239
  }
206
240
  toBeObject() {
241
+ this._expected = true;
242
+
207
243
  if (!isObject(this.value)) {
208
- throw new Exception({
244
+ throw new TestException({
209
245
  message: `${this.value} is not object`,
210
246
  code: 1034,
211
247
  status: "is-object",
@@ -215,8 +251,10 @@ class Expect {
215
251
  return this;
216
252
  }
217
253
  toBeSomeObject() {
254
+ this._expected = true;
255
+
218
256
  if (!isSomeObject(this.value)) {
219
- throw new Exception({
257
+ throw new TestException({
220
258
  message: `${this.value} is not some object`,
221
259
  code: 1035,
222
260
  status: "is-some-object",
@@ -226,8 +264,10 @@ class Expect {
226
264
  return this;
227
265
  }
228
266
  toBeFunction() {
267
+ this._expected = true;
268
+
229
269
  if (!isFunction(this.value)) {
230
- throw new Exception({
270
+ throw new TestException({
231
271
  message: `${this.value} is not function`,
232
272
  code: 1036,
233
273
  status: "is-function",
@@ -237,8 +277,10 @@ class Expect {
237
277
  return this;
238
278
  }
239
279
  toBeNumeric() {
280
+ this._expected = true;
281
+
240
282
  if (!isNumeric(this.value)) {
241
- throw new Exception({
283
+ throw new TestException({
242
284
  message: `${this.value} is not numeric`,
243
285
  code: 1037,
244
286
  status: "is-numeric",
@@ -248,8 +290,10 @@ class Expect {
248
290
  return this;
249
291
  }
250
292
  toBeArray() {
293
+ this._expected = true;
294
+
251
295
  if (!isArray(this.value)) {
252
- throw new Exception({
296
+ throw new TestException({
253
297
  message: `${this.value} is not array`,
254
298
  code: 1038,
255
299
  status: "is-array",
@@ -259,8 +303,10 @@ class Expect {
259
303
  return this;
260
304
  }
261
305
  toBeSomeArray() {
306
+ this._expected = true;
307
+
262
308
  if (!isSomeArray(this.value)) {
263
- throw new Exception({
309
+ throw new TestException({
264
310
  message: `${this.value} is not some array`,
265
311
  code: 1039,
266
312
  status: "is-some-array",
@@ -270,8 +316,10 @@ class Expect {
270
316
  return this;
271
317
  }
272
318
  toBeIterable() {
319
+ this._expected = true;
320
+
273
321
  if (!isIterable(this.value)) {
274
- throw new Exception({
322
+ throw new TestException({
275
323
  message: `${this.value} is not iterable`,
276
324
  code: 1040,
277
325
  status: "is-iterable",
@@ -281,8 +329,10 @@ class Expect {
281
329
  return this;
282
330
  }
283
331
  toBeSubClassOf(type) {
332
+ this._expected = true;
333
+
284
334
  if (!isSubClassOf(this.value, type)) {
285
- throw new Exception({
335
+ throw new TestException({
286
336
  message: `${this.value} is not subclass of ${type}`,
287
337
  code: 1041,
288
338
  status: "is-subclass-of",
@@ -292,8 +342,10 @@ class Expect {
292
342
  return this;
293
343
  }
294
344
  toBeInstanceOf(type) {
345
+ this._expected = true;
346
+
295
347
  if (!(this.value instanceof type)) {
296
- throw new Exception({
348
+ throw new TestException({
297
349
  message: `${this.value} is not instance of ${type}`,
298
350
  code: 1042,
299
351
  status: "instanceof",
@@ -303,10 +355,12 @@ class Expect {
303
355
  return this;
304
356
  }
305
357
  toMatch(pattern, flags) {
358
+ this._expected = true;
359
+
306
360
  const r = new RegExp(pattern, flags);
307
361
 
308
362
  if (!r.test(this.value)) {
309
- throw new Exception({
363
+ throw new TestException({
310
364
  message: `${this.value} does not match ${pattern}`,
311
365
  code: 1043,
312
366
  status: "match",
@@ -316,8 +370,10 @@ class Expect {
316
370
  return this;
317
371
  }
318
372
  notToBe(value) {
373
+ this._expected = true;
374
+
319
375
  if (this.value === value) {
320
- throw new Exception({
376
+ throw new TestException({
321
377
  message: `${value} is equal to ${this.value}`,
322
378
  code: 1005,
323
379
  status: "eq",
@@ -327,8 +383,10 @@ class Expect {
327
383
  return this;
328
384
  }
329
385
  toBeDefined() {
386
+ this._expected = true;
387
+
330
388
  if (this.value === undefined) {
331
- throw new Exception({
389
+ throw new TestException({
332
390
  message: `value is undefined`,
333
391
  code: 1006,
334
392
  status: "undefined",
@@ -338,8 +396,10 @@ class Expect {
338
396
  return this;
339
397
  }
340
398
  toBeUndefined() {
399
+ this._expected = true;
400
+
341
401
  if (this.value !== undefined) {
342
- throw new Exception({
402
+ throw new TestException({
343
403
  message: `value is defined`,
344
404
  code: 1007,
345
405
  status: "defined",
@@ -349,8 +409,10 @@ class Expect {
349
409
  return this;
350
410
  }
351
411
  toBeNull() {
412
+ this._expected = true;
413
+
352
414
  if (this.value !== null) {
353
- throw new Exception({
415
+ throw new TestException({
354
416
  message: `value is not null`,
355
417
  code: 1008,
356
418
  status: "not-null",
@@ -360,8 +422,10 @@ class Expect {
360
422
  return this;
361
423
  }
362
424
  notToBeNull() {
425
+ this._expected = true;
426
+
363
427
  if (this.value === null) {
364
- throw new Exception({
428
+ throw new TestException({
365
429
  message: `value is null`,
366
430
  code: 1009,
367
431
  status: "null",
@@ -371,9 +435,11 @@ class Expect {
371
435
  return this;
372
436
  }
373
437
  toBeNullOrUndefined() {
438
+ this._expected = true;
439
+
374
440
  if (this.value == null) {
375
441
  } else {
376
- throw new Exception({
442
+ throw new TestException({
377
443
  message: `value is not null/undefined`,
378
444
  code: 1010,
379
445
  status: "not-null-or-undefined",
@@ -383,8 +449,10 @@ class Expect {
383
449
  return this;
384
450
  }
385
451
  notToBeNullOrUndefined() {
452
+ this._expected = true;
453
+
386
454
  if (this.value == null) {
387
- throw new Exception({
455
+ throw new TestException({
388
456
  message: `value is null/undefined`,
389
457
  code: 1011,
390
458
  status: "null-or-undefined",
@@ -394,8 +462,10 @@ class Expect {
394
462
  return this;
395
463
  }
396
464
  notToBeBetween(n, m) {
465
+ this._expected = true;
466
+
397
467
  if (this.value >= n && this.value < m) {
398
- throw new Exception({
468
+ throw new TestException({
399
469
  message: `${this.value} is between ${n} and ${m}`,
400
470
  code: 1044,
401
471
  status: "not-between",
@@ -405,8 +475,10 @@ class Expect {
405
475
  return this;
406
476
  }
407
477
  notToBeOfType(type) {
478
+ this._expected = true;
479
+
408
480
  if (typeof this.value === type) {
409
- throw new Exception({
481
+ throw new TestException({
410
482
  message: `${this.value} is of type ${type}`,
411
483
  code: 1045,
412
484
  status: "not-oftype",
@@ -416,8 +488,10 @@ class Expect {
416
488
  return this;
417
489
  }
418
490
  notToBeString() {
491
+ this._expected = true;
492
+
419
493
  if (isString(this.value)) {
420
- throw new Exception({
494
+ throw new TestException({
421
495
  message: `${this.value} is string`,
422
496
  code: 1046,
423
497
  status: "not-is-string",
@@ -427,8 +501,10 @@ class Expect {
427
501
  return this;
428
502
  }
429
503
  notToBeSomeString() {
504
+ this._expected = true;
505
+
430
506
  if (isSomeString(this.value)) {
431
- throw new Exception({
507
+ throw new TestException({
432
508
  message: `${this.value} is some string`,
433
509
  code: 1047,
434
510
  status: "not-is-some-string",
@@ -438,8 +514,10 @@ class Expect {
438
514
  return this;
439
515
  }
440
516
  notToBeNumber() {
517
+ this._expected = true;
518
+
441
519
  if (isNumber(this.value)) {
442
- throw new Exception({
520
+ throw new TestException({
443
521
  message: `${this.value} is number`,
444
522
  code: 1048,
445
523
  status: "not-is-number",
@@ -449,8 +527,10 @@ class Expect {
449
527
  return this;
450
528
  }
451
529
  notToBeDate() {
530
+ this._expected = true;
531
+
452
532
  if (isDate(this.value)) {
453
- throw new Exception({
533
+ throw new TestException({
454
534
  message: `${this.value} is date`,
455
535
  code: 1049,
456
536
  status: "not-is-date",
@@ -460,8 +540,10 @@ class Expect {
460
540
  return this;
461
541
  }
462
542
  notToBeBool() {
543
+ this._expected = true;
544
+
463
545
  if (isBool(this.value)) {
464
- throw new Exception({
546
+ throw new TestException({
465
547
  message: `${this.value} is bool`,
466
548
  code: 1050,
467
549
  status: "not-is-bool",
@@ -471,8 +553,10 @@ class Expect {
471
553
  return this;
472
554
  }
473
555
  notToBeBasicType() {
556
+ this._expected = true;
557
+
474
558
  if (isBasic(this.value)) {
475
- throw new Exception({
559
+ throw new TestException({
476
560
  message: `${this.value} is basic type`,
477
561
  code: 1051,
478
562
  status: "not-is-basic-type",
@@ -482,8 +566,10 @@ class Expect {
482
566
  return this;
483
567
  }
484
568
  notToBePrimitive() {
569
+ this._expected = true;
570
+
485
571
  if (isPrimitive(this.value)) {
486
- throw new Exception({
572
+ throw new TestException({
487
573
  message: `${this.value} is primitive type`,
488
574
  code: 1052,
489
575
  status: "not-is-primitive",
@@ -493,8 +579,10 @@ class Expect {
493
579
  return this;
494
580
  }
495
581
  notToBeEmpty() {
582
+ this._expected = true;
583
+
496
584
  if (isEmpty(this.value)) {
497
- throw new Exception({
585
+ throw new TestException({
498
586
  message: `${this.value} is empty`,
499
587
  code: 1053,
500
588
  status: "not-is-empty",
@@ -504,8 +592,10 @@ class Expect {
504
592
  return this;
505
593
  }
506
594
  notToBeObject() {
595
+ this._expected = true;
596
+
507
597
  if (isObject(this.value)) {
508
- throw new Exception({
598
+ throw new TestException({
509
599
  message: `${this.value} is object`,
510
600
  code: 1054,
511
601
  status: "not-is-object",
@@ -515,8 +605,10 @@ class Expect {
515
605
  return this;
516
606
  }
517
607
  notToBeSomeObject() {
608
+ this._expected = true;
609
+
518
610
  if (isSomeObject(this.value)) {
519
- throw new Exception({
611
+ throw new TestException({
520
612
  message: `${this.value} is some object`,
521
613
  code: 1055,
522
614
  status: "not-is-some-object",
@@ -526,8 +618,10 @@ class Expect {
526
618
  return this;
527
619
  }
528
620
  notToBeFunction() {
621
+ this._expected = true;
622
+
529
623
  if (isFunction(this.value)) {
530
- throw new Exception({
624
+ throw new TestException({
531
625
  message: `${this.value} is function`,
532
626
  code: 1056,
533
627
  status: "not-is-function",
@@ -537,8 +631,10 @@ class Expect {
537
631
  return this;
538
632
  }
539
633
  notToBeNumeric() {
634
+ this._expected = true;
635
+
540
636
  if (isNumeric(this.value)) {
541
- throw new Exception({
637
+ throw new TestException({
542
638
  message: `${this.value} is numeric`,
543
639
  code: 1057,
544
640
  status: "not-is-numeric",
@@ -548,8 +644,10 @@ class Expect {
548
644
  return this;
549
645
  }
550
646
  notToBeArray() {
647
+ this._expected = true;
648
+
551
649
  if (isArray(this.value)) {
552
- throw new Exception({
650
+ throw new TestException({
553
651
  message: `${this.value} is array`,
554
652
  code: 1058,
555
653
  status: "not-is-array",
@@ -559,8 +657,10 @@ class Expect {
559
657
  return this;
560
658
  }
561
659
  toBeEmptyArray() {
660
+ this._expected = true;
661
+
562
662
  if (isSomeArray(this.value)) {
563
- throw new Exception({
663
+ throw new TestException({
564
664
  message: `${this.value} is some array`,
565
665
  code: 1059,
566
666
  status: "to-be-empty-array",
@@ -570,8 +670,10 @@ class Expect {
570
670
  return this;
571
671
  }
572
672
  notToBeIterable() {
673
+ this._expected = true;
674
+
573
675
  if (isIterable(this.value)) {
574
- throw new Exception({
676
+ throw new TestException({
575
677
  message: `${this.value} is iterable`,
576
678
  code: 1060,
577
679
  status: "not-iterable",
@@ -581,8 +683,10 @@ class Expect {
581
683
  return this;
582
684
  }
583
685
  notToBeSubClassOf(type) {
686
+ this._expected = true;
687
+
584
688
  if (isSubClassOf(this.value, type)) {
585
- throw new Exception({
689
+ throw new TestException({
586
690
  message: `${this.value} is subclass of ${type}`,
587
691
  code: 1061,
588
692
  status: "not-subclassof",
@@ -592,8 +696,10 @@ class Expect {
592
696
  return this;
593
697
  }
594
698
  notToBeInstanceOf(type) {
699
+ this._expected = true;
700
+
595
701
  if (this.value instanceof type) {
596
- throw new Exception({
702
+ throw new TestException({
597
703
  message: `${this.value} is instance of ${type}`,
598
704
  code: 1062,
599
705
  status: "not-instanceof",
@@ -603,10 +709,12 @@ class Expect {
603
709
  return this;
604
710
  }
605
711
  doesNotMatch(pattern, flags) {
712
+ this._expected = true;
713
+
606
714
  const r = new RegExp(pattern, flags);
607
715
 
608
716
  if (r.test(this.value)) {
609
- throw new Exception({
717
+ throw new TestException({
610
718
  message: `${this.value} matches ${pattern}`,
611
719
  code: 1063,
612
720
  status: "not-match",
@@ -616,15 +724,17 @@ class Expect {
616
724
  return this;
617
725
  }
618
726
  toBeValid(fnValidation) {
727
+ this._expected = true;
728
+
619
729
  if (!isFunction(fnValidation)) {
620
- throw new Exception({
730
+ throw new TestException({
621
731
  message: `fnValidation is not function`,
622
732
  code: 1064,
623
733
  status: "to-be-valid",
624
734
  });
625
735
  }
626
736
  if (!fnValidation(this.value)) {
627
- throw new Exception({
737
+ throw new TestException({
628
738
  message: `${this.value} is not valid`,
629
739
  code: 1065,
630
740
  status: "to-be-valid",
@@ -634,15 +744,17 @@ class Expect {
634
744
  return this;
635
745
  }
636
746
  notToBeValid(fnValidation) {
747
+ this._expected = true;
748
+
637
749
  if (!isFunction(fnValidation)) {
638
- throw new Exception({
750
+ throw new TestException({
639
751
  message: `fnValidation is not function`,
640
752
  code: 1066,
641
753
  status: "not-to-be-valid",
642
754
  });
643
755
  }
644
756
  if (fnValidation(this.value)) {
645
- throw new Exception({
757
+ throw new TestException({
646
758
  message: `${this.value} is valid`,
647
759
  code: 1067,
648
760
  status: "not-to-be-valid",
@@ -652,8 +764,10 @@ class Expect {
652
764
  return this;
653
765
  }
654
766
  toThrow(ex, shape = false, strict = false) {
767
+ this._expected = true;
768
+
655
769
  if (!isFunction(this.value)) {
656
- throw new Exception({
770
+ throw new TestException({
657
771
  message: `given argument is not a function.`,
658
772
  code: 1012,
659
773
  status: "not-func",
@@ -670,7 +784,7 @@ class Expect {
670
784
  if (ex !== undefined) {
671
785
  if (isPrimitive(ex)) {
672
786
  if (e !== ex) {
673
- throw new Exception({
787
+ throw new TestException({
674
788
  message: `given function threw incorrect error.`,
675
789
  code: 1018,
676
790
  status: "incorrect-throw-error",
@@ -678,7 +792,7 @@ class Expect {
678
792
  }
679
793
  } else if (isFunction(ex)) {
680
794
  if (!(e instanceof ex)) {
681
- throw new Exception({
795
+ throw new TestException({
682
796
  message: `given function threw incorrect instance.`,
683
797
  code: 1019,
684
798
  status: "incorrect-throw-instance",
@@ -687,7 +801,7 @@ class Expect {
687
801
  } else if (isObject(ex)) {
688
802
  if (shape) {
689
803
  if (!equals(e, ex, strict)) {
690
- throw new Exception({
804
+ throw new TestException({
691
805
  message: `given function threw incorrect object shape.`,
692
806
  code: 1020,
693
807
  status: "incorrect-throw-shape",
@@ -695,7 +809,7 @@ class Expect {
695
809
  }
696
810
  } else {
697
811
  if (e !== ex) {
698
- throw new Exception({
812
+ throw new TestException({
699
813
  message: `given function threw incorrect object.`,
700
814
  code: 1021,
701
815
  status: "incorrect-throw-object",
@@ -704,7 +818,7 @@ class Expect {
704
818
  }
705
819
  } else {
706
820
  if (e !== ex) {
707
- throw new Exception({
821
+ throw new TestException({
708
822
  message: `given function threw incorrect value.`,
709
823
  code: 1022,
710
824
  status: "incorrect-throw-value",
@@ -715,7 +829,7 @@ class Expect {
715
829
  }
716
830
 
717
831
  if (ok) {
718
- throw new Exception({
832
+ throw new TestException({
719
833
  message: `given function ran without throwing any errors.`,
720
834
  code: 1013,
721
835
  status: "ran-to-completion",
@@ -725,8 +839,10 @@ class Expect {
725
839
  return this;
726
840
  }
727
841
  async toThrowAsync(ex, shape = false, strict = false) {
842
+ this._expected = true;
843
+
728
844
  if (!isFunction(this.value)) {
729
- throw new Exception({
845
+ throw new TestException({
730
846
  message: `given argument is not a function.`,
731
847
  code: 1012,
732
848
  status: "not-func",
@@ -743,7 +859,7 @@ class Expect {
743
859
  if (ex !== undefined) {
744
860
  if (isPrimitive(ex)) {
745
861
  if (e !== ex) {
746
- throw new Exception({
862
+ throw new TestException({
747
863
  message: `given function threw incorrect error.`,
748
864
  code: 1018,
749
865
  status: "incorrect-throw-error",
@@ -751,7 +867,7 @@ class Expect {
751
867
  }
752
868
  } else if (isFunction(ex)) {
753
869
  if (!(e instanceof ex)) {
754
- throw new Exception({
870
+ throw new TestException({
755
871
  message: `given function threw incorrect instance.`,
756
872
  code: 1019,
757
873
  status: "incorrect-throw-instance",
@@ -760,7 +876,7 @@ class Expect {
760
876
  } else if (isObject(ex)) {
761
877
  if (shape) {
762
878
  if (!equals(e, ex, strict)) {
763
- throw new Exception({
879
+ throw new TestException({
764
880
  message: `given function threw incorrect object shape.`,
765
881
  code: 1020,
766
882
  status: "incorrect-throw-shape",
@@ -768,7 +884,7 @@ class Expect {
768
884
  }
769
885
  } else {
770
886
  if (e !== ex) {
771
- throw new Exception({
887
+ throw new TestException({
772
888
  message: `given function threw incorrect object.`,
773
889
  code: 1021,
774
890
  status: "incorrect-throw-object",
@@ -777,7 +893,7 @@ class Expect {
777
893
  }
778
894
  } else {
779
895
  if (e !== ex) {
780
- throw new Exception({
896
+ throw new TestException({
781
897
  message: `given function threw incorrect value.`,
782
898
  code: 1022,
783
899
  status: "incorrect-throw-value",
@@ -788,7 +904,7 @@ class Expect {
788
904
  }
789
905
 
790
906
  if (ok) {
791
- throw new Exception({
907
+ throw new TestException({
792
908
  message: `given function ran without throwing any errors.`,
793
909
  code: 1013,
794
910
  status: "ran-to-completion",
@@ -798,8 +914,10 @@ class Expect {
798
914
  return this;
799
915
  }
800
916
  notToThrow(ex, shape = false, strict = false) {
917
+ this._expected = true;
918
+
801
919
  if (!isFunction(this.value)) {
802
- throw new Exception({
920
+ throw new TestException({
803
921
  message: `given argument is not a function.`,
804
922
  code: 1012,
805
923
  status: "not-func",
@@ -819,7 +937,7 @@ class Expect {
819
937
  if (ex !== undefined) {
820
938
  if (isPrimitive(ex)) {
821
939
  if (e === ex) {
822
- throw new Exception({
940
+ throw new TestException({
823
941
  message: `given function threw incorrect error.`,
824
942
  code: 1018,
825
943
  status: "incorrect-throw-error",
@@ -827,7 +945,7 @@ class Expect {
827
945
  }
828
946
  } else if (isFunction(ex)) {
829
947
  if (e instanceof ex) {
830
- throw new Exception({
948
+ throw new TestException({
831
949
  message: `given function threw incorrect instance.`,
832
950
  code: 1019,
833
951
  status: "incorrect-throw-instance",
@@ -836,7 +954,7 @@ class Expect {
836
954
  } else if (isObject(ex)) {
837
955
  if (shape) {
838
956
  if (equals(e, ex, strict)) {
839
- throw new Exception({
957
+ throw new TestException({
840
958
  message: `given function threw incorrect object shape.`,
841
959
  code: 1020,
842
960
  status: "incorrect-throw-shape",
@@ -844,7 +962,7 @@ class Expect {
844
962
  }
845
963
  } else {
846
964
  if (e === ex) {
847
- throw new Exception({
965
+ throw new TestException({
848
966
  message: `given function threw incorrect object.`,
849
967
  code: 1021,
850
968
  status: "incorrect-throw-object",
@@ -853,7 +971,7 @@ class Expect {
853
971
  }
854
972
  } else {
855
973
  if (e === ex) {
856
- throw new Exception({
974
+ throw new TestException({
857
975
  message: `given function threw incorrect value.`,
858
976
  code: 1022,
859
977
  status: "incorrect-throw-value",
@@ -864,7 +982,7 @@ class Expect {
864
982
  }
865
983
 
866
984
  if (ok) {
867
- throw new Exception({
985
+ throw new TestException({
868
986
  message: `given function threw an error.`,
869
987
  code: 1014,
870
988
  status: "ran-to-error",
@@ -875,8 +993,10 @@ class Expect {
875
993
  return this;
876
994
  }
877
995
  async notToThrowAsync(ex, shape = false, strict = false) {
996
+ this._expected = true;
997
+
878
998
  if (!isFunction(this.value)) {
879
- throw new Exception({
999
+ throw new TestException({
880
1000
  message: `given argument is not a function.`,
881
1001
  code: 1012,
882
1002
  status: "not-func",
@@ -896,7 +1016,7 @@ class Expect {
896
1016
  if (ex !== undefined) {
897
1017
  if (isPrimitive(ex)) {
898
1018
  if (e === ex) {
899
- throw new Exception({
1019
+ throw new TestException({
900
1020
  message: `given function threw incorrect error.`,
901
1021
  code: 1018,
902
1022
  status: "incorrect-throw-error",
@@ -904,7 +1024,7 @@ class Expect {
904
1024
  }
905
1025
  } else if (isFunction(ex)) {
906
1026
  if (e instanceof ex) {
907
- throw new Exception({
1027
+ throw new TestException({
908
1028
  message: `given function threw incorrect instance.`,
909
1029
  code: 1019,
910
1030
  status: "incorrect-throw-instance",
@@ -913,7 +1033,7 @@ class Expect {
913
1033
  } else if (isObject(ex)) {
914
1034
  if (shape) {
915
1035
  if (equals(e, ex, strict)) {
916
- throw new Exception({
1036
+ throw new TestException({
917
1037
  message: `given function threw incorrect object shape.`,
918
1038
  code: 1020,
919
1039
  status: "incorrect-throw-shape",
@@ -921,7 +1041,7 @@ class Expect {
921
1041
  }
922
1042
  } else {
923
1043
  if (e === ex) {
924
- throw new Exception({
1044
+ throw new TestException({
925
1045
  message: `given function threw incorrect object.`,
926
1046
  code: 1021,
927
1047
  status: "incorrect-throw-object",
@@ -930,7 +1050,7 @@ class Expect {
930
1050
  }
931
1051
  } else {
932
1052
  if (e === ex) {
933
- throw new Exception({
1053
+ throw new TestException({
934
1054
  message: `given function threw incorrect value.`,
935
1055
  code: 1022,
936
1056
  status: "incorrect-throw-value",
@@ -941,7 +1061,7 @@ class Expect {
941
1061
  }
942
1062
 
943
1063
  if (ok) {
944
- throw new Exception({
1064
+ throw new TestException({
945
1065
  message: `given function threw an error.`,
946
1066
  code: 1014,
947
1067
  status: "ran-to-error",
@@ -952,9 +1072,11 @@ class Expect {
952
1072
  return this;
953
1073
  }
954
1074
  toBeTruthy() {
1075
+ this._expected = true;
1076
+
955
1077
  if (this.value) {
956
1078
  } else {
957
- throw new Exception({
1079
+ throw new TestException({
958
1080
  message: `${this.value} is not truthy`,
959
1081
  code: 1015,
960
1082
  status: "not-truthy",
@@ -967,9 +1089,11 @@ class Expect {
967
1089
  return this.toBeTruthy();
968
1090
  }
969
1091
  toBeFalsy() {
1092
+ this._expected = true;
1093
+
970
1094
  if (!this.value) {
971
1095
  } else {
972
- throw new Exception({
1096
+ throw new TestException({
973
1097
  message: `${this.value} is not falsy`,
974
1098
  code: 1016,
975
1099
  status: "not-falsy",
@@ -982,9 +1106,11 @@ class Expect {
982
1106
  return this.toBeFalsy();
983
1107
  }
984
1108
  toBeNaN() {
1109
+ this._expected = true;
1110
+
985
1111
  if (isNaN(this.value)) {
986
1112
  } else {
987
- throw new Exception({
1113
+ throw new TestException({
988
1114
  message: `${this.value} is not NaN`,
989
1115
  code: 1017,
990
1116
  status: "not-nan",
@@ -994,9 +1120,11 @@ class Expect {
994
1120
  return this;
995
1121
  }
996
1122
  notToBeNaN() {
1123
+ this._expected = true;
1124
+
997
1125
  if (!isNaN(this.value)) {
998
1126
  } else {
999
- throw new Exception({
1127
+ throw new TestException({
1000
1128
  message: `${this.value} is NaN`,
1001
1129
  code: 1023,
1002
1130
  status: "is-nan",
@@ -1007,8 +1135,6 @@ class Expect {
1007
1135
  }
1008
1136
  }
1009
1137
 
1010
- const expect = (x) => new Expect(x);
1011
-
1012
1138
  class Test {
1013
1139
  constructor(name, fn) {
1014
1140
  this.name = name;
@@ -1019,8 +1145,14 @@ class Test {
1019
1145
  const start = new Date();
1020
1146
 
1021
1147
  if (isFunction(this.fn)) {
1148
+ const _expect = new Expect();
1149
+
1022
1150
  try {
1023
- const _result = this.fn(expect);
1151
+ const _result = this.fn((x) => {
1152
+ _expect.value = x;
1153
+
1154
+ return _expect;
1155
+ });
1024
1156
 
1025
1157
  if (_result && isFunction(_result.then)) {
1026
1158
  _result
@@ -1030,6 +1162,7 @@ class Test {
1030
1162
  test: this.name,
1031
1163
  result,
1032
1164
  time: new Date() - start,
1165
+ expected: _expect.expected,
1033
1166
  });
1034
1167
  })
1035
1168
  .catch((ex) => {
@@ -1037,7 +1170,8 @@ class Test {
1037
1170
  success: false,
1038
1171
  test: this.name,
1039
1172
  time: new Date() - start,
1040
- err: new Exception({
1173
+ expected: _expect.expected,
1174
+ err: new TestException({
1041
1175
  message: `test '${this.name}' failed.`,
1042
1176
  code: 501,
1043
1177
  status: "failed",
@@ -1051,6 +1185,7 @@ class Test {
1051
1185
  test: this.name,
1052
1186
  time: new Date() - start,
1053
1187
  result: _result,
1188
+ expected: _expect.expected,
1054
1189
  });
1055
1190
  }
1056
1191
  } catch (ex) {
@@ -1058,7 +1193,8 @@ class Test {
1058
1193
  success: false,
1059
1194
  test: this.name,
1060
1195
  time: new Date() - start,
1061
- err: new Exception({
1196
+ expected: _expect.expected,
1197
+ err: new TestException({
1062
1198
  message: `test '${this.name}' failed.`,
1063
1199
  code: 501,
1064
1200
  status: "failed",
@@ -1071,7 +1207,7 @@ class Test {
1071
1207
  success: false,
1072
1208
  test: this.name,
1073
1209
  time: new Date() - start,
1074
- err: new Exception({
1210
+ err: new TestException({
1075
1211
  message: `test '${this.name}' does not have a function to be called.`,
1076
1212
  code: 500,
1077
1213
  status: "no-func",
@@ -1082,38 +1218,39 @@ class Test {
1082
1218
  }
1083
1219
  }
1084
1220
 
1085
- const reset = "\x1b[0m"
1086
- const bright = "\x1b[1m"
1087
- const dim = "\x1b[2m"
1088
- const underscore = "\x1b[4m"
1089
- const blink = "\x1b[5m"
1090
- const reverse = "\x1b[7m"
1091
- const hidden = "\x1b[8m"
1092
-
1093
- const fgBlack = "\x1b[30m"
1094
- const fgRed = "\x1b[31m"
1095
- const fgGreen = "\x1b[32m"
1096
- const fgYellow = "\x1b[33m"
1097
- const fgBlue = "\x1b[34m"
1098
- const fgMagenta = "\x1b[35m"
1099
- const fgCyan = "\x1b[36m"
1100
- const fgWhite = "\x1b[37m"
1101
- const fgGray = "\x1b[90m"
1102
-
1103
- const bgBlack = "\x1b[40m"
1104
- const bgRed = "\x1b[41m"
1105
- const bgGreen = "\x1b[42m"
1106
- const bgYellow = "\x1b[43m"
1107
- const bgBlue = "\x1b[44m"
1108
- const bgMagenta = "\x1b[45m"
1109
- const bgCyan = "\x1b[46m"
1110
- const bgWhite = "\x1b[47m"
1111
- const bgGray = "\x1b[100m"
1221
+ const reset = "\x1b[0m";
1222
+ const bright = "\x1b[1m";
1223
+ const dim = "\x1b[2m";
1224
+ const underscore = "\x1b[4m";
1225
+ const blink = "\x1b[5m";
1226
+ const reverse = "\x1b[7m";
1227
+ const hidden = "\x1b[8m";
1228
+
1229
+ const fgBlack = "\x1b[30m";
1230
+ const fgRed = "\x1b[31m";
1231
+ const fgGreen = "\x1b[32m";
1232
+ const fgYellow = "\x1b[33m";
1233
+ const fgBlue = "\x1b[34m";
1234
+ const fgMagenta = "\x1b[35m";
1235
+ const fgCyan = "\x1b[36m";
1236
+ const fgWhite = "\x1b[37m";
1237
+ const fgGray = "\x1b[90m";
1238
+
1239
+ const bgBlack = "\x1b[40m";
1240
+ const bgRed = "\x1b[41m";
1241
+ const bgGreen = "\x1b[42m";
1242
+ const bgYellow = "\x1b[43m";
1243
+ const bgBlue = "\x1b[44m";
1244
+ const bgMagenta = "\x1b[45m";
1245
+ const bgCyan = "\x1b[46m";
1246
+ const bgWhite = "\x1b[47m";
1247
+ const bgGray = "\x1b[100m";
1112
1248
 
1113
1249
  class TestRunner {
1114
1250
  constructor() {
1115
1251
  this._passed = 0;
1116
1252
  this._failed = 0;
1253
+ this._unknown = 0;
1117
1254
  this._results = [];
1118
1255
  this._errors = [];
1119
1256
  }
@@ -1125,7 +1262,7 @@ class TestRunner {
1125
1262
  this._errors.push({
1126
1263
  index: i,
1127
1264
  test: test.name,
1128
- err: new Exception({
1265
+ err: new TestException({
1129
1266
  message: `onProgress failed for test '${test.name} at index ${i}'.`,
1130
1267
  code: 1500,
1131
1268
  status: "progress-failed",
@@ -1139,7 +1276,9 @@ class TestRunner {
1139
1276
 
1140
1277
  this._results.push(tr);
1141
1278
 
1142
- if (tr.success) {
1279
+ if (!tr.expected) {
1280
+ this._unknown++;
1281
+ } else if (tr.success) {
1143
1282
  this._passed++;
1144
1283
  } else {
1145
1284
  this._failed++;
@@ -1185,7 +1324,7 @@ class TestRunner {
1185
1324
  .then((_) => res(this.result))
1186
1325
  .catch((ex) => {
1187
1326
  this._errors.push({
1188
- err: new Exception({
1327
+ err: new TestException({
1189
1328
  message: `not all tests succeeded. check errors.`,
1190
1329
  code: 1503,
1191
1330
  status: "partial-finished",
@@ -1197,7 +1336,7 @@ class TestRunner {
1197
1336
  });
1198
1337
  } else {
1199
1338
  this._errors.push({
1200
- err: new Exception({
1339
+ err: new TestException({
1201
1340
  message: `invalid tests. expected array or a single test.`,
1202
1341
  code: 1502,
1203
1342
  status: "invalid-tests",
@@ -1208,7 +1347,7 @@ class TestRunner {
1208
1347
  }
1209
1348
  } else {
1210
1349
  this._errors.push({
1211
- err: new Exception({
1350
+ err: new TestException({
1212
1351
  message: `no tests given to be ran.`,
1213
1352
  code: 1501,
1214
1353
  status: "no-tests",
@@ -1234,7 +1373,9 @@ class TestRunner {
1234
1373
  if (detailed) {
1235
1374
  let message = "\n" + (i + 1) + ". ";
1236
1375
 
1237
- if (result.success) {
1376
+ if (!result.expected) {
1377
+ message += `${bright}${fgWhite}${result.test}: ${fgMagenta}expect not used${reset} ${t}`;
1378
+ } else if (result.success) {
1238
1379
  message += `${fgWhite}${result.test}: ${fgGreen}passed${reset} ${t}`;
1239
1380
  } else {
1240
1381
  message += `${bright}${fgWhite}${result.test}: ${fgRed}failed${reset} ${t}`;
@@ -1291,6 +1432,9 @@ class TestRunner {
1291
1432
  (this._failed > 0
1292
1433
  ? `${fgRed} ${this._failed} test(s) failed${reset}`
1293
1434
  : `0 tests failed${reset}`) +
1435
+ (this._unknown > 0
1436
+ ? `, ${fgMagenta} ${this._unknown} test(s) are unknown${reset}`
1437
+ : ``) +
1294
1438
  "\n";
1295
1439
 
1296
1440
  console.log(text);
@@ -1336,4 +1480,4 @@ class TestRunner {
1336
1480
  }
1337
1481
 
1338
1482
  export default TestRunner;
1339
- export { Test, Expect, expect };
1483
+ export { Test, Expect, TestException };