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