@locustjs/test 1.5.0 → 1.6.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
@@ -16,6 +16,7 @@ import {
16
16
  isIterable,
17
17
  isSomeArray,
18
18
  isSubClassOf,
19
+ isNullOrEmpty,
19
20
  } from "@locustjs/base";
20
21
  import { Exception } from "@locustjs/exception";
21
22
  import fs from "fs";
@@ -44,6 +45,19 @@ class Expect {
44
45
 
45
46
  return this;
46
47
  }
48
+ notToBe(value) {
49
+ this._expected = true;
50
+
51
+ if (this.value === value) {
52
+ throw new TestException({
53
+ message: `${value} is equal to ${this.value}`,
54
+ code: 1005,
55
+ status: "eq",
56
+ });
57
+ }
58
+
59
+ return this;
60
+ }
47
61
  toBeGt(value) {
48
62
  this._expected = true;
49
63
 
@@ -121,6 +135,19 @@ class Expect {
121
135
 
122
136
  return this;
123
137
  }
138
+ notToBeBetween(n, m) {
139
+ this._expected = true;
140
+
141
+ if (this.value >= n && this.value < m) {
142
+ throw new TestException({
143
+ message: `${this.value} is between ${n} and ${m}`,
144
+ code: 1044,
145
+ status: "not-between",
146
+ });
147
+ }
148
+
149
+ return this;
150
+ }
124
151
  toBeOfType(type) {
125
152
  this._expected = true;
126
153
 
@@ -134,6 +161,19 @@ class Expect {
134
161
 
135
162
  return this;
136
163
  }
164
+ notToBeOfType(type) {
165
+ this._expected = true;
166
+
167
+ if (typeof this.value === type) {
168
+ throw new TestException({
169
+ message: `${this.value} is of type ${type}`,
170
+ code: 1045,
171
+ status: "not-oftype",
172
+ });
173
+ }
174
+
175
+ return this;
176
+ }
137
177
  toBeString() {
138
178
  this._expected = true;
139
179
 
@@ -147,6 +187,19 @@ class Expect {
147
187
 
148
188
  return this;
149
189
  }
190
+ notToBeString() {
191
+ this._expected = true;
192
+
193
+ if (isString(this.value)) {
194
+ throw new TestException({
195
+ message: `${this.value} is string`,
196
+ code: 1046,
197
+ status: "not-is-string",
198
+ });
199
+ }
200
+
201
+ return this;
202
+ }
150
203
  toBeSomeString() {
151
204
  this._expected = true;
152
205
  if (!isSomeString(this.value)) {
@@ -159,565 +212,574 @@ class Expect {
159
212
 
160
213
  return this;
161
214
  }
162
- toBeNumber() {
215
+ notToBeSomeString() {
163
216
  this._expected = true;
164
217
 
165
- if (!isNumber(this.value)) {
218
+ if (isSomeString(this.value)) {
166
219
  throw new TestException({
167
- message: `${this.value} is not number`,
168
- code: 1028,
169
- status: "is-number",
220
+ message: `${this.value} is some string`,
221
+ code: 1047,
222
+ status: "not-is-some-string",
170
223
  });
171
224
  }
172
225
 
173
226
  return this;
174
227
  }
175
- toBeDate() {
228
+ toBeNumber() {
176
229
  this._expected = true;
177
230
 
178
- if (!isDate(this.value)) {
231
+ if (!isNumber(this.value)) {
179
232
  throw new TestException({
180
- message: `${this.value} is not date`,
181
- code: 1029,
182
- status: "is-date",
233
+ message: `${this.value} is not number`,
234
+ code: 1028,
235
+ status: "is-number",
183
236
  });
184
237
  }
185
238
 
186
239
  return this;
187
240
  }
188
- toBeBool() {
241
+ notToBeNumber() {
189
242
  this._expected = true;
190
243
 
191
- if (!isBool(this.value)) {
244
+ if (isNumber(this.value)) {
192
245
  throw new TestException({
193
- message: `${this.value} is not bool`,
194
- code: 1030,
195
- status: "is-bool",
246
+ message: `${this.value} is number`,
247
+ code: 1048,
248
+ status: "not-is-number",
196
249
  });
197
250
  }
198
251
 
199
252
  return this;
200
253
  }
201
- toBeBasicType() {
254
+ toBeDate() {
202
255
  this._expected = true;
203
256
 
204
- if (!isBasic(this.value)) {
257
+ if (!isDate(this.value)) {
205
258
  throw new TestException({
206
- message: `${this.value} is not basic type`,
207
- code: 1031,
208
- status: "is-basic-type",
259
+ message: `${this.value} is not date`,
260
+ code: 1029,
261
+ status: "is-date",
209
262
  });
210
263
  }
211
264
 
212
265
  return this;
213
266
  }
214
- toBePrimitive() {
267
+ notToBeDate() {
215
268
  this._expected = true;
216
269
 
217
- if (!isPrimitive(this.value)) {
270
+ if (isDate(this.value)) {
218
271
  throw new TestException({
219
- message: `${this.value} is not primitive type`,
220
- code: 1032,
221
- status: "is-primitive",
272
+ message: `${this.value} is date`,
273
+ code: 1049,
274
+ status: "not-is-date",
222
275
  });
223
276
  }
224
277
 
225
278
  return this;
226
279
  }
227
- toBeEmpty() {
280
+ toBeBool() {
228
281
  this._expected = true;
229
282
 
230
- if (!isEmpty(this.value)) {
283
+ if (!isBool(this.value)) {
231
284
  throw new TestException({
232
- message: `${this.value} is not empty`,
233
- code: 1033,
234
- status: "is-empty",
285
+ message: `${this.value} is not bool`,
286
+ code: 1030,
287
+ status: "is-bool",
235
288
  });
236
289
  }
237
290
 
238
291
  return this;
239
292
  }
240
- toBeObject() {
293
+ notToBeBool() {
241
294
  this._expected = true;
242
295
 
243
- if (!isObject(this.value)) {
296
+ if (isBool(this.value)) {
244
297
  throw new TestException({
245
- message: `${this.value} is not object`,
246
- code: 1034,
247
- status: "is-object",
298
+ message: `${this.value} is bool`,
299
+ code: 1050,
300
+ status: "not-is-bool",
248
301
  });
249
302
  }
250
303
 
251
304
  return this;
252
305
  }
253
- toBeSomeObject() {
306
+ toBeBasicType() {
254
307
  this._expected = true;
255
308
 
256
- if (!isSomeObject(this.value)) {
309
+ if (!isBasic(this.value)) {
257
310
  throw new TestException({
258
- message: `${this.value} is not some object`,
259
- code: 1035,
260
- status: "is-some-object",
311
+ message: `${this.value} is not basic type`,
312
+ code: 1031,
313
+ status: "is-basic-type",
261
314
  });
262
315
  }
263
316
 
264
317
  return this;
265
318
  }
266
- toBeFunction() {
319
+ notToBeBasicType() {
267
320
  this._expected = true;
268
321
 
269
- if (!isFunction(this.value)) {
322
+ if (isBasic(this.value)) {
270
323
  throw new TestException({
271
- message: `${this.value} is not function`,
272
- code: 1036,
273
- status: "is-function",
324
+ message: `${this.value} is basic type`,
325
+ code: 1051,
326
+ status: "not-is-basic-type",
274
327
  });
275
328
  }
276
329
 
277
330
  return this;
278
331
  }
279
- toBeNumeric() {
332
+ toBePrimitive() {
280
333
  this._expected = true;
281
334
 
282
- if (!isNumeric(this.value)) {
335
+ if (!isPrimitive(this.value)) {
283
336
  throw new TestException({
284
- message: `${this.value} is not numeric`,
285
- code: 1037,
286
- status: "is-numeric",
337
+ message: `${this.value} is not primitive type`,
338
+ code: 1032,
339
+ status: "is-primitive",
287
340
  });
288
341
  }
289
342
 
290
343
  return this;
291
344
  }
292
- toBeArray() {
345
+ notToBePrimitive() {
293
346
  this._expected = true;
294
347
 
295
- if (!isArray(this.value)) {
348
+ if (isPrimitive(this.value)) {
296
349
  throw new TestException({
297
- message: `${this.value} is not array`,
298
- code: 1038,
299
- status: "is-array",
350
+ message: `${this.value} is primitive type`,
351
+ code: 1052,
352
+ status: "not-is-primitive",
300
353
  });
301
354
  }
302
355
 
303
356
  return this;
304
357
  }
305
- toBeSomeArray() {
358
+ toBeEmpty() {
306
359
  this._expected = true;
307
360
 
308
- if (!isSomeArray(this.value)) {
361
+ if (!isEmpty(this.value)) {
309
362
  throw new TestException({
310
- message: `${this.value} is not some array`,
311
- code: 1039,
312
- status: "is-some-array",
363
+ message: `${this.value} is not empty`,
364
+ code: 1033,
365
+ status: "is-empty",
313
366
  });
314
367
  }
315
368
 
316
369
  return this;
317
370
  }
318
- toBeIterable() {
371
+ notToBeEmpty() {
319
372
  this._expected = true;
320
373
 
321
- if (!isIterable(this.value)) {
374
+ if (isEmpty(this.value)) {
322
375
  throw new TestException({
323
- message: `${this.value} is not iterable`,
324
- code: 1040,
325
- status: "is-iterable",
376
+ message: `${this.value} is empty`,
377
+ code: 1053,
378
+ status: "not-is-empty",
326
379
  });
327
380
  }
328
381
 
329
382
  return this;
330
383
  }
331
- toBeSubClassOf(type) {
384
+ toBeObject() {
332
385
  this._expected = true;
333
386
 
334
- if (!isSubClassOf(this.value, type)) {
387
+ if (!isObject(this.value)) {
335
388
  throw new TestException({
336
- message: `${this.value} is not subclass of ${type}`,
337
- code: 1041,
338
- status: "is-subclass-of",
389
+ message: `${this.value} is not object`,
390
+ code: 1034,
391
+ status: "is-object",
339
392
  });
340
393
  }
341
394
 
342
395
  return this;
343
396
  }
344
- toBeInstanceOf(type) {
397
+ notToBeObject() {
345
398
  this._expected = true;
346
399
 
347
- if (!(this.value instanceof type)) {
400
+ if (isObject(this.value)) {
348
401
  throw new TestException({
349
- message: `${this.value} is not instance of ${type}`,
350
- code: 1042,
351
- status: "instanceof",
402
+ message: `${this.value} is object`,
403
+ code: 1054,
404
+ status: "not-is-object",
352
405
  });
353
406
  }
354
407
 
355
408
  return this;
356
409
  }
357
- toMatch(pattern, flags) {
410
+ toBeSomeObject() {
358
411
  this._expected = true;
359
412
 
360
- const r = new RegExp(pattern, flags);
361
-
362
- if (!r.test(this.value)) {
413
+ if (!isSomeObject(this.value)) {
363
414
  throw new TestException({
364
- message: `${this.value} does not match ${pattern}`,
365
- code: 1043,
366
- status: "match",
415
+ message: `${this.value} is not some object`,
416
+ code: 1035,
417
+ status: "is-some-object",
367
418
  });
368
419
  }
369
420
 
370
421
  return this;
371
422
  }
372
- notToBe(value) {
423
+ notToBeSomeObject() {
373
424
  this._expected = true;
374
425
 
375
- if (this.value === value) {
426
+ if (isSomeObject(this.value)) {
376
427
  throw new TestException({
377
- message: `${value} is equal to ${this.value}`,
378
- code: 1005,
379
- status: "eq",
428
+ message: `${this.value} is some object`,
429
+ code: 1055,
430
+ status: "not-is-some-object",
380
431
  });
381
432
  }
382
433
 
383
434
  return this;
384
435
  }
385
- toBeDefined() {
436
+ toBeFunction() {
386
437
  this._expected = true;
387
438
 
388
- if (this.value === undefined) {
439
+ if (!isFunction(this.value)) {
389
440
  throw new TestException({
390
- message: `value is undefined`,
391
- code: 1006,
392
- status: "undefined",
441
+ message: `${this.value} is not function`,
442
+ code: 1036,
443
+ status: "is-function",
393
444
  });
394
445
  }
395
446
 
396
447
  return this;
397
448
  }
398
- toBeUndefined() {
449
+ notToBeFunction() {
399
450
  this._expected = true;
400
451
 
401
- if (this.value !== undefined) {
452
+ if (isFunction(this.value)) {
402
453
  throw new TestException({
403
- message: `value is defined`,
404
- code: 1007,
405
- status: "defined",
454
+ message: `${this.value} is function`,
455
+ code: 1056,
456
+ status: "not-is-function",
406
457
  });
407
458
  }
408
459
 
409
460
  return this;
410
461
  }
411
- toBeNull() {
462
+ toBeNumeric() {
412
463
  this._expected = true;
413
464
 
414
- if (this.value !== null) {
465
+ if (!isNumeric(this.value)) {
415
466
  throw new TestException({
416
- message: `value is not null`,
417
- code: 1008,
418
- status: "not-null",
467
+ message: `${this.value} is not numeric`,
468
+ code: 1037,
469
+ status: "is-numeric",
419
470
  });
420
471
  }
421
472
 
422
473
  return this;
423
474
  }
424
- notToBeNull() {
475
+ notToBeNumeric() {
425
476
  this._expected = true;
426
477
 
427
- if (this.value === null) {
478
+ if (isNumeric(this.value)) {
428
479
  throw new TestException({
429
- message: `value is null`,
430
- code: 1009,
431
- status: "null",
480
+ message: `${this.value} is numeric`,
481
+ code: 1057,
482
+ status: "not-is-numeric",
432
483
  });
433
484
  }
434
485
 
435
486
  return this;
436
487
  }
437
- toBeNullOrUndefined() {
488
+ toBeArray() {
438
489
  this._expected = true;
439
490
 
440
- if (this.value == null) {
441
- } else {
491
+ if (!isArray(this.value)) {
442
492
  throw new TestException({
443
- message: `value is not null/undefined`,
444
- code: 1010,
445
- status: "not-null-or-undefined",
493
+ message: `${this.value} is not array`,
494
+ code: 1038,
495
+ status: "is-array",
446
496
  });
447
497
  }
448
498
 
449
499
  return this;
450
500
  }
451
- notToBeNullOrUndefined() {
501
+ notToBeArray() {
452
502
  this._expected = true;
453
503
 
454
- if (this.value == null) {
504
+ if (isArray(this.value)) {
455
505
  throw new TestException({
456
- message: `value is null/undefined`,
457
- code: 1011,
458
- status: "null-or-undefined",
506
+ message: `${this.value} is array`,
507
+ code: 1058,
508
+ status: "not-is-array",
459
509
  });
460
510
  }
461
511
 
462
512
  return this;
463
513
  }
464
- notToBeBetween(n, m) {
514
+ toBeSomeArray() {
465
515
  this._expected = true;
466
516
 
467
- if (this.value >= n && this.value < m) {
517
+ if (!isSomeArray(this.value)) {
468
518
  throw new TestException({
469
- message: `${this.value} is between ${n} and ${m}`,
470
- code: 1044,
471
- status: "not-between",
519
+ message: `${this.value} is not some array`,
520
+ code: 1039,
521
+ status: "is-some-array",
472
522
  });
473
523
  }
474
524
 
475
525
  return this;
476
526
  }
477
- notToBeOfType(type) {
527
+ notToBeSomeArray() {
478
528
  this._expected = true;
479
529
 
480
- if (typeof this.value === type) {
530
+ if (isArray(this.value)) {
531
+ throw new TestException({
532
+ message: `${this.value} is array`,
533
+ code: 1068,
534
+ status: "is-array",
535
+ });
536
+ }
537
+ if (this.value.length) {
481
538
  throw new TestException({
482
- message: `${this.value} is of type ${type}`,
483
- code: 1045,
484
- status: "not-oftype",
539
+ message: `${this.value} is array`,
540
+ code: 1069,
541
+ status: "is-some-array",
485
542
  });
486
543
  }
487
544
 
488
545
  return this;
489
546
  }
490
- notToBeString() {
547
+ toBeIterable() {
491
548
  this._expected = true;
492
549
 
493
- if (isString(this.value)) {
550
+ if (!isIterable(this.value)) {
494
551
  throw new TestException({
495
- message: `${this.value} is string`,
496
- code: 1046,
497
- status: "not-is-string",
552
+ message: `${this.value} is not iterable`,
553
+ code: 1040,
554
+ status: "is-iterable",
498
555
  });
499
556
  }
500
557
 
501
558
  return this;
502
559
  }
503
- notToBeSomeString() {
560
+ notToBeIterable() {
504
561
  this._expected = true;
505
562
 
506
- if (isSomeString(this.value)) {
563
+ if (isIterable(this.value)) {
507
564
  throw new TestException({
508
- message: `${this.value} is some string`,
509
- code: 1047,
510
- status: "not-is-some-string",
565
+ message: `${this.value} is iterable`,
566
+ code: 1060,
567
+ status: "not-iterable",
511
568
  });
512
569
  }
513
570
 
514
571
  return this;
515
572
  }
516
- notToBeNumber() {
573
+ toBeSubClassOf(type) {
517
574
  this._expected = true;
518
575
 
519
- if (isNumber(this.value)) {
576
+ if (!isSubClassOf(this.value, type)) {
520
577
  throw new TestException({
521
- message: `${this.value} is number`,
522
- code: 1048,
523
- status: "not-is-number",
578
+ message: `${this.value} is not subclass of ${type}`,
579
+ code: 1041,
580
+ status: "is-subclass-of",
524
581
  });
525
582
  }
526
583
 
527
584
  return this;
528
585
  }
529
- notToBeDate() {
586
+ notToBeSubClassOf(type) {
530
587
  this._expected = true;
531
588
 
532
- if (isDate(this.value)) {
589
+ if (isSubClassOf(this.value, type)) {
533
590
  throw new TestException({
534
- message: `${this.value} is date`,
535
- code: 1049,
536
- status: "not-is-date",
591
+ message: `${this.value} is subclass of ${type}`,
592
+ code: 1061,
593
+ status: "not-subclassof",
537
594
  });
538
595
  }
539
596
 
540
597
  return this;
541
598
  }
542
- notToBeBool() {
599
+ toBeInstanceOf(type) {
543
600
  this._expected = true;
544
601
 
545
- if (isBool(this.value)) {
602
+ if (!(this.value instanceof type)) {
546
603
  throw new TestException({
547
- message: `${this.value} is bool`,
548
- code: 1050,
549
- status: "not-is-bool",
604
+ message: `${this.value} is not instance of ${type}`,
605
+ code: 1042,
606
+ status: "instanceof",
550
607
  });
551
608
  }
552
609
 
553
610
  return this;
554
611
  }
555
- notToBeBasicType() {
612
+ notToBeInstanceOf(type) {
556
613
  this._expected = true;
557
614
 
558
- if (isBasic(this.value)) {
615
+ if (this.value instanceof type) {
559
616
  throw new TestException({
560
- message: `${this.value} is basic type`,
561
- code: 1051,
562
- status: "not-is-basic-type",
617
+ message: `${this.value} is instance of ${type}`,
618
+ code: 1062,
619
+ status: "not-instanceof",
563
620
  });
564
621
  }
565
622
 
566
623
  return this;
567
624
  }
568
- notToBePrimitive() {
625
+ toMatch(pattern, flags) {
569
626
  this._expected = true;
570
627
 
571
- if (isPrimitive(this.value)) {
628
+ const r = new RegExp(pattern, flags);
629
+
630
+ if (!r.test(this.value)) {
572
631
  throw new TestException({
573
- message: `${this.value} is primitive type`,
574
- code: 1052,
575
- status: "not-is-primitive",
632
+ message: `${this.value} does not match ${pattern}`,
633
+ code: 1043,
634
+ status: "match",
576
635
  });
577
636
  }
578
637
 
579
638
  return this;
580
639
  }
581
- notToBeEmpty() {
640
+ notToMatch(pattern, flags) {
582
641
  this._expected = true;
583
642
 
584
- if (isEmpty(this.value)) {
643
+ const r = new RegExp(pattern, flags);
644
+
645
+ if (r.test(this.value)) {
585
646
  throw new TestException({
586
- message: `${this.value} is empty`,
587
- code: 1053,
588
- status: "not-is-empty",
647
+ message: `${this.value} matches ${pattern}`,
648
+ code: 1070,
649
+ status: "match",
589
650
  });
590
651
  }
591
652
 
592
653
  return this;
593
654
  }
594
- notToBeObject() {
655
+ doesNotMatch(pattern, flags) {
595
656
  this._expected = true;
596
657
 
597
- if (isObject(this.value)) {
658
+ const r = new RegExp(pattern, flags);
659
+
660
+ if (r.test(this.value)) {
598
661
  throw new TestException({
599
- message: `${this.value} is object`,
600
- code: 1054,
601
- status: "not-is-object",
662
+ message: `${this.value} matches ${pattern}`,
663
+ code: 1063,
664
+ status: "not-match",
602
665
  });
603
666
  }
604
667
 
605
668
  return this;
606
669
  }
607
- notToBeSomeObject() {
670
+ toBeDefined() {
608
671
  this._expected = true;
609
672
 
610
- if (isSomeObject(this.value)) {
673
+ if (this.value === undefined) {
611
674
  throw new TestException({
612
- message: `${this.value} is some object`,
613
- code: 1055,
614
- status: "not-is-some-object",
675
+ message: `value is undefined`,
676
+ code: 1006,
677
+ status: "undefined",
615
678
  });
616
679
  }
617
680
 
618
681
  return this;
619
682
  }
620
- notToBeFunction() {
683
+ notToBeDefined() {
621
684
  this._expected = true;
622
685
 
623
- if (isFunction(this.value)) {
686
+ if (this.value !== undefined) {
624
687
  throw new TestException({
625
- message: `${this.value} is function`,
626
- code: 1056,
627
- status: "not-is-function",
688
+ message: `value is defined`,
689
+ code: 1071,
690
+ status: "defined",
628
691
  });
629
692
  }
630
693
 
631
694
  return this;
632
695
  }
633
- notToBeNumeric() {
696
+ toBeUndefined() {
634
697
  this._expected = true;
635
698
 
636
- if (isNumeric(this.value)) {
699
+ if (this.value !== undefined) {
637
700
  throw new TestException({
638
- message: `${this.value} is numeric`,
639
- code: 1057,
640
- status: "not-is-numeric",
701
+ message: `value is defined`,
702
+ code: 1007,
703
+ status: "defined",
641
704
  });
642
705
  }
643
706
 
644
707
  return this;
645
708
  }
646
- notToBeArray() {
709
+ notToBeUndefined() {
647
710
  this._expected = true;
648
711
 
649
- if (isArray(this.value)) {
712
+ if (this.value === undefined) {
650
713
  throw new TestException({
651
- message: `${this.value} is array`,
652
- code: 1058,
653
- status: "not-is-array",
714
+ message: `value is undefined`,
715
+ code: 1072,
716
+ status: "undefined",
654
717
  });
655
718
  }
656
719
 
657
720
  return this;
658
721
  }
659
- toBeEmptyArray() {
722
+ toBeNull() {
660
723
  this._expected = true;
661
724
 
662
- if (isSomeArray(this.value)) {
725
+ if (this.value !== null) {
663
726
  throw new TestException({
664
- message: `${this.value} is some array`,
665
- code: 1059,
666
- status: "to-be-empty-array",
727
+ message: `value is not null`,
728
+ code: 1008,
729
+ status: "not-null",
667
730
  });
668
731
  }
669
732
 
670
733
  return this;
671
734
  }
672
- notToBeIterable() {
735
+ notToBeNull() {
673
736
  this._expected = true;
674
737
 
675
- if (isIterable(this.value)) {
738
+ if (this.value === null) {
676
739
  throw new TestException({
677
- message: `${this.value} is iterable`,
678
- code: 1060,
679
- status: "not-iterable",
740
+ message: `value is null`,
741
+ code: 1009,
742
+ status: "null",
680
743
  });
681
744
  }
682
745
 
683
746
  return this;
684
747
  }
685
- notToBeSubClassOf(type) {
748
+ toBeNullOrUndefined() {
686
749
  this._expected = true;
687
750
 
688
- if (isSubClassOf(this.value, type)) {
751
+ if (this.value == null) {
752
+ } else {
689
753
  throw new TestException({
690
- message: `${this.value} is subclass of ${type}`,
691
- code: 1061,
692
- status: "not-subclassof",
754
+ message: `value is not null/undefined`,
755
+ code: 1010,
756
+ status: "not-null-or-undefined",
693
757
  });
694
758
  }
695
759
 
696
760
  return this;
697
761
  }
698
- notToBeInstanceOf(type) {
762
+ notToBeNullOrUndefined() {
699
763
  this._expected = true;
700
764
 
701
- if (this.value instanceof type) {
765
+ if (this.value == null) {
702
766
  throw new TestException({
703
- message: `${this.value} is instance of ${type}`,
704
- code: 1062,
705
- status: "not-instanceof",
767
+ message: `value is null/undefined`,
768
+ code: 1011,
769
+ status: "null-or-undefined",
706
770
  });
707
771
  }
708
772
 
709
773
  return this;
710
774
  }
711
- doesNotMatch(pattern, flags) {
775
+ toBeEmptyArray() {
712
776
  this._expected = true;
713
777
 
714
- const r = new RegExp(pattern, flags);
715
-
716
- if (r.test(this.value)) {
778
+ if (isSomeArray(this.value)) {
717
779
  throw new TestException({
718
- message: `${this.value} matches ${pattern}`,
719
- code: 1063,
720
- status: "not-match",
780
+ message: `${this.value} is some array`,
781
+ code: 1059,
782
+ status: "to-be-empty-array",
721
783
  });
722
784
  }
723
785
 
@@ -838,7 +900,7 @@ class Expect {
838
900
 
839
901
  return this;
840
902
  }
841
- async toThrowAsync(ex, shape = false, strict = false) {
903
+ notToThrow(ex, shape = false, strict = false) {
842
904
  this._expected = true;
843
905
 
844
906
  if (!isFunction(this.value)) {
@@ -849,16 +911,19 @@ class Expect {
849
911
  });
850
912
  }
851
913
 
852
- let ok = false;
914
+ let ok = true;
915
+ let error;
853
916
 
854
917
  try {
855
- await this.value();
918
+ this.value();
856
919
 
857
- ok = true;
920
+ ok = false;
858
921
  } catch (e) {
922
+ error = e;
923
+
859
924
  if (ex !== undefined) {
860
925
  if (isPrimitive(ex)) {
861
- if (e !== ex) {
926
+ if (e === ex) {
862
927
  throw new TestException({
863
928
  message: `given function threw incorrect error.`,
864
929
  code: 1018,
@@ -866,7 +931,7 @@ class Expect {
866
931
  });
867
932
  }
868
933
  } else if (isFunction(ex)) {
869
- if (!(e instanceof ex)) {
934
+ if (e instanceof ex) {
870
935
  throw new TestException({
871
936
  message: `given function threw incorrect instance.`,
872
937
  code: 1019,
@@ -875,7 +940,7 @@ class Expect {
875
940
  }
876
941
  } else if (isObject(ex)) {
877
942
  if (shape) {
878
- if (!equals(e, ex, strict)) {
943
+ if (equals(e, ex, strict)) {
879
944
  throw new TestException({
880
945
  message: `given function threw incorrect object shape.`,
881
946
  code: 1020,
@@ -883,7 +948,7 @@ class Expect {
883
948
  });
884
949
  }
885
950
  } else {
886
- if (e !== ex) {
951
+ if (e === ex) {
887
952
  throw new TestException({
888
953
  message: `given function threw incorrect object.`,
889
954
  code: 1021,
@@ -892,7 +957,7 @@ class Expect {
892
957
  }
893
958
  }
894
959
  } else {
895
- if (e !== ex) {
960
+ if (e === ex) {
896
961
  throw new TestException({
897
962
  message: `given function threw incorrect value.`,
898
963
  code: 1022,
@@ -905,15 +970,16 @@ class Expect {
905
970
 
906
971
  if (ok) {
907
972
  throw new TestException({
908
- message: `given function ran without throwing any errors.`,
909
- code: 1013,
910
- status: "ran-to-completion",
973
+ message: `given function threw an error.`,
974
+ code: 1014,
975
+ status: "ran-to-error",
976
+ innerException: error,
911
977
  });
912
978
  }
913
979
 
914
980
  return this;
915
981
  }
916
- notToThrow(ex, shape = false, strict = false) {
982
+ async toThrowAsync(ex, shape = false, strict = false) {
917
983
  this._expected = true;
918
984
 
919
985
  if (!isFunction(this.value)) {
@@ -924,19 +990,16 @@ class Expect {
924
990
  });
925
991
  }
926
992
 
927
- let ok = true;
928
- let error;
993
+ let ok = false;
929
994
 
930
995
  try {
931
- this.value();
996
+ await this.value();
932
997
 
933
- ok = false;
998
+ ok = true;
934
999
  } catch (e) {
935
- error = e;
936
-
937
1000
  if (ex !== undefined) {
938
1001
  if (isPrimitive(ex)) {
939
- if (e === ex) {
1002
+ if (e !== ex) {
940
1003
  throw new TestException({
941
1004
  message: `given function threw incorrect error.`,
942
1005
  code: 1018,
@@ -944,7 +1007,7 @@ class Expect {
944
1007
  });
945
1008
  }
946
1009
  } else if (isFunction(ex)) {
947
- if (e instanceof ex) {
1010
+ if (!(e instanceof ex)) {
948
1011
  throw new TestException({
949
1012
  message: `given function threw incorrect instance.`,
950
1013
  code: 1019,
@@ -953,7 +1016,7 @@ class Expect {
953
1016
  }
954
1017
  } else if (isObject(ex)) {
955
1018
  if (shape) {
956
- if (equals(e, ex, strict)) {
1019
+ if (!equals(e, ex, strict)) {
957
1020
  throw new TestException({
958
1021
  message: `given function threw incorrect object shape.`,
959
1022
  code: 1020,
@@ -961,7 +1024,7 @@ class Expect {
961
1024
  });
962
1025
  }
963
1026
  } else {
964
- if (e === ex) {
1027
+ if (e !== ex) {
965
1028
  throw new TestException({
966
1029
  message: `given function threw incorrect object.`,
967
1030
  code: 1021,
@@ -970,7 +1033,7 @@ class Expect {
970
1033
  }
971
1034
  }
972
1035
  } else {
973
- if (e === ex) {
1036
+ if (e !== ex) {
974
1037
  throw new TestException({
975
1038
  message: `given function threw incorrect value.`,
976
1039
  code: 1022,
@@ -983,10 +1046,9 @@ class Expect {
983
1046
 
984
1047
  if (ok) {
985
1048
  throw new TestException({
986
- message: `given function threw an error.`,
987
- code: 1014,
988
- status: "ran-to-error",
989
- innerException: error,
1049
+ message: `given function ran without throwing any errors.`,
1050
+ code: 1013,
1051
+ status: "ran-to-completion",
990
1052
  });
991
1053
  }
992
1054
 
@@ -1257,7 +1319,7 @@ class TestRunner {
1257
1319
  async _runSingle(test, onProgress, i) {
1258
1320
  if (isFunction(onProgress)) {
1259
1321
  try {
1260
- onProgress(i, test);
1322
+ onProgress({ source: this, test, index: i });
1261
1323
  } catch (ex) {
1262
1324
  this._errors.push({
1263
1325
  index: i,
@@ -1367,40 +1429,45 @@ class TestRunner {
1367
1429
  console.log("Finished.\n");
1368
1430
 
1369
1431
  for (let i = 0; i < this._results.length; i++) {
1370
- const result = this._results[i];
1371
- const t = `(${this._getTime(result.time)})`;
1432
+ const testResult = this._results[i];
1433
+ const t = `(${this._getTime(testResult.time)})`;
1372
1434
 
1373
1435
  if (detailed) {
1374
1436
  let message = "\n" + (i + 1) + ". ";
1375
-
1376
- if (!result.expected) {
1377
- message += `${bright}${fgWhite}${result.test}: ${fgMagenta}expect not used${reset} ${t}`;
1378
- } else if (result.success) {
1379
- message += `${fgWhite}${result.test}: ${fgGreen}passed${reset} ${t}`;
1437
+ let err = !isNullOrEmpty(testResult.err)
1438
+ ? testResult.err.toString().split("\n")
1439
+ : [];
1440
+
1441
+ err = err
1442
+ .map(
1443
+ (msg, i) =>
1444
+ `\t${
1445
+ i == err.length - 1
1446
+ ? `${fgYellow}`
1447
+ : `${fgGray}error ${testResult.err.code}: `
1448
+ }${msg}${reset}`
1449
+ )
1450
+ .join("\n");
1451
+
1452
+ if (!testResult.expected) {
1453
+ message += `${bright}${fgWhite}${testResult.test}: ${fgMagenta}expect not used${reset} ${t}`;
1454
+
1455
+ if (testResult.err) {
1456
+ message += "\n";
1457
+ message += `${fgGray}${err} ${reset}`;
1458
+ }
1459
+ } else if (testResult.success) {
1460
+ message += `${fgWhite}${testResult.test}: ${fgGreen}passed${reset} ${t}`;
1380
1461
  } else {
1381
- message += `${bright}${fgWhite}${result.test}: ${fgRed}failed${reset} ${t}`;
1462
+ message += `${bright}${fgWhite}${testResult.test}: ${fgRed}failed${reset} ${t}`;
1382
1463
  message += "\n";
1383
-
1384
- let err = result.err.toString().split("\n");
1385
-
1386
- err = err
1387
- .map(
1388
- (msg, i) =>
1389
- `\t${
1390
- i == err.length - 1
1391
- ? `${fgYellow}`
1392
- : `${fgGray}error ${result.err.code}: `
1393
- }${msg}${reset}`
1394
- )
1395
- .join("\n");
1396
-
1397
1464
  message += `${fgGray}${err} ${reset}`;
1398
1465
  }
1399
1466
 
1400
1467
  console.log(message);
1401
1468
  }
1402
1469
 
1403
- time += result.time;
1470
+ time += testResult.time;
1404
1471
  }
1405
1472
 
1406
1473
  if (detailed && this._errors.length) {
@@ -1472,10 +1539,27 @@ class TestRunner {
1472
1539
  console.log("writing tests outcome failed.\n" + ex);
1473
1540
  }
1474
1541
  }
1475
- static start(tests) {
1542
+ static async start(...tests) {
1476
1543
  const tr = new TestRunner();
1544
+ const lastArg = tests[tests.length - 1];
1545
+ const detailed = tests.length && isBool(lastArg) ? lastArg : false;
1546
+ let _tests = [];
1547
+
1548
+ for (let i = 0; i < tests.length; i++) {
1549
+ const t = tests[i];
1550
+
1551
+ if (i != tests.length - 1 || !isBool(t)) {
1552
+ if (isIterable(t)) {
1553
+ _tests = [..._tests, ...t];
1554
+ }
1555
+ }
1556
+ }
1557
+
1558
+ const result = await tr.run(_tests);
1559
+
1560
+ tr.report(detailed || result.failed > 0);
1477
1561
 
1478
- tr.run(tests).then((result) => tr.report(result.failed > 0));
1562
+ return { runner: tr, result };
1479
1563
  }
1480
1564
  }
1481
1565