@locustjs/test 1.1.7 → 1.3.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 CHANGED
@@ -1,4 +1,4 @@
1
- import { isArray, isFunction, isObject, isPrimitive, equals } from '@locustjs/base';
1
+ import { equals, isString, isNumber, isDate, isBool, isBasic, isPrimitive, isEmpty, isSomeString, isObject, isSomeObject, isFunction, isNumeric, isArray, isIterable, isSomeArray, isSubClassOf } from '@locustjs/base';
2
2
  import { Exception } from '@locustjs/exception';
3
3
  import fs from 'fs';
4
4
  import path from 'path';
@@ -14,42 +14,248 @@ class Expect {
14
14
  status: 'not-eq'
15
15
  });
16
16
  }
17
+ return this;
17
18
  }
18
19
  toBeGt(value) {
19
20
  if (this.value <= value) {
20
21
  throw new Exception({
21
- message: `${this.value} is lower than or equal to ${value}`,
22
+ message: `${this.value} is not greater than ${value}`,
22
23
  code: 1001,
23
24
  status: 'lte'
24
25
  });
25
26
  }
27
+ return this;
26
28
  }
27
29
  toBeGte(value) {
28
30
  if (this.value < value) {
29
31
  throw new Exception({
30
- message: `${this.value} is lower than to ${value}`,
32
+ message: `${this.value} is not greater than or equal to ${value}`,
31
33
  code: 1002,
32
34
  status: 'lt'
33
35
  });
34
36
  }
37
+ return this;
35
38
  }
36
39
  toBeLt(value) {
37
40
  if (this.value >= value) {
38
41
  throw new Exception({
39
- message: `${this.value} is greater than or equal to ${value}`,
42
+ message: `${this.value} is not less than ${value}`,
40
43
  code: 1003,
41
44
  status: 'gte'
42
45
  });
43
46
  }
47
+ return this;
44
48
  }
45
49
  toBeLte(value) {
46
50
  if (this.value > value) {
47
51
  throw new Exception({
48
- message: `${this.value} is greater than ${value}`,
52
+ message: `${this.value} is not less than or equal to ${value}`,
49
53
  code: 1004,
50
54
  status: 'gt'
51
55
  });
52
56
  }
57
+ return this;
58
+ }
59
+ toBeBetween(n, m) {
60
+ if (!(this.value >= n && this.value < m)) {
61
+ throw new Exception({
62
+ message: `${this.value} is not between ${n} and ${m}`,
63
+ code: 1024,
64
+ status: 'between'
65
+ });
66
+ }
67
+ return this;
68
+ }
69
+ toBeOfType(type) {
70
+ if (typeof this.value !== type) {
71
+ throw new Exception({
72
+ message: `${this.value} is not of type ${type}`,
73
+ code: 1025,
74
+ status: 'of-type'
75
+ });
76
+ }
77
+ return this;
78
+ }
79
+ toBeString() {
80
+ if (!isString(this.value)) {
81
+ throw new Exception({
82
+ message: `${this.value} is not string`,
83
+ code: 1026,
84
+ status: 'is-string'
85
+ });
86
+ }
87
+ return this;
88
+ }
89
+ toBeSomeString() {
90
+ if (!isSomeString(this.value)) {
91
+ throw new Exception({
92
+ message: `${this.value} is not some string`,
93
+ code: 1027,
94
+ status: 'is-some-string'
95
+ });
96
+ }
97
+ return this;
98
+ }
99
+ toBeNumber() {
100
+ if (!isNumber(this.value)) {
101
+ throw new Exception({
102
+ message: `${this.value} is not number`,
103
+ code: 1028,
104
+ status: 'is-number'
105
+ });
106
+ }
107
+ return this;
108
+ }
109
+ toBeDate() {
110
+ if (!isDate(this.value)) {
111
+ throw new Exception({
112
+ message: `${this.value} is not date`,
113
+ code: 1029,
114
+ status: 'is-date'
115
+ });
116
+ }
117
+ return this;
118
+ }
119
+ toBeBool() {
120
+ if (!isBool(this.value)) {
121
+ throw new Exception({
122
+ message: `${this.value} is not bool`,
123
+ code: 1030,
124
+ status: 'is-bool'
125
+ });
126
+ }
127
+ return this;
128
+ }
129
+ toBeBasicType() {
130
+ if (!isBasic(this.value)) {
131
+ throw new Exception({
132
+ message: `${this.value} is not basic type`,
133
+ code: 1031,
134
+ status: 'is-basic-type'
135
+ });
136
+ }
137
+ return this;
138
+ }
139
+ toBePrimitive() {
140
+ if (!isPrimitive(this.value)) {
141
+ throw new Exception({
142
+ message: `${this.value} is not primitive type`,
143
+ code: 1032,
144
+ status: 'is-primitive'
145
+ });
146
+ }
147
+ return this;
148
+ }
149
+ toBeEmpty() {
150
+ if (!isEmpty(this.value)) {
151
+ throw new Exception({
152
+ message: `${this.value} is not empty`,
153
+ code: 1033,
154
+ status: 'is-empty'
155
+ });
156
+ }
157
+ return this;
158
+ }
159
+ toBeObject() {
160
+ if (!isObject(this.value)) {
161
+ throw new Exception({
162
+ message: `${this.value} is not object`,
163
+ code: 1034,
164
+ status: 'is-object'
165
+ });
166
+ }
167
+ return this;
168
+ }
169
+ toBeSomeObject() {
170
+ if (!isSomeObject(this.value)) {
171
+ throw new Exception({
172
+ message: `${this.value} is not some object`,
173
+ code: 1035,
174
+ status: 'is-some-object'
175
+ });
176
+ }
177
+ return this;
178
+ }
179
+ toBeFunction() {
180
+ if (!isFunction(this.value)) {
181
+ throw new Exception({
182
+ message: `${this.value} is not function`,
183
+ code: 1036,
184
+ status: 'is-function'
185
+ });
186
+ }
187
+ return this;
188
+ }
189
+ toBeNumeric() {
190
+ if (!isNumeric(this.value)) {
191
+ throw new Exception({
192
+ message: `${this.value} is not numeric`,
193
+ code: 1037,
194
+ status: 'is-numeric'
195
+ });
196
+ }
197
+ return this;
198
+ }
199
+ toBeArray() {
200
+ if (!isArray(this.value)) {
201
+ throw new Exception({
202
+ message: `${this.value} is not array`,
203
+ code: 1038,
204
+ status: 'is-array'
205
+ });
206
+ }
207
+ return this;
208
+ }
209
+ toBeSomeArray() {
210
+ if (!isSomeArray(this.value)) {
211
+ throw new Exception({
212
+ message: `${this.value} is not some array`,
213
+ code: 1039,
214
+ status: 'is-some-array'
215
+ });
216
+ }
217
+ return this;
218
+ }
219
+ toBeIterable() {
220
+ if (!isIterable(this.value)) {
221
+ throw new Exception({
222
+ message: `${this.value} is not iterable`,
223
+ code: 1040,
224
+ status: 'is-iterable'
225
+ });
226
+ }
227
+ return this;
228
+ }
229
+ toBeSubClassOf(type) {
230
+ if (!isSubClassOf(this.value, type)) {
231
+ throw new Exception({
232
+ message: `${this.value} is not subclass of ${type}`,
233
+ code: 1041,
234
+ status: 'is-subclass-of'
235
+ });
236
+ }
237
+ return this;
238
+ }
239
+ toBeInstanceOf(type) {
240
+ if (!(this.value instanceof type)) {
241
+ throw new Exception({
242
+ message: `${this.value} is not instance of ${type}`,
243
+ code: 1042,
244
+ status: 'instanceof'
245
+ });
246
+ }
247
+ return this;
248
+ }
249
+ toMatch(pattern, flags) {
250
+ const r = new RegExp(pattern, flags);
251
+ if (!r.test(this.value)) {
252
+ throw new Exception({
253
+ message: `${this.value} does not match ${pattern}`,
254
+ code: 1043,
255
+ status: 'match'
256
+ });
257
+ }
258
+ return this;
53
259
  }
54
260
  notToBe(value) {
55
261
  if (this.value === value) {
@@ -59,6 +265,7 @@ class Expect {
59
265
  status: 'eq'
60
266
  });
61
267
  }
268
+ return this;
62
269
  }
63
270
  toBeDefined() {
64
271
  if (this.value === undefined) {
@@ -68,6 +275,7 @@ class Expect {
68
275
  status: 'undefined'
69
276
  });
70
277
  }
278
+ return this;
71
279
  }
72
280
  toBeUndefined() {
73
281
  if (this.value !== undefined) {
@@ -77,6 +285,7 @@ class Expect {
77
285
  status: 'defined'
78
286
  });
79
287
  }
288
+ return this;
80
289
  }
81
290
  toBeNull() {
82
291
  if (this.value !== null) {
@@ -86,6 +295,7 @@ class Expect {
86
295
  status: 'not-null'
87
296
  });
88
297
  }
298
+ return this;
89
299
  }
90
300
  notToBeNull() {
91
301
  if (this.value === null) {
@@ -95,6 +305,7 @@ class Expect {
95
305
  status: 'null'
96
306
  });
97
307
  }
308
+ return this;
98
309
  }
99
310
  toBeNullOrUndefined() {
100
311
  if (this.value == null) {} else {
@@ -104,6 +315,7 @@ class Expect {
104
315
  status: 'not-null-or-undefined'
105
316
  });
106
317
  }
318
+ return this;
107
319
  }
108
320
  notToBeNullOrUndefined() {
109
321
  if (this.value == null) {
@@ -113,6 +325,242 @@ class Expect {
113
325
  status: 'null-or-undefined'
114
326
  });
115
327
  }
328
+ return this;
329
+ }
330
+ notToBeBetween(n, m) {
331
+ if (this.value >= n && this.value < m) {
332
+ throw new Exception({
333
+ message: `${this.value} is between ${n} and ${m}`,
334
+ code: 1044,
335
+ status: 'not-between'
336
+ });
337
+ }
338
+ return this;
339
+ }
340
+ notToBeOfType(type) {
341
+ if (typeof this.value === type) {
342
+ throw new Exception({
343
+ message: `${this.value} is of type ${type}`,
344
+ code: 1045,
345
+ status: 'not-oftype'
346
+ });
347
+ }
348
+ return this;
349
+ }
350
+ notToBeString() {
351
+ if (isString(this.value)) {
352
+ throw new Exception({
353
+ message: `${this.value} is string`,
354
+ code: 1046,
355
+ status: 'not-is-string'
356
+ });
357
+ }
358
+ return this;
359
+ }
360
+ notToBeSomeString() {
361
+ if (isSomeString(this.value)) {
362
+ throw new Exception({
363
+ message: `${this.value} is some string`,
364
+ code: 1047,
365
+ status: 'not-is-some-string'
366
+ });
367
+ }
368
+ return this;
369
+ }
370
+ notToBeNumber() {
371
+ if (isNumber(this.value)) {
372
+ throw new Exception({
373
+ message: `${this.value} is number`,
374
+ code: 1048,
375
+ status: 'not-is-number'
376
+ });
377
+ }
378
+ return this;
379
+ }
380
+ notToBeDate() {
381
+ if (isDate(this.value)) {
382
+ throw new Exception({
383
+ message: `${this.value} is date`,
384
+ code: 1049,
385
+ status: 'not-is-date'
386
+ });
387
+ }
388
+ return this;
389
+ }
390
+ notToBeBool() {
391
+ if (isBool(this.value)) {
392
+ throw new Exception({
393
+ message: `${this.value} is bool`,
394
+ code: 1050,
395
+ status: 'not-is-bool'
396
+ });
397
+ }
398
+ return this;
399
+ }
400
+ notToBeBasicType() {
401
+ if (isBasic(this.value)) {
402
+ throw new Exception({
403
+ message: `${this.value} is basic type`,
404
+ code: 1051,
405
+ status: 'not-is-basic-type'
406
+ });
407
+ }
408
+ return this;
409
+ }
410
+ notToBePrimitive() {
411
+ if (isPrimitive(this.value)) {
412
+ throw new Exception({
413
+ message: `${this.value} is primitive type`,
414
+ code: 1052,
415
+ status: 'not-is-primitive'
416
+ });
417
+ }
418
+ return this;
419
+ }
420
+ notToBeEmpty() {
421
+ if (isEmpty(this.value)) {
422
+ throw new Exception({
423
+ message: `${this.value} is empty`,
424
+ code: 1053,
425
+ status: 'not-is-empty'
426
+ });
427
+ }
428
+ return this;
429
+ }
430
+ notToBeObject() {
431
+ if (isObject(this.value)) {
432
+ throw new Exception({
433
+ message: `${this.value} is object`,
434
+ code: 1054,
435
+ status: 'not-is-object'
436
+ });
437
+ }
438
+ return this;
439
+ }
440
+ notToBeSomeObject() {
441
+ if (isSomeObject(this.value)) {
442
+ throw new Exception({
443
+ message: `${this.value} is some object`,
444
+ code: 1055,
445
+ status: 'not-is-some-object'
446
+ });
447
+ }
448
+ return this;
449
+ }
450
+ notToBeFunction() {
451
+ if (isFunction(this.value)) {
452
+ throw new Exception({
453
+ message: `${this.value} is function`,
454
+ code: 1056,
455
+ status: 'not-is-function'
456
+ });
457
+ }
458
+ return this;
459
+ }
460
+ notToBeNumeric() {
461
+ if (isNumeric(this.value)) {
462
+ throw new Exception({
463
+ message: `${this.value} is numeric`,
464
+ code: 1057,
465
+ status: 'not-is-numeric'
466
+ });
467
+ }
468
+ return this;
469
+ }
470
+ notToBeArray() {
471
+ if (isArray(this.value)) {
472
+ throw new Exception({
473
+ message: `${this.value} is array`,
474
+ code: 1058,
475
+ status: 'not-is-array'
476
+ });
477
+ }
478
+ return this;
479
+ }
480
+ toBeEmptyArray() {
481
+ if (isSomeArray(this.value)) {
482
+ throw new Exception({
483
+ message: `${this.value} is some array`,
484
+ code: 1059,
485
+ status: 'to-be-empty-array'
486
+ });
487
+ }
488
+ return this;
489
+ }
490
+ notToBeIterable() {
491
+ if (isIterable(this.value)) {
492
+ throw new Exception({
493
+ message: `${this.value} is iterable`,
494
+ code: 1060,
495
+ status: 'not-iterable'
496
+ });
497
+ }
498
+ return this;
499
+ }
500
+ notToBeSubClassOf(type) {
501
+ if (isSubClassOf(this.value, type)) {
502
+ throw new Exception({
503
+ message: `${this.value} is subclass of ${type}`,
504
+ code: 1061,
505
+ status: 'not-subclassof'
506
+ });
507
+ }
508
+ return this;
509
+ }
510
+ notToBeInstanceOf(type) {
511
+ if (this.value instanceof type) {
512
+ throw new Exception({
513
+ message: `${this.value} is instance of ${type}`,
514
+ code: 1062,
515
+ status: 'not-instanceof'
516
+ });
517
+ }
518
+ return this;
519
+ }
520
+ doesNotMatch(pattern, flags) {
521
+ const r = new RegExp(pattern, flags);
522
+ if (r.test(this.value)) {
523
+ throw new Exception({
524
+ message: `${this.value} matches ${pattern}`,
525
+ code: 1063,
526
+ status: 'not-match'
527
+ });
528
+ }
529
+ return this;
530
+ }
531
+ toBeValid(fnValidation) {
532
+ if (!isFunction(fnValidation)) {
533
+ throw new Exception({
534
+ message: `fnValidation is not function`,
535
+ code: 1064,
536
+ status: 'to-be-valid'
537
+ });
538
+ }
539
+ if (!fnValidation(this.value)) {
540
+ throw new Exception({
541
+ message: `${this.value} is not valid`,
542
+ code: 1065,
543
+ status: 'to-be-valid'
544
+ });
545
+ }
546
+ return this;
547
+ }
548
+ notToBeValid(fnValidation) {
549
+ if (!isFunction(fnValidation)) {
550
+ throw new Exception({
551
+ message: `fnValidation is not function`,
552
+ code: 1066,
553
+ status: 'not-to-be-valid'
554
+ });
555
+ }
556
+ if (fnValidation(this.value)) {
557
+ throw new Exception({
558
+ message: `${this.value} is valid`,
559
+ code: 1067,
560
+ status: 'not-to-be-valid'
561
+ });
562
+ }
563
+ return this;
116
564
  }
117
565
  toThrow(ex, shape = false, strict = false) {
118
566
  if (!isFunction(this.value)) {
@@ -180,6 +628,7 @@ class Expect {
180
628
  status: 'ran-to-completion'
181
629
  });
182
630
  }
631
+ return this;
183
632
  }
184
633
  async toThrowAsync(ex, shape = false, strict = false) {
185
634
  if (!isFunction(this.value)) {
@@ -247,6 +696,7 @@ class Expect {
247
696
  status: 'ran-to-completion'
248
697
  });
249
698
  }
699
+ return this;
250
700
  }
251
701
  notToThrow(ex, shape = false, strict = false) {
252
702
  if (!isFunction(this.value)) {
@@ -317,6 +767,7 @@ class Expect {
317
767
  innerException: error
318
768
  });
319
769
  }
770
+ return this;
320
771
  }
321
772
  async notToThrowAsync(ex, shape = false, strict = false) {
322
773
  if (!isFunction(this.value)) {
@@ -387,6 +838,7 @@ class Expect {
387
838
  innerException: error
388
839
  });
389
840
  }
841
+ return this;
390
842
  }
391
843
  toBeTruthy() {
392
844
  if (this.value) {} else {
@@ -396,6 +848,7 @@ class Expect {
396
848
  status: 'not-truthy'
397
849
  });
398
850
  }
851
+ return this;
399
852
  }
400
853
  toBeFalsy() {
401
854
  if (!this.value) {} else {
@@ -405,6 +858,7 @@ class Expect {
405
858
  status: 'not-falsy'
406
859
  });
407
860
  }
861
+ return this;
408
862
  }
409
863
  toBeNaN() {
410
864
  if (isNaN(this.value)) {} else {
@@ -414,6 +868,7 @@ class Expect {
414
868
  status: 'not-nan'
415
869
  });
416
870
  }
871
+ return this;
417
872
  }
418
873
  notToBeNaN() {
419
874
  if (!isNaN(this.value)) {} else {
@@ -423,6 +878,7 @@ class Expect {
423
878
  status: 'is-nan'
424
879
  });
425
880
  }
881
+ return this;
426
882
  }
427
883
  }
428
884
  const expect = x => new Expect(x);
package/index.esm.js CHANGED
@@ -1,4 +1,22 @@
1
- import { isArray, isFunction, isObject, isPrimitive, equals } from '@locustjs/base';
1
+ import {
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';
2
20
  import { Exception } from '@locustjs/exception';
3
21
  import fs from 'fs';
4
22
  import path from 'path';
@@ -12,62 +30,390 @@ class Expect {
12
30
  } else {
13
31
  throw new Exception({ message: `${this.value} is not equal to ${value}`, code: 1000, status: 'not-eq' })
14
32
  }
33
+
34
+ return this;
15
35
  }
16
36
  toBeGt(value) {
17
37
  if (this.value <= value) {
18
- throw new Exception({ message: `${this.value} is lower than or equal to ${value}`, code: 1001, status: 'lte' })
38
+ throw new Exception({ message: `${this.value} is not greater than ${value}`, code: 1001, status: 'lte' })
19
39
  }
40
+
41
+ return this;
20
42
  }
21
43
  toBeGte(value) {
22
44
  if (this.value < value) {
23
- throw new Exception({ message: `${this.value} is lower than to ${value}`, code: 1002, status: 'lt' })
45
+ throw new Exception({ message: `${this.value} is not greater than or equal to ${value}`, code: 1002, status: 'lt' })
24
46
  }
47
+
48
+ return this;
25
49
  }
26
50
  toBeLt(value) {
27
51
  if (this.value >= value) {
28
- throw new Exception({ message: `${this.value} is greater than or equal to ${value}`, code: 1003, status: 'gte' })
52
+ throw new Exception({ message: `${this.value} is not less than ${value}`, code: 1003, status: 'gte' })
29
53
  }
54
+
55
+ return this;
30
56
  }
31
57
  toBeLte(value) {
32
58
  if (this.value > value) {
33
- throw new Exception({ message: `${this.value} is greater than ${value}`, code: 1004, status: 'gt' })
59
+ throw new Exception({ message: `${this.value} is not less than or equal to ${value}`, code: 1004, status: 'gt' })
60
+ }
61
+
62
+ return this;
63
+ }
64
+ toBeBetween(n, m) {
65
+ if (!(this.value >= n && this.value < m)) {
66
+ throw new Exception({ message: `${this.value} is not between ${n} and ${m}`, code: 1024, status: 'between' })
67
+ }
68
+
69
+ return this;
70
+ }
71
+ toBeOfType(type) {
72
+ if (typeof this.value !== type) {
73
+ throw new Exception({ message: `${this.value} is not of type ${type}`, code: 1025, status: 'of-type' })
74
+ }
75
+
76
+ return this;
77
+ }
78
+ toBeString() {
79
+ if (!isString(this.value)) {
80
+ throw new Exception({ message: `${this.value} is not string`, code: 1026, status: 'is-string' })
81
+ }
82
+
83
+ return this;
84
+ }
85
+ toBeSomeString() {
86
+ if (!isSomeString(this.value)) {
87
+ throw new Exception({ message: `${this.value} is not some string`, code: 1027, status: 'is-some-string' })
88
+ }
89
+
90
+ return this;
91
+ }
92
+ toBeNumber() {
93
+ if (!isNumber(this.value)) {
94
+ throw new Exception({ message: `${this.value} is not number`, code: 1028, status: 'is-number' })
95
+ }
96
+
97
+ return this;
98
+ }
99
+ toBeDate() {
100
+ if (!isDate(this.value)) {
101
+ throw new Exception({ message: `${this.value} is not date`, code: 1029, status: 'is-date' })
102
+ }
103
+
104
+ return this;
105
+ }
106
+ toBeBool() {
107
+ if (!isBool(this.value)) {
108
+ throw new Exception({ message: `${this.value} is not bool`, code: 1030, status: 'is-bool' })
109
+ }
110
+
111
+ return this;
112
+ }
113
+ toBeBasicType() {
114
+ if (!isBasic(this.value)) {
115
+ throw new Exception({ message: `${this.value} is not basic type`, code: 1031, status: 'is-basic-type' })
116
+ }
117
+
118
+ return this;
119
+ }
120
+ toBePrimitive() {
121
+ if (!isPrimitive(this.value)) {
122
+ throw new Exception({ message: `${this.value} is not primitive type`, code: 1032, status: 'is-primitive' })
123
+ }
124
+
125
+ return this;
126
+ }
127
+ toBeEmpty() {
128
+ if (!isEmpty(this.value)) {
129
+ throw new Exception({ message: `${this.value} is not empty`, code: 1033, status: 'is-empty' })
130
+ }
131
+
132
+ return this;
133
+ }
134
+ toBeObject() {
135
+ if (!isObject(this.value)) {
136
+ throw new Exception({ message: `${this.value} is not object`, code: 1034, status: 'is-object' })
137
+ }
138
+
139
+ return this;
140
+ }
141
+ toBeSomeObject() {
142
+ if (!isSomeObject(this.value)) {
143
+ throw new Exception({ message: `${this.value} is not some object`, code: 1035, status: 'is-some-object' })
144
+ }
145
+
146
+ return this;
147
+ }
148
+ toBeFunction() {
149
+ if (!isFunction(this.value)) {
150
+ throw new Exception({ message: `${this.value} is not function`, code: 1036, status: 'is-function' })
151
+ }
152
+
153
+ return this;
154
+ }
155
+ toBeNumeric() {
156
+ if (!isNumeric(this.value)) {
157
+ throw new Exception({ message: `${this.value} is not numeric`, code: 1037, status: 'is-numeric' })
158
+ }
159
+
160
+ return this;
161
+ }
162
+ toBeArray() {
163
+ if (!isArray(this.value)) {
164
+ throw new Exception({ message: `${this.value} is not array`, code: 1038, status: 'is-array' })
165
+ }
166
+
167
+ return this;
168
+ }
169
+ toBeSomeArray() {
170
+ if (!isSomeArray(this.value)) {
171
+ throw new Exception({ message: `${this.value} is not some array`, code: 1039, status: 'is-some-array' })
172
+ }
173
+
174
+ return this;
175
+ }
176
+ toBeIterable() {
177
+ if (!isIterable(this.value)) {
178
+ throw new Exception({ message: `${this.value} is not iterable`, code: 1040, status: 'is-iterable' })
179
+ }
180
+
181
+ return this;
182
+ }
183
+ toBeSubClassOf(type) {
184
+ if (!isSubClassOf(this.value, type)) {
185
+ throw new Exception({ message: `${this.value} is not subclass of ${type}`, code: 1041, status: 'is-subclass-of' })
186
+ }
187
+
188
+ return this;
189
+ }
190
+ toBeInstanceOf(type) {
191
+ if (!(this.value instanceof type)) {
192
+ throw new Exception({ message: `${this.value} is not instance of ${type}`, code: 1042, status: 'instanceof' })
193
+ }
194
+
195
+ return this;
196
+ }
197
+ toMatch(pattern, flags) {
198
+ const r = new RegExp(pattern, flags)
199
+
200
+ if (!r.test(this.value)) {
201
+ throw new Exception({ message: `${this.value} does not match ${pattern}`, code: 1043, status: 'match' })
34
202
  }
203
+
204
+ return this;
35
205
  }
36
206
  notToBe(value) {
37
207
  if (this.value === value) {
38
208
  throw new Exception({ message: `${value} is equal to ${this.value}`, code: 1005, status: 'eq' })
39
209
  }
210
+
211
+ return this;
40
212
  }
41
213
  toBeDefined() {
42
214
  if (this.value === undefined) {
43
215
  throw new Exception({ message: `value is undefined`, code: 1006, status: 'undefined' })
44
216
  }
217
+
218
+ return this;
45
219
  }
46
220
  toBeUndefined() {
47
221
  if (this.value !== undefined) {
48
222
  throw new Exception({ message: `value is defined`, code: 1007, status: 'defined' })
49
223
  }
224
+
225
+ return this;
50
226
  }
51
227
  toBeNull() {
52
228
  if (this.value !== null) {
53
229
  throw new Exception({ message: `value is not null`, code: 1008, status: 'not-null' })
54
230
  }
231
+
232
+ return this;
55
233
  }
56
234
  notToBeNull() {
57
235
  if (this.value === null) {
58
236
  throw new Exception({ message: `value is null`, code: 1009, status: 'null' })
59
237
  }
238
+
239
+ return this;
60
240
  }
61
241
  toBeNullOrUndefined() {
62
242
  if (this.value == null) {
63
243
  } else {
64
244
  throw new Exception({ message: `value is not null/undefined`, code: 1010, status: 'not-null-or-undefined' })
65
245
  }
246
+
247
+ return this;
66
248
  }
67
249
  notToBeNullOrUndefined() {
68
250
  if (this.value == null) {
69
251
  throw new Exception({ message: `value is null/undefined`, code: 1011, status: 'null-or-undefined' })
70
252
  }
253
+
254
+ return this;
255
+ }
256
+ notToBeBetween(n, m) {
257
+ if (this.value >= n && this.value < m) {
258
+ throw new Exception({ message: `${this.value} is between ${n} and ${m}`, code: 1044, status: 'not-between' })
259
+ }
260
+
261
+ return this;
262
+ }
263
+ notToBeOfType(type) {
264
+ if (typeof this.value === type) {
265
+ throw new Exception({ message: `${this.value} is of type ${type}`, code: 1045, status: 'not-oftype' })
266
+ }
267
+
268
+ return this;
269
+ }
270
+ notToBeString() {
271
+ if (isString(this.value)) {
272
+ throw new Exception({ message: `${this.value} is string`, code: 1046, status: 'not-is-string' })
273
+ }
274
+
275
+ return this;
276
+ }
277
+ notToBeSomeString() {
278
+ if (isSomeString(this.value)) {
279
+ throw new Exception({ message: `${this.value} is some string`, code: 1047, status: 'not-is-some-string' })
280
+ }
281
+
282
+ return this;
283
+ }
284
+ notToBeNumber() {
285
+ if (isNumber(this.value)) {
286
+ throw new Exception({ message: `${this.value} is number`, code: 1048, status: 'not-is-number' })
287
+ }
288
+
289
+ return this;
290
+ }
291
+ notToBeDate() {
292
+ if (isDate(this.value)) {
293
+ throw new Exception({ message: `${this.value} is date`, code: 1049, status: 'not-is-date' })
294
+ }
295
+
296
+ return this;
297
+ }
298
+ notToBeBool() {
299
+ if (isBool(this.value)) {
300
+ throw new Exception({ message: `${this.value} is bool`, code: 1050, status: 'not-is-bool' })
301
+ }
302
+
303
+ return this;
304
+ }
305
+ notToBeBasicType() {
306
+ if (isBasic(this.value)) {
307
+ throw new Exception({ message: `${this.value} is basic type`, code: 1051, status: 'not-is-basic-type' })
308
+ }
309
+
310
+ return this;
311
+ }
312
+ notToBePrimitive() {
313
+ if (isPrimitive(this.value)) {
314
+ throw new Exception({ message: `${this.value} is primitive type`, code: 1052, status: 'not-is-primitive' })
315
+ }
316
+
317
+ return this;
318
+ }
319
+ notToBeEmpty() {
320
+ if (isEmpty(this.value)) {
321
+ throw new Exception({ message: `${this.value} is empty`, code: 1053, status: 'not-is-empty' })
322
+ }
323
+
324
+ return this;
325
+ }
326
+ notToBeObject() {
327
+ if (isObject(this.value)) {
328
+ throw new Exception({ message: `${this.value} is object`, code: 1054, status: 'not-is-object' })
329
+ }
330
+
331
+ return this;
332
+ }
333
+ notToBeSomeObject() {
334
+ if (isSomeObject(this.value)) {
335
+ throw new Exception({ message: `${this.value} is some object`, code: 1055, status: 'not-is-some-object' })
336
+ }
337
+
338
+ return this;
339
+ }
340
+ notToBeFunction() {
341
+ if (isFunction(this.value)) {
342
+ throw new Exception({ message: `${this.value} is function`, code: 1056, status: 'not-is-function' })
343
+ }
344
+
345
+ return this;
346
+ }
347
+ notToBeNumeric() {
348
+ if (isNumeric(this.value)) {
349
+ throw new Exception({ message: `${this.value} is numeric`, code: 1057, status: 'not-is-numeric' })
350
+ }
351
+
352
+ return this;
353
+ }
354
+ notToBeArray() {
355
+ if (isArray(this.value)) {
356
+ throw new Exception({ message: `${this.value} is array`, code: 1058, status: 'not-is-array' })
357
+ }
358
+
359
+ return this;
360
+ }
361
+ toBeEmptyArray() {
362
+ if (isSomeArray(this.value)) {
363
+ throw new Exception({ message: `${this.value} is some array`, code: 1059, status: 'to-be-empty-array' })
364
+ }
365
+
366
+ return this;
367
+ }
368
+ notToBeIterable() {
369
+ if (isIterable(this.value)) {
370
+ throw new Exception({ message: `${this.value} is iterable`, code: 1060, status: 'not-iterable' })
371
+ }
372
+
373
+ return this;
374
+ }
375
+ notToBeSubClassOf(type) {
376
+ if (isSubClassOf(this.value, type)) {
377
+ throw new Exception({ message: `${this.value} is subclass of ${type}`, code: 1061, status: 'not-subclassof' })
378
+ }
379
+
380
+ return this;
381
+ }
382
+ notToBeInstanceOf(type) {
383
+ if (this.value instanceof type) {
384
+ throw new Exception({ message: `${this.value} is instance of ${type}`, code: 1062, status: 'not-instanceof' })
385
+ }
386
+
387
+ return this;
388
+ }
389
+ doesNotMatch(pattern, flags) {
390
+ const r = new RegExp(pattern, flags)
391
+
392
+ if (r.test(this.value)) {
393
+ throw new Exception({ message: `${this.value} matches ${pattern}`, code: 1063, status: 'not-match' })
394
+ }
395
+
396
+ return this;
397
+ }
398
+ toBeValid(fnValidation) {
399
+ if (!isFunction(fnValidation)) {
400
+ throw new Exception({ message: `fnValidation is not function`, code: 1064, status: 'to-be-valid' })
401
+ }
402
+ if (!fnValidation(this.value)) {
403
+ throw new Exception({ message: `${this.value} is not valid`, code: 1065, status: 'to-be-valid' })
404
+ }
405
+
406
+ return this;
407
+ }
408
+ notToBeValid(fnValidation) {
409
+ if (!isFunction(fnValidation)) {
410
+ throw new Exception({ message: `fnValidation is not function`, code: 1066, status: 'not-to-be-valid' })
411
+ }
412
+ if (fnValidation(this.value)) {
413
+ throw new Exception({ message: `${this.value} is valid`, code: 1067, status: 'not-to-be-valid' })
414
+ }
415
+
416
+ return this;
71
417
  }
72
418
  toThrow(ex, shape = false, strict = false) {
73
419
  if (!isFunction(this.value)) {
@@ -111,6 +457,8 @@ class Expect {
111
457
  if (ok) {
112
458
  throw new Exception({ message: `given function ran without throwing any errors.`, code: 1013, status: 'ran-to-completion' })
113
459
  }
460
+
461
+ return this;
114
462
  }
115
463
  async toThrowAsync(ex, shape = false, strict = false) {
116
464
  if (!isFunction(this.value)) {
@@ -154,6 +502,8 @@ class Expect {
154
502
  if (ok) {
155
503
  throw new Exception({ message: `given function ran without throwing any errors.`, code: 1013, status: 'ran-to-completion' })
156
504
  }
505
+
506
+ return this;
157
507
  }
158
508
  notToThrow(ex, shape = false, strict = false) {
159
509
  if (!isFunction(this.value)) {
@@ -200,6 +550,8 @@ class Expect {
200
550
  if (ok) {
201
551
  throw new Exception({ message: `given function threw an error.`, code: 1014, status: 'ran-to-error', innerException: error })
202
552
  }
553
+
554
+ return this;
203
555
  }
204
556
  async notToThrowAsync(ex, shape = false, strict = false) {
205
557
  if (!isFunction(this.value)) {
@@ -246,30 +598,40 @@ class Expect {
246
598
  if (ok) {
247
599
  throw new Exception({ message: `given function threw an error.`, code: 1014, status: 'ran-to-error', innerException: error })
248
600
  }
601
+
602
+ return this;
249
603
  }
250
604
  toBeTruthy() {
251
605
  if (this.value) {
252
606
  } else {
253
607
  throw new Exception({ message: `${this.value} is not truthy`, code: 1015, status: 'not-truthy' })
254
608
  }
609
+
610
+ return this;
255
611
  }
256
612
  toBeFalsy() {
257
613
  if (!this.value) {
258
614
  } else {
259
615
  throw new Exception({ message: `${this.value} is not falsy`, code: 1016, status: 'not-falsy' })
260
616
  }
617
+
618
+ return this;
261
619
  }
262
620
  toBeNaN() {
263
621
  if (isNaN(this.value)) {
264
622
  } else {
265
623
  throw new Exception({ message: `${this.value} is not NaN`, code: 1017, status: 'not-nan' })
266
624
  }
625
+
626
+ return this;
267
627
  }
268
628
  notToBeNaN() {
269
629
  if (!isNaN(this.value)) {
270
630
  } else {
271
631
  throw new Exception({ message: `${this.value} is NaN`, code: 1023, status: 'is-nan' })
272
632
  }
633
+
634
+ return this;
273
635
  }
274
636
  }
275
637
 
package/package.json CHANGED
@@ -1,12 +1,9 @@
1
1
  {
2
2
  "name": "@locustjs/test",
3
- "version": "1.1.7",
3
+ "version": "1.3.0",
4
4
  "description": "This library provides a simple test runner.",
5
5
  "main": "index.cjs.js",
6
6
  "module": "index.esm.js",
7
- "scripts": {
8
- "build": "babel index.esm.js -o index.cjs.js"
9
- },
10
7
  "repository": {
11
8
  "type": "git",
12
9
  "url": "git+https://github.com/ironcodev/locustjs-test.git"
@@ -27,6 +24,11 @@
27
24
  },
28
25
  "devDependencies": {
29
26
  "@babel/cli": "^7.22.6",
30
- "@babel/core": "^7.22.8"
27
+ "@babel/core": "^7.22.8",
28
+ "esm": "^3.2.25"
29
+ },
30
+ "scripts": {
31
+ "build": "babel index.esm.js -o index.cjs.js",
32
+ "test": "node -r esm ./tests/index.js"
31
33
  }
32
- }
34
+ }
package/tests/index.js ADDED
@@ -0,0 +1,116 @@
1
+ import TestRunner from "../index.esm.js";
2
+
3
+ class Foo {}
4
+ class Bar extends Foo {}
5
+ class Buz {}
6
+
7
+ const tests = [
8
+ [
9
+ "Test 1: number",
10
+ function (expect) {
11
+ const n = 10;
12
+
13
+ expect(n)
14
+ .toBeDefined()
15
+ .toBeBasicType()
16
+ .toBePrimitive()
17
+ .toBeNumber()
18
+ .toBeNumeric()
19
+ .toBeGt(8)
20
+ .toBeGte(10)
21
+ .toBeLt(12)
22
+ .toBeLte(10)
23
+ .toBeBetween(5, 15)
24
+ .notToBeBetween(12, 20)
25
+ .toBeOfType("number");
26
+
27
+ expect(n)
28
+ .toBeValid(x => x > 2)
29
+ .notToBeValid(x => x < 2);
30
+ },
31
+ ],
32
+ [
33
+ "Test 2: string",
34
+ function (expect) {
35
+ const n = "10";
36
+
37
+ expect(n)
38
+ .toBeDefined()
39
+ .notToBeNumber()
40
+ .toBeNumeric()
41
+ .toBeOfType("string")
42
+ .toBeString()
43
+ .toBeSomeString();
44
+ },
45
+ ],
46
+ [
47
+ "Test 3: empty array",
48
+ function (expect) {
49
+ const n = [];
50
+
51
+ expect(n)
52
+ .toBeDefined()
53
+ .toBeArray()
54
+ .toBeEmptyArray();
55
+ },
56
+ ],
57
+ [
58
+ "Test 4: array",
59
+ function (expect) {
60
+ const n = [10];
61
+
62
+ expect(n)
63
+ .toBeDefined()
64
+ .toBeArray()
65
+ .toBeSomeArray();
66
+ },
67
+ ],
68
+ [
69
+ "Test 3: empty object",
70
+ function (expect) {
71
+ const n = {};
72
+
73
+ expect(n)
74
+ .toBeDefined()
75
+ .notToBeBasicType()
76
+ .notToBePrimitive()
77
+ .notToBeNull()
78
+ .toBeObject()
79
+ .notToBeSomeObject();
80
+ },
81
+ ],
82
+ [
83
+ "Test 4: object",
84
+ function (expect) {
85
+ const n = {a:10};
86
+
87
+ expect(n)
88
+ .toBeDefined()
89
+ .notToBeBasicType()
90
+ .notToBePrimitive()
91
+ .notToBeNull()
92
+ .toBeObject()
93
+ .toBeSomeObject();
94
+ },
95
+ ],
96
+ [
97
+ "Test 4: class",
98
+ function (expect) {
99
+ const x = new Bar();
100
+
101
+ expect(x)
102
+ .toBeDefined()
103
+ .toBeObject()
104
+ .notToBeSomeObject()
105
+ .toBeInstanceOf(Bar)
106
+ .toBeInstanceOf(Foo)
107
+ .notToBeInstanceOf(Buz);
108
+ },
109
+ ]
110
+ ];
111
+
112
+ const runner = new TestRunner();
113
+
114
+ runner.run(tests).then((result) => {
115
+ runner.report(result.failed > 0);
116
+ });