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