@locustjs/test 1.3.1 → 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 +2 -2
- package/tests/index.js +12 -8
package/index.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { equals, isString, isNumber, isDate, isBool, isBasic, isPrimitive, isEmpty, isSomeString, isObject, isSomeObject, isFunction, isNumeric, isArray, isIterable, isSomeArray, isSubClassOf } from
|
|
2
|
-
import { Exception } from
|
|
3
|
-
import fs from
|
|
4
|
-
import path from
|
|
1
|
+
import { equals, isString, isNumber, isDate, isBool, isBasic, isPrimitive, isEmpty, isSomeString, isObject, isSomeObject, isFunction, isNumeric, isArray, isIterable, isSomeArray, isSubClassOf } from "@locustjs/base";
|
|
2
|
+
import { Exception } from "@locustjs/exception";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
5
|
class Expect {
|
|
6
6
|
constructor(value) {
|
|
7
7
|
this.value = value;
|
|
@@ -11,7 +11,7 @@ class Expect {
|
|
|
11
11
|
throw new Exception({
|
|
12
12
|
message: `${this.value} is not equal to ${value}`,
|
|
13
13
|
code: 1000,
|
|
14
|
-
status:
|
|
14
|
+
status: "not-eq"
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
return this;
|
|
@@ -21,47 +21,59 @@ class Expect {
|
|
|
21
21
|
throw new Exception({
|
|
22
22
|
message: `${this.value} is not greater than ${value}`,
|
|
23
23
|
code: 1001,
|
|
24
|
-
status:
|
|
24
|
+
status: "lte"
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
return this;
|
|
28
28
|
}
|
|
29
|
+
toBeGreaterThan(value) {
|
|
30
|
+
return this.toBeGt(value);
|
|
31
|
+
}
|
|
29
32
|
toBeGte(value) {
|
|
30
33
|
if (this.value < value) {
|
|
31
34
|
throw new Exception({
|
|
32
35
|
message: `${this.value} is not greater than or equal to ${value}`,
|
|
33
36
|
code: 1002,
|
|
34
|
-
status:
|
|
37
|
+
status: "lt"
|
|
35
38
|
});
|
|
36
39
|
}
|
|
37
40
|
return this;
|
|
38
41
|
}
|
|
42
|
+
toBeGreaterThanOrEqualTo(value) {
|
|
43
|
+
return this.toBeGte(value);
|
|
44
|
+
}
|
|
39
45
|
toBeLt(value) {
|
|
40
46
|
if (this.value >= value) {
|
|
41
47
|
throw new Exception({
|
|
42
48
|
message: `${this.value} is not less than ${value}`,
|
|
43
49
|
code: 1003,
|
|
44
|
-
status:
|
|
50
|
+
status: "gte"
|
|
45
51
|
});
|
|
46
52
|
}
|
|
47
53
|
return this;
|
|
48
54
|
}
|
|
55
|
+
toBeLowerThan(value) {
|
|
56
|
+
return this.toBeLt(value);
|
|
57
|
+
}
|
|
49
58
|
toBeLte(value) {
|
|
50
59
|
if (this.value > value) {
|
|
51
60
|
throw new Exception({
|
|
52
61
|
message: `${this.value} is not less than or equal to ${value}`,
|
|
53
62
|
code: 1004,
|
|
54
|
-
status:
|
|
63
|
+
status: "gt"
|
|
55
64
|
});
|
|
56
65
|
}
|
|
57
66
|
return this;
|
|
58
67
|
}
|
|
68
|
+
toBeLowerThanOrEqualTo(value) {
|
|
69
|
+
return this.toBeLte(value);
|
|
70
|
+
}
|
|
59
71
|
toBeBetween(n, m) {
|
|
60
72
|
if (!(this.value >= n && this.value < m)) {
|
|
61
73
|
throw new Exception({
|
|
62
74
|
message: `${this.value} is not between ${n} and ${m}`,
|
|
63
75
|
code: 1024,
|
|
64
|
-
status:
|
|
76
|
+
status: "between"
|
|
65
77
|
});
|
|
66
78
|
}
|
|
67
79
|
return this;
|
|
@@ -71,7 +83,7 @@ class Expect {
|
|
|
71
83
|
throw new Exception({
|
|
72
84
|
message: `${this.value} is not of type ${type}`,
|
|
73
85
|
code: 1025,
|
|
74
|
-
status:
|
|
86
|
+
status: "of-type"
|
|
75
87
|
});
|
|
76
88
|
}
|
|
77
89
|
return this;
|
|
@@ -81,7 +93,7 @@ class Expect {
|
|
|
81
93
|
throw new Exception({
|
|
82
94
|
message: `${this.value} is not string`,
|
|
83
95
|
code: 1026,
|
|
84
|
-
status:
|
|
96
|
+
status: "is-string"
|
|
85
97
|
});
|
|
86
98
|
}
|
|
87
99
|
return this;
|
|
@@ -91,7 +103,7 @@ class Expect {
|
|
|
91
103
|
throw new Exception({
|
|
92
104
|
message: `${this.value} is not some string`,
|
|
93
105
|
code: 1027,
|
|
94
|
-
status:
|
|
106
|
+
status: "is-some-string"
|
|
95
107
|
});
|
|
96
108
|
}
|
|
97
109
|
return this;
|
|
@@ -101,7 +113,7 @@ class Expect {
|
|
|
101
113
|
throw new Exception({
|
|
102
114
|
message: `${this.value} is not number`,
|
|
103
115
|
code: 1028,
|
|
104
|
-
status:
|
|
116
|
+
status: "is-number"
|
|
105
117
|
});
|
|
106
118
|
}
|
|
107
119
|
return this;
|
|
@@ -111,7 +123,7 @@ class Expect {
|
|
|
111
123
|
throw new Exception({
|
|
112
124
|
message: `${this.value} is not date`,
|
|
113
125
|
code: 1029,
|
|
114
|
-
status:
|
|
126
|
+
status: "is-date"
|
|
115
127
|
});
|
|
116
128
|
}
|
|
117
129
|
return this;
|
|
@@ -121,7 +133,7 @@ class Expect {
|
|
|
121
133
|
throw new Exception({
|
|
122
134
|
message: `${this.value} is not bool`,
|
|
123
135
|
code: 1030,
|
|
124
|
-
status:
|
|
136
|
+
status: "is-bool"
|
|
125
137
|
});
|
|
126
138
|
}
|
|
127
139
|
return this;
|
|
@@ -131,7 +143,7 @@ class Expect {
|
|
|
131
143
|
throw new Exception({
|
|
132
144
|
message: `${this.value} is not basic type`,
|
|
133
145
|
code: 1031,
|
|
134
|
-
status:
|
|
146
|
+
status: "is-basic-type"
|
|
135
147
|
});
|
|
136
148
|
}
|
|
137
149
|
return this;
|
|
@@ -141,7 +153,7 @@ class Expect {
|
|
|
141
153
|
throw new Exception({
|
|
142
154
|
message: `${this.value} is not primitive type`,
|
|
143
155
|
code: 1032,
|
|
144
|
-
status:
|
|
156
|
+
status: "is-primitive"
|
|
145
157
|
});
|
|
146
158
|
}
|
|
147
159
|
return this;
|
|
@@ -151,7 +163,7 @@ class Expect {
|
|
|
151
163
|
throw new Exception({
|
|
152
164
|
message: `${this.value} is not empty`,
|
|
153
165
|
code: 1033,
|
|
154
|
-
status:
|
|
166
|
+
status: "is-empty"
|
|
155
167
|
});
|
|
156
168
|
}
|
|
157
169
|
return this;
|
|
@@ -161,7 +173,7 @@ class Expect {
|
|
|
161
173
|
throw new Exception({
|
|
162
174
|
message: `${this.value} is not object`,
|
|
163
175
|
code: 1034,
|
|
164
|
-
status:
|
|
176
|
+
status: "is-object"
|
|
165
177
|
});
|
|
166
178
|
}
|
|
167
179
|
return this;
|
|
@@ -171,7 +183,7 @@ class Expect {
|
|
|
171
183
|
throw new Exception({
|
|
172
184
|
message: `${this.value} is not some object`,
|
|
173
185
|
code: 1035,
|
|
174
|
-
status:
|
|
186
|
+
status: "is-some-object"
|
|
175
187
|
});
|
|
176
188
|
}
|
|
177
189
|
return this;
|
|
@@ -181,7 +193,7 @@ class Expect {
|
|
|
181
193
|
throw new Exception({
|
|
182
194
|
message: `${this.value} is not function`,
|
|
183
195
|
code: 1036,
|
|
184
|
-
status:
|
|
196
|
+
status: "is-function"
|
|
185
197
|
});
|
|
186
198
|
}
|
|
187
199
|
return this;
|
|
@@ -191,7 +203,7 @@ class Expect {
|
|
|
191
203
|
throw new Exception({
|
|
192
204
|
message: `${this.value} is not numeric`,
|
|
193
205
|
code: 1037,
|
|
194
|
-
status:
|
|
206
|
+
status: "is-numeric"
|
|
195
207
|
});
|
|
196
208
|
}
|
|
197
209
|
return this;
|
|
@@ -201,7 +213,7 @@ class Expect {
|
|
|
201
213
|
throw new Exception({
|
|
202
214
|
message: `${this.value} is not array`,
|
|
203
215
|
code: 1038,
|
|
204
|
-
status:
|
|
216
|
+
status: "is-array"
|
|
205
217
|
});
|
|
206
218
|
}
|
|
207
219
|
return this;
|
|
@@ -211,7 +223,7 @@ class Expect {
|
|
|
211
223
|
throw new Exception({
|
|
212
224
|
message: `${this.value} is not some array`,
|
|
213
225
|
code: 1039,
|
|
214
|
-
status:
|
|
226
|
+
status: "is-some-array"
|
|
215
227
|
});
|
|
216
228
|
}
|
|
217
229
|
return this;
|
|
@@ -221,7 +233,7 @@ class Expect {
|
|
|
221
233
|
throw new Exception({
|
|
222
234
|
message: `${this.value} is not iterable`,
|
|
223
235
|
code: 1040,
|
|
224
|
-
status:
|
|
236
|
+
status: "is-iterable"
|
|
225
237
|
});
|
|
226
238
|
}
|
|
227
239
|
return this;
|
|
@@ -231,7 +243,7 @@ class Expect {
|
|
|
231
243
|
throw new Exception({
|
|
232
244
|
message: `${this.value} is not subclass of ${type}`,
|
|
233
245
|
code: 1041,
|
|
234
|
-
status:
|
|
246
|
+
status: "is-subclass-of"
|
|
235
247
|
});
|
|
236
248
|
}
|
|
237
249
|
return this;
|
|
@@ -241,7 +253,7 @@ class Expect {
|
|
|
241
253
|
throw new Exception({
|
|
242
254
|
message: `${this.value} is not instance of ${type}`,
|
|
243
255
|
code: 1042,
|
|
244
|
-
status:
|
|
256
|
+
status: "instanceof"
|
|
245
257
|
});
|
|
246
258
|
}
|
|
247
259
|
return this;
|
|
@@ -252,7 +264,7 @@ class Expect {
|
|
|
252
264
|
throw new Exception({
|
|
253
265
|
message: `${this.value} does not match ${pattern}`,
|
|
254
266
|
code: 1043,
|
|
255
|
-
status:
|
|
267
|
+
status: "match"
|
|
256
268
|
});
|
|
257
269
|
}
|
|
258
270
|
return this;
|
|
@@ -262,7 +274,7 @@ class Expect {
|
|
|
262
274
|
throw new Exception({
|
|
263
275
|
message: `${value} is equal to ${this.value}`,
|
|
264
276
|
code: 1005,
|
|
265
|
-
status:
|
|
277
|
+
status: "eq"
|
|
266
278
|
});
|
|
267
279
|
}
|
|
268
280
|
return this;
|
|
@@ -272,7 +284,7 @@ class Expect {
|
|
|
272
284
|
throw new Exception({
|
|
273
285
|
message: `value is undefined`,
|
|
274
286
|
code: 1006,
|
|
275
|
-
status:
|
|
287
|
+
status: "undefined"
|
|
276
288
|
});
|
|
277
289
|
}
|
|
278
290
|
return this;
|
|
@@ -282,7 +294,7 @@ class Expect {
|
|
|
282
294
|
throw new Exception({
|
|
283
295
|
message: `value is defined`,
|
|
284
296
|
code: 1007,
|
|
285
|
-
status:
|
|
297
|
+
status: "defined"
|
|
286
298
|
});
|
|
287
299
|
}
|
|
288
300
|
return this;
|
|
@@ -292,7 +304,7 @@ class Expect {
|
|
|
292
304
|
throw new Exception({
|
|
293
305
|
message: `value is not null`,
|
|
294
306
|
code: 1008,
|
|
295
|
-
status:
|
|
307
|
+
status: "not-null"
|
|
296
308
|
});
|
|
297
309
|
}
|
|
298
310
|
return this;
|
|
@@ -302,7 +314,7 @@ class Expect {
|
|
|
302
314
|
throw new Exception({
|
|
303
315
|
message: `value is null`,
|
|
304
316
|
code: 1009,
|
|
305
|
-
status:
|
|
317
|
+
status: "null"
|
|
306
318
|
});
|
|
307
319
|
}
|
|
308
320
|
return this;
|
|
@@ -312,7 +324,7 @@ class Expect {
|
|
|
312
324
|
throw new Exception({
|
|
313
325
|
message: `value is not null/undefined`,
|
|
314
326
|
code: 1010,
|
|
315
|
-
status:
|
|
327
|
+
status: "not-null-or-undefined"
|
|
316
328
|
});
|
|
317
329
|
}
|
|
318
330
|
return this;
|
|
@@ -322,7 +334,7 @@ class Expect {
|
|
|
322
334
|
throw new Exception({
|
|
323
335
|
message: `value is null/undefined`,
|
|
324
336
|
code: 1011,
|
|
325
|
-
status:
|
|
337
|
+
status: "null-or-undefined"
|
|
326
338
|
});
|
|
327
339
|
}
|
|
328
340
|
return this;
|
|
@@ -332,7 +344,7 @@ class Expect {
|
|
|
332
344
|
throw new Exception({
|
|
333
345
|
message: `${this.value} is between ${n} and ${m}`,
|
|
334
346
|
code: 1044,
|
|
335
|
-
status:
|
|
347
|
+
status: "not-between"
|
|
336
348
|
});
|
|
337
349
|
}
|
|
338
350
|
return this;
|
|
@@ -342,7 +354,7 @@ class Expect {
|
|
|
342
354
|
throw new Exception({
|
|
343
355
|
message: `${this.value} is of type ${type}`,
|
|
344
356
|
code: 1045,
|
|
345
|
-
status:
|
|
357
|
+
status: "not-oftype"
|
|
346
358
|
});
|
|
347
359
|
}
|
|
348
360
|
return this;
|
|
@@ -352,7 +364,7 @@ class Expect {
|
|
|
352
364
|
throw new Exception({
|
|
353
365
|
message: `${this.value} is string`,
|
|
354
366
|
code: 1046,
|
|
355
|
-
status:
|
|
367
|
+
status: "not-is-string"
|
|
356
368
|
});
|
|
357
369
|
}
|
|
358
370
|
return this;
|
|
@@ -362,7 +374,7 @@ class Expect {
|
|
|
362
374
|
throw new Exception({
|
|
363
375
|
message: `${this.value} is some string`,
|
|
364
376
|
code: 1047,
|
|
365
|
-
status:
|
|
377
|
+
status: "not-is-some-string"
|
|
366
378
|
});
|
|
367
379
|
}
|
|
368
380
|
return this;
|
|
@@ -372,7 +384,7 @@ class Expect {
|
|
|
372
384
|
throw new Exception({
|
|
373
385
|
message: `${this.value} is number`,
|
|
374
386
|
code: 1048,
|
|
375
|
-
status:
|
|
387
|
+
status: "not-is-number"
|
|
376
388
|
});
|
|
377
389
|
}
|
|
378
390
|
return this;
|
|
@@ -382,7 +394,7 @@ class Expect {
|
|
|
382
394
|
throw new Exception({
|
|
383
395
|
message: `${this.value} is date`,
|
|
384
396
|
code: 1049,
|
|
385
|
-
status:
|
|
397
|
+
status: "not-is-date"
|
|
386
398
|
});
|
|
387
399
|
}
|
|
388
400
|
return this;
|
|
@@ -392,7 +404,7 @@ class Expect {
|
|
|
392
404
|
throw new Exception({
|
|
393
405
|
message: `${this.value} is bool`,
|
|
394
406
|
code: 1050,
|
|
395
|
-
status:
|
|
407
|
+
status: "not-is-bool"
|
|
396
408
|
});
|
|
397
409
|
}
|
|
398
410
|
return this;
|
|
@@ -402,7 +414,7 @@ class Expect {
|
|
|
402
414
|
throw new Exception({
|
|
403
415
|
message: `${this.value} is basic type`,
|
|
404
416
|
code: 1051,
|
|
405
|
-
status:
|
|
417
|
+
status: "not-is-basic-type"
|
|
406
418
|
});
|
|
407
419
|
}
|
|
408
420
|
return this;
|
|
@@ -412,7 +424,7 @@ class Expect {
|
|
|
412
424
|
throw new Exception({
|
|
413
425
|
message: `${this.value} is primitive type`,
|
|
414
426
|
code: 1052,
|
|
415
|
-
status:
|
|
427
|
+
status: "not-is-primitive"
|
|
416
428
|
});
|
|
417
429
|
}
|
|
418
430
|
return this;
|
|
@@ -422,7 +434,7 @@ class Expect {
|
|
|
422
434
|
throw new Exception({
|
|
423
435
|
message: `${this.value} is empty`,
|
|
424
436
|
code: 1053,
|
|
425
|
-
status:
|
|
437
|
+
status: "not-is-empty"
|
|
426
438
|
});
|
|
427
439
|
}
|
|
428
440
|
return this;
|
|
@@ -432,7 +444,7 @@ class Expect {
|
|
|
432
444
|
throw new Exception({
|
|
433
445
|
message: `${this.value} is object`,
|
|
434
446
|
code: 1054,
|
|
435
|
-
status:
|
|
447
|
+
status: "not-is-object"
|
|
436
448
|
});
|
|
437
449
|
}
|
|
438
450
|
return this;
|
|
@@ -442,7 +454,7 @@ class Expect {
|
|
|
442
454
|
throw new Exception({
|
|
443
455
|
message: `${this.value} is some object`,
|
|
444
456
|
code: 1055,
|
|
445
|
-
status:
|
|
457
|
+
status: "not-is-some-object"
|
|
446
458
|
});
|
|
447
459
|
}
|
|
448
460
|
return this;
|
|
@@ -452,7 +464,7 @@ class Expect {
|
|
|
452
464
|
throw new Exception({
|
|
453
465
|
message: `${this.value} is function`,
|
|
454
466
|
code: 1056,
|
|
455
|
-
status:
|
|
467
|
+
status: "not-is-function"
|
|
456
468
|
});
|
|
457
469
|
}
|
|
458
470
|
return this;
|
|
@@ -462,7 +474,7 @@ class Expect {
|
|
|
462
474
|
throw new Exception({
|
|
463
475
|
message: `${this.value} is numeric`,
|
|
464
476
|
code: 1057,
|
|
465
|
-
status:
|
|
477
|
+
status: "not-is-numeric"
|
|
466
478
|
});
|
|
467
479
|
}
|
|
468
480
|
return this;
|
|
@@ -472,7 +484,7 @@ class Expect {
|
|
|
472
484
|
throw new Exception({
|
|
473
485
|
message: `${this.value} is array`,
|
|
474
486
|
code: 1058,
|
|
475
|
-
status:
|
|
487
|
+
status: "not-is-array"
|
|
476
488
|
});
|
|
477
489
|
}
|
|
478
490
|
return this;
|
|
@@ -482,7 +494,7 @@ class Expect {
|
|
|
482
494
|
throw new Exception({
|
|
483
495
|
message: `${this.value} is some array`,
|
|
484
496
|
code: 1059,
|
|
485
|
-
status:
|
|
497
|
+
status: "to-be-empty-array"
|
|
486
498
|
});
|
|
487
499
|
}
|
|
488
500
|
return this;
|
|
@@ -492,7 +504,7 @@ class Expect {
|
|
|
492
504
|
throw new Exception({
|
|
493
505
|
message: `${this.value} is iterable`,
|
|
494
506
|
code: 1060,
|
|
495
|
-
status:
|
|
507
|
+
status: "not-iterable"
|
|
496
508
|
});
|
|
497
509
|
}
|
|
498
510
|
return this;
|
|
@@ -502,7 +514,7 @@ class Expect {
|
|
|
502
514
|
throw new Exception({
|
|
503
515
|
message: `${this.value} is subclass of ${type}`,
|
|
504
516
|
code: 1061,
|
|
505
|
-
status:
|
|
517
|
+
status: "not-subclassof"
|
|
506
518
|
});
|
|
507
519
|
}
|
|
508
520
|
return this;
|
|
@@ -512,7 +524,7 @@ class Expect {
|
|
|
512
524
|
throw new Exception({
|
|
513
525
|
message: `${this.value} is instance of ${type}`,
|
|
514
526
|
code: 1062,
|
|
515
|
-
status:
|
|
527
|
+
status: "not-instanceof"
|
|
516
528
|
});
|
|
517
529
|
}
|
|
518
530
|
return this;
|
|
@@ -523,7 +535,7 @@ class Expect {
|
|
|
523
535
|
throw new Exception({
|
|
524
536
|
message: `${this.value} matches ${pattern}`,
|
|
525
537
|
code: 1063,
|
|
526
|
-
status:
|
|
538
|
+
status: "not-match"
|
|
527
539
|
});
|
|
528
540
|
}
|
|
529
541
|
return this;
|
|
@@ -533,14 +545,14 @@ class Expect {
|
|
|
533
545
|
throw new Exception({
|
|
534
546
|
message: `fnValidation is not function`,
|
|
535
547
|
code: 1064,
|
|
536
|
-
status:
|
|
548
|
+
status: "to-be-valid"
|
|
537
549
|
});
|
|
538
550
|
}
|
|
539
551
|
if (!fnValidation(this.value)) {
|
|
540
552
|
throw new Exception({
|
|
541
553
|
message: `${this.value} is not valid`,
|
|
542
554
|
code: 1065,
|
|
543
|
-
status:
|
|
555
|
+
status: "to-be-valid"
|
|
544
556
|
});
|
|
545
557
|
}
|
|
546
558
|
return this;
|
|
@@ -550,14 +562,14 @@ class Expect {
|
|
|
550
562
|
throw new Exception({
|
|
551
563
|
message: `fnValidation is not function`,
|
|
552
564
|
code: 1066,
|
|
553
|
-
status:
|
|
565
|
+
status: "not-to-be-valid"
|
|
554
566
|
});
|
|
555
567
|
}
|
|
556
568
|
if (fnValidation(this.value)) {
|
|
557
569
|
throw new Exception({
|
|
558
570
|
message: `${this.value} is valid`,
|
|
559
571
|
code: 1067,
|
|
560
|
-
status:
|
|
572
|
+
status: "not-to-be-valid"
|
|
561
573
|
});
|
|
562
574
|
}
|
|
563
575
|
return this;
|
|
@@ -567,7 +579,7 @@ class Expect {
|
|
|
567
579
|
throw new Exception({
|
|
568
580
|
message: `given argument is not a function.`,
|
|
569
581
|
code: 1012,
|
|
570
|
-
status:
|
|
582
|
+
status: "not-func"
|
|
571
583
|
});
|
|
572
584
|
}
|
|
573
585
|
let ok = false;
|
|
@@ -581,7 +593,7 @@ class Expect {
|
|
|
581
593
|
throw new Exception({
|
|
582
594
|
message: `given function threw incorrect error.`,
|
|
583
595
|
code: 1018,
|
|
584
|
-
status:
|
|
596
|
+
status: "incorrect-throw-error"
|
|
585
597
|
});
|
|
586
598
|
}
|
|
587
599
|
} else if (isFunction(ex)) {
|
|
@@ -589,7 +601,7 @@ class Expect {
|
|
|
589
601
|
throw new Exception({
|
|
590
602
|
message: `given function threw incorrect instance.`,
|
|
591
603
|
code: 1019,
|
|
592
|
-
status:
|
|
604
|
+
status: "incorrect-throw-instance"
|
|
593
605
|
});
|
|
594
606
|
}
|
|
595
607
|
} else if (isObject(ex)) {
|
|
@@ -598,7 +610,7 @@ class Expect {
|
|
|
598
610
|
throw new Exception({
|
|
599
611
|
message: `given function threw incorrect object shape.`,
|
|
600
612
|
code: 1020,
|
|
601
|
-
status:
|
|
613
|
+
status: "incorrect-throw-shape"
|
|
602
614
|
});
|
|
603
615
|
}
|
|
604
616
|
} else {
|
|
@@ -606,7 +618,7 @@ class Expect {
|
|
|
606
618
|
throw new Exception({
|
|
607
619
|
message: `given function threw incorrect object.`,
|
|
608
620
|
code: 1021,
|
|
609
|
-
status:
|
|
621
|
+
status: "incorrect-throw-object"
|
|
610
622
|
});
|
|
611
623
|
}
|
|
612
624
|
}
|
|
@@ -615,7 +627,7 @@ class Expect {
|
|
|
615
627
|
throw new Exception({
|
|
616
628
|
message: `given function threw incorrect value.`,
|
|
617
629
|
code: 1022,
|
|
618
|
-
status:
|
|
630
|
+
status: "incorrect-throw-value"
|
|
619
631
|
});
|
|
620
632
|
}
|
|
621
633
|
}
|
|
@@ -625,7 +637,7 @@ class Expect {
|
|
|
625
637
|
throw new Exception({
|
|
626
638
|
message: `given function ran without throwing any errors.`,
|
|
627
639
|
code: 1013,
|
|
628
|
-
status:
|
|
640
|
+
status: "ran-to-completion"
|
|
629
641
|
});
|
|
630
642
|
}
|
|
631
643
|
return this;
|
|
@@ -635,7 +647,7 @@ class Expect {
|
|
|
635
647
|
throw new Exception({
|
|
636
648
|
message: `given argument is not a function.`,
|
|
637
649
|
code: 1012,
|
|
638
|
-
status:
|
|
650
|
+
status: "not-func"
|
|
639
651
|
});
|
|
640
652
|
}
|
|
641
653
|
let ok = false;
|
|
@@ -649,7 +661,7 @@ class Expect {
|
|
|
649
661
|
throw new Exception({
|
|
650
662
|
message: `given function threw incorrect error.`,
|
|
651
663
|
code: 1018,
|
|
652
|
-
status:
|
|
664
|
+
status: "incorrect-throw-error"
|
|
653
665
|
});
|
|
654
666
|
}
|
|
655
667
|
} else if (isFunction(ex)) {
|
|
@@ -657,7 +669,7 @@ class Expect {
|
|
|
657
669
|
throw new Exception({
|
|
658
670
|
message: `given function threw incorrect instance.`,
|
|
659
671
|
code: 1019,
|
|
660
|
-
status:
|
|
672
|
+
status: "incorrect-throw-instance"
|
|
661
673
|
});
|
|
662
674
|
}
|
|
663
675
|
} else if (isObject(ex)) {
|
|
@@ -666,7 +678,7 @@ class Expect {
|
|
|
666
678
|
throw new Exception({
|
|
667
679
|
message: `given function threw incorrect object shape.`,
|
|
668
680
|
code: 1020,
|
|
669
|
-
status:
|
|
681
|
+
status: "incorrect-throw-shape"
|
|
670
682
|
});
|
|
671
683
|
}
|
|
672
684
|
} else {
|
|
@@ -674,7 +686,7 @@ class Expect {
|
|
|
674
686
|
throw new Exception({
|
|
675
687
|
message: `given function threw incorrect object.`,
|
|
676
688
|
code: 1021,
|
|
677
|
-
status:
|
|
689
|
+
status: "incorrect-throw-object"
|
|
678
690
|
});
|
|
679
691
|
}
|
|
680
692
|
}
|
|
@@ -683,7 +695,7 @@ class Expect {
|
|
|
683
695
|
throw new Exception({
|
|
684
696
|
message: `given function threw incorrect value.`,
|
|
685
697
|
code: 1022,
|
|
686
|
-
status:
|
|
698
|
+
status: "incorrect-throw-value"
|
|
687
699
|
});
|
|
688
700
|
}
|
|
689
701
|
}
|
|
@@ -693,7 +705,7 @@ class Expect {
|
|
|
693
705
|
throw new Exception({
|
|
694
706
|
message: `given function ran without throwing any errors.`,
|
|
695
707
|
code: 1013,
|
|
696
|
-
status:
|
|
708
|
+
status: "ran-to-completion"
|
|
697
709
|
});
|
|
698
710
|
}
|
|
699
711
|
return this;
|
|
@@ -703,7 +715,7 @@ class Expect {
|
|
|
703
715
|
throw new Exception({
|
|
704
716
|
message: `given argument is not a function.`,
|
|
705
717
|
code: 1012,
|
|
706
|
-
status:
|
|
718
|
+
status: "not-func"
|
|
707
719
|
});
|
|
708
720
|
}
|
|
709
721
|
let ok = true;
|
|
@@ -719,7 +731,7 @@ class Expect {
|
|
|
719
731
|
throw new Exception({
|
|
720
732
|
message: `given function threw incorrect error.`,
|
|
721
733
|
code: 1018,
|
|
722
|
-
status:
|
|
734
|
+
status: "incorrect-throw-error"
|
|
723
735
|
});
|
|
724
736
|
}
|
|
725
737
|
} else if (isFunction(ex)) {
|
|
@@ -727,7 +739,7 @@ class Expect {
|
|
|
727
739
|
throw new Exception({
|
|
728
740
|
message: `given function threw incorrect instance.`,
|
|
729
741
|
code: 1019,
|
|
730
|
-
status:
|
|
742
|
+
status: "incorrect-throw-instance"
|
|
731
743
|
});
|
|
732
744
|
}
|
|
733
745
|
} else if (isObject(ex)) {
|
|
@@ -736,7 +748,7 @@ class Expect {
|
|
|
736
748
|
throw new Exception({
|
|
737
749
|
message: `given function threw incorrect object shape.`,
|
|
738
750
|
code: 1020,
|
|
739
|
-
status:
|
|
751
|
+
status: "incorrect-throw-shape"
|
|
740
752
|
});
|
|
741
753
|
}
|
|
742
754
|
} else {
|
|
@@ -744,7 +756,7 @@ class Expect {
|
|
|
744
756
|
throw new Exception({
|
|
745
757
|
message: `given function threw incorrect object.`,
|
|
746
758
|
code: 1021,
|
|
747
|
-
status:
|
|
759
|
+
status: "incorrect-throw-object"
|
|
748
760
|
});
|
|
749
761
|
}
|
|
750
762
|
}
|
|
@@ -753,7 +765,7 @@ class Expect {
|
|
|
753
765
|
throw new Exception({
|
|
754
766
|
message: `given function threw incorrect value.`,
|
|
755
767
|
code: 1022,
|
|
756
|
-
status:
|
|
768
|
+
status: "incorrect-throw-value"
|
|
757
769
|
});
|
|
758
770
|
}
|
|
759
771
|
}
|
|
@@ -763,7 +775,7 @@ class Expect {
|
|
|
763
775
|
throw new Exception({
|
|
764
776
|
message: `given function threw an error.`,
|
|
765
777
|
code: 1014,
|
|
766
|
-
status:
|
|
778
|
+
status: "ran-to-error",
|
|
767
779
|
innerException: error
|
|
768
780
|
});
|
|
769
781
|
}
|
|
@@ -774,7 +786,7 @@ class Expect {
|
|
|
774
786
|
throw new Exception({
|
|
775
787
|
message: `given argument is not a function.`,
|
|
776
788
|
code: 1012,
|
|
777
|
-
status:
|
|
789
|
+
status: "not-func"
|
|
778
790
|
});
|
|
779
791
|
}
|
|
780
792
|
let ok = true;
|
|
@@ -790,7 +802,7 @@ class Expect {
|
|
|
790
802
|
throw new Exception({
|
|
791
803
|
message: `given function threw incorrect error.`,
|
|
792
804
|
code: 1018,
|
|
793
|
-
status:
|
|
805
|
+
status: "incorrect-throw-error"
|
|
794
806
|
});
|
|
795
807
|
}
|
|
796
808
|
} else if (isFunction(ex)) {
|
|
@@ -798,7 +810,7 @@ class Expect {
|
|
|
798
810
|
throw new Exception({
|
|
799
811
|
message: `given function threw incorrect instance.`,
|
|
800
812
|
code: 1019,
|
|
801
|
-
status:
|
|
813
|
+
status: "incorrect-throw-instance"
|
|
802
814
|
});
|
|
803
815
|
}
|
|
804
816
|
} else if (isObject(ex)) {
|
|
@@ -807,7 +819,7 @@ class Expect {
|
|
|
807
819
|
throw new Exception({
|
|
808
820
|
message: `given function threw incorrect object shape.`,
|
|
809
821
|
code: 1020,
|
|
810
|
-
status:
|
|
822
|
+
status: "incorrect-throw-shape"
|
|
811
823
|
});
|
|
812
824
|
}
|
|
813
825
|
} else {
|
|
@@ -815,7 +827,7 @@ class Expect {
|
|
|
815
827
|
throw new Exception({
|
|
816
828
|
message: `given function threw incorrect object.`,
|
|
817
829
|
code: 1021,
|
|
818
|
-
status:
|
|
830
|
+
status: "incorrect-throw-object"
|
|
819
831
|
});
|
|
820
832
|
}
|
|
821
833
|
}
|
|
@@ -824,7 +836,7 @@ class Expect {
|
|
|
824
836
|
throw new Exception({
|
|
825
837
|
message: `given function threw incorrect value.`,
|
|
826
838
|
code: 1022,
|
|
827
|
-
status:
|
|
839
|
+
status: "incorrect-throw-value"
|
|
828
840
|
});
|
|
829
841
|
}
|
|
830
842
|
}
|
|
@@ -834,7 +846,7 @@ class Expect {
|
|
|
834
846
|
throw new Exception({
|
|
835
847
|
message: `given function threw an error.`,
|
|
836
848
|
code: 1014,
|
|
837
|
-
status:
|
|
849
|
+
status: "ran-to-error",
|
|
838
850
|
innerException: error
|
|
839
851
|
});
|
|
840
852
|
}
|
|
@@ -845,27 +857,33 @@ class Expect {
|
|
|
845
857
|
throw new Exception({
|
|
846
858
|
message: `${this.value} is not truthy`,
|
|
847
859
|
code: 1015,
|
|
848
|
-
status:
|
|
860
|
+
status: "not-truthy"
|
|
849
861
|
});
|
|
850
862
|
}
|
|
851
863
|
return this;
|
|
852
864
|
}
|
|
865
|
+
toBeTrue() {
|
|
866
|
+
return this.toBeTruthy();
|
|
867
|
+
}
|
|
853
868
|
toBeFalsy() {
|
|
854
869
|
if (!this.value) {} else {
|
|
855
870
|
throw new Exception({
|
|
856
871
|
message: `${this.value} is not falsy`,
|
|
857
872
|
code: 1016,
|
|
858
|
-
status:
|
|
873
|
+
status: "not-falsy"
|
|
859
874
|
});
|
|
860
875
|
}
|
|
861
876
|
return this;
|
|
862
877
|
}
|
|
878
|
+
toBeFalse() {
|
|
879
|
+
return this.toBeFalsy();
|
|
880
|
+
}
|
|
863
881
|
toBeNaN() {
|
|
864
882
|
if (isNaN(this.value)) {} else {
|
|
865
883
|
throw new Exception({
|
|
866
884
|
message: `${this.value} is not NaN`,
|
|
867
885
|
code: 1017,
|
|
868
|
-
status:
|
|
886
|
+
status: "not-nan"
|
|
869
887
|
});
|
|
870
888
|
}
|
|
871
889
|
return this;
|
|
@@ -875,7 +893,7 @@ class Expect {
|
|
|
875
893
|
throw new Exception({
|
|
876
894
|
message: `${this.value} is NaN`,
|
|
877
895
|
code: 1023,
|
|
878
|
-
status:
|
|
896
|
+
status: "is-nan"
|
|
879
897
|
});
|
|
880
898
|
}
|
|
881
899
|
return this;
|
|
@@ -909,7 +927,7 @@ class Test {
|
|
|
909
927
|
err: new Exception({
|
|
910
928
|
message: `test '${this.name}' failed.`,
|
|
911
929
|
code: 501,
|
|
912
|
-
status:
|
|
930
|
+
status: "failed",
|
|
913
931
|
innerException: ex
|
|
914
932
|
})
|
|
915
933
|
});
|
|
@@ -930,7 +948,7 @@ class Test {
|
|
|
930
948
|
err: new Exception({
|
|
931
949
|
message: `test '${this.name}' failed.`,
|
|
932
950
|
code: 501,
|
|
933
|
-
status:
|
|
951
|
+
status: "failed",
|
|
934
952
|
innerException: ex
|
|
935
953
|
})
|
|
936
954
|
});
|
|
@@ -943,27 +961,38 @@ class Test {
|
|
|
943
961
|
err: new Exception({
|
|
944
962
|
message: `test '${this.name}' does not have a function to be called.`,
|
|
945
963
|
code: 500,
|
|
946
|
-
status:
|
|
964
|
+
status: "no-func"
|
|
947
965
|
})
|
|
948
966
|
});
|
|
949
967
|
}
|
|
950
968
|
});
|
|
951
969
|
}
|
|
952
970
|
}
|
|
953
|
-
const
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
971
|
+
const reset = "\x1b[0m";
|
|
972
|
+
const bright = "\x1b[1m";
|
|
973
|
+
const dim = "\x1b[2m";
|
|
974
|
+
const underscore = "\x1b[4m";
|
|
975
|
+
const blink = "\x1b[5m";
|
|
976
|
+
const reverse = "\x1b[7m";
|
|
977
|
+
const hidden = "\x1b[8m";
|
|
978
|
+
const fgBlack = "\x1b[30m";
|
|
979
|
+
const fgRed = "\x1b[31m";
|
|
980
|
+
const fgGreen = "\x1b[32m";
|
|
981
|
+
const fgYellow = "\x1b[33m";
|
|
982
|
+
const fgBlue = "\x1b[34m";
|
|
983
|
+
const fgMagenta = "\x1b[35m";
|
|
984
|
+
const fgCyan = "\x1b[36m";
|
|
985
|
+
const fgWhite = "\x1b[37m";
|
|
986
|
+
const fgGray = "\x1b[90m";
|
|
987
|
+
const bgBlack = "\x1b[40m";
|
|
988
|
+
const bgRed = "\x1b[41m";
|
|
989
|
+
const bgGreen = "\x1b[42m";
|
|
990
|
+
const bgYellow = "\x1b[43m";
|
|
991
|
+
const bgBlue = "\x1b[44m";
|
|
992
|
+
const bgMagenta = "\x1b[45m";
|
|
993
|
+
const bgCyan = "\x1b[46m";
|
|
994
|
+
const bgWhite = "\x1b[47m";
|
|
995
|
+
const bgGray = "\x1b[100m";
|
|
967
996
|
class TestRunner {
|
|
968
997
|
constructor() {
|
|
969
998
|
this._passed = 0;
|
|
@@ -982,7 +1011,7 @@ class TestRunner {
|
|
|
982
1011
|
err: new Exception({
|
|
983
1012
|
message: `onProgress failed for test '${test.name} at index ${i}'.`,
|
|
984
1013
|
code: 1500,
|
|
985
|
-
status:
|
|
1014
|
+
status: "progress-failed",
|
|
986
1015
|
innerException: ex
|
|
987
1016
|
})
|
|
988
1017
|
});
|
|
@@ -1029,7 +1058,7 @@ class TestRunner {
|
|
|
1029
1058
|
err: new Exception({
|
|
1030
1059
|
message: `not all tests succeeded. check errors.`,
|
|
1031
1060
|
code: 1503,
|
|
1032
|
-
status:
|
|
1061
|
+
status: "partial-finished",
|
|
1033
1062
|
innerException: ex
|
|
1034
1063
|
})
|
|
1035
1064
|
});
|
|
@@ -1040,7 +1069,7 @@ class TestRunner {
|
|
|
1040
1069
|
err: new Exception({
|
|
1041
1070
|
message: `invalid tests. expected array or a single test.`,
|
|
1042
1071
|
code: 1502,
|
|
1043
|
-
status:
|
|
1072
|
+
status: "invalid-tests"
|
|
1044
1073
|
})
|
|
1045
1074
|
});
|
|
1046
1075
|
res(this.result);
|
|
@@ -1050,7 +1079,7 @@ class TestRunner {
|
|
|
1050
1079
|
err: new Exception({
|
|
1051
1080
|
message: `no tests given to be ran.`,
|
|
1052
1081
|
code: 1501,
|
|
1053
|
-
status:
|
|
1082
|
+
status: "no-tests"
|
|
1054
1083
|
})
|
|
1055
1084
|
});
|
|
1056
1085
|
res(this.result);
|
|
@@ -1062,24 +1091,27 @@ class TestRunner {
|
|
|
1062
1091
|
}
|
|
1063
1092
|
report(detailed) {
|
|
1064
1093
|
let time = 0;
|
|
1065
|
-
console.log(
|
|
1094
|
+
console.log("Finished.\n");
|
|
1066
1095
|
for (let i = 0; i < this._results.length; i++) {
|
|
1067
1096
|
const result = this._results[i];
|
|
1097
|
+
const t = `(${this._getTime(result.time)})`;
|
|
1068
1098
|
if (detailed) {
|
|
1069
|
-
let message =
|
|
1099
|
+
let message = "\n" + (i + 1) + ". ";
|
|
1070
1100
|
if (result.success) {
|
|
1071
|
-
message += `${
|
|
1101
|
+
message += `${fgWhite}${result.test}: ${fgGreen}passed${reset} ${t}`;
|
|
1072
1102
|
} else {
|
|
1073
|
-
message += `${
|
|
1074
|
-
message +=
|
|
1075
|
-
|
|
1103
|
+
message += `${bright}${fgWhite}${result.test}: ${fgRed}failed${reset} ${t}`;
|
|
1104
|
+
message += "\n";
|
|
1105
|
+
let err = result.err.toString().split("\n");
|
|
1106
|
+
err = err.map((msg, i) => `\t${i == err.length - 1 ? `${fgYellow}` : `${fgGray}error ${result.err.code}: `}${msg}${reset}`).join("\n");
|
|
1107
|
+
message += `${fgGray}${err} ${reset}`;
|
|
1076
1108
|
}
|
|
1077
1109
|
console.log(message);
|
|
1078
1110
|
}
|
|
1079
1111
|
time += result.time;
|
|
1080
1112
|
}
|
|
1081
1113
|
if (detailed && this._errors.length) {
|
|
1082
|
-
console.log(
|
|
1114
|
+
console.log("Errors:");
|
|
1083
1115
|
for (let error of this._errors) {
|
|
1084
1116
|
if (error.index !== undefined) {
|
|
1085
1117
|
console.log(`${error.index}. ${error.test}: ${error.err.innerException.toString()}`);
|
|
@@ -1088,22 +1120,22 @@ class TestRunner {
|
|
|
1088
1120
|
}
|
|
1089
1121
|
}
|
|
1090
1122
|
}
|
|
1091
|
-
const text = (detailed ?
|
|
1123
|
+
const text = (detailed ? "\n" : "") + `${bright}Number of tests: ${reset}${this._passed + this._failed}` + "\n" + `${bright}Total Time: ${reset}${time / 1000} sec` + "\n\n" + (this._passed > 0 ? `${fgGreen} ${this._passed} test(s) passed${reset}` : `0 tests passed${reset}`) + ", " + (this._failed > 0 ? `${fgRed} ${this._failed} test(s) failed${reset}` : `0 tests failed${reset}`) + "\n";
|
|
1092
1124
|
console.log(text);
|
|
1093
1125
|
}
|
|
1094
1126
|
log(filename) {
|
|
1095
1127
|
const content = JSON.stringify({
|
|
1096
1128
|
results: this._results,
|
|
1097
1129
|
errors: this._errors
|
|
1098
|
-
}, null,
|
|
1130
|
+
}, null, "\t");
|
|
1099
1131
|
if (filename == null) {
|
|
1100
1132
|
const d = new Date();
|
|
1101
|
-
const year = d.getFullYear().toString().padStart(4,
|
|
1102
|
-
const month = (d.getMonth() + 1).toString().padStart(2,
|
|
1103
|
-
const day = d.getDate().toString().padStart(2,
|
|
1104
|
-
const hours = d.getHours().toString().padStart(2,
|
|
1105
|
-
const minutes = d.getMinutes().toString().padStart(2,
|
|
1106
|
-
const seconds = d.getSeconds().toString().padStart(2,
|
|
1133
|
+
const year = d.getFullYear().toString().padStart(4, "0");
|
|
1134
|
+
const month = (d.getMonth() + 1).toString().padStart(2, "0");
|
|
1135
|
+
const day = d.getDate().toString().padStart(2, "0");
|
|
1136
|
+
const hours = d.getHours().toString().padStart(2, "0");
|
|
1137
|
+
const minutes = d.getMinutes().toString().padStart(2, "0");
|
|
1138
|
+
const seconds = d.getSeconds().toString().padStart(2, "0");
|
|
1107
1139
|
filename = `test-${year}-${month}-${day}-${hours}${minutes}${seconds}.json`;
|
|
1108
1140
|
}
|
|
1109
1141
|
const filepath = path.join(process.cwd(), filename);
|
|
@@ -1111,9 +1143,13 @@ class TestRunner {
|
|
|
1111
1143
|
fs.writeFileSync(filepath, content);
|
|
1112
1144
|
console.log(`tests outcome wrote in ${filename}.`);
|
|
1113
1145
|
} catch (ex) {
|
|
1114
|
-
console.log(
|
|
1146
|
+
console.log("writing tests outcome failed.\n" + ex);
|
|
1115
1147
|
}
|
|
1116
1148
|
}
|
|
1149
|
+
static start(tests) {
|
|
1150
|
+
const tr = new TestRunner();
|
|
1151
|
+
tr.run(tests).then(result => tr.report(result.failed > 0));
|
|
1152
|
+
}
|
|
1117
1153
|
}
|
|
1118
1154
|
export default TestRunner;
|
|
1119
1155
|
export { Test, Expect, expect };
|