@locustjs/test 1.5.0 → 1.6.1
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/.babelrc +3 -0
- package/README.md +143 -24
- package/index.cjs.js +1649 -1150
- package/index.esm.js +358 -274
- package/package.json +6 -1
- package/tests/index.js +7 -1
package/.babelrc
ADDED
package/README.md
CHANGED
|
@@ -1,33 +1,11 @@
|
|
|
1
|
-
#
|
|
2
|
-
This library provides a simple test runner.
|
|
1
|
+
# @locustjs/test
|
|
2
|
+
This library provides a simple test runner for unit-testing.
|
|
3
3
|
|
|
4
4
|
# Install
|
|
5
5
|
```
|
|
6
6
|
npm i @locustjs/test
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
# Matchers
|
|
10
|
-
- `toBe()`
|
|
11
|
-
- `notToBe()`
|
|
12
|
-
- `toBeGt()`
|
|
13
|
-
- `toBeGte()`
|
|
14
|
-
- `toBeLt()`
|
|
15
|
-
- `toBeLte()`
|
|
16
|
-
- `toBeDefined()`
|
|
17
|
-
- `toBeUndefined()`
|
|
18
|
-
- `toBeNull()`
|
|
19
|
-
- `notToBeNull()`
|
|
20
|
-
- `toBeNullOrUndefined()`
|
|
21
|
-
- `notToBeNullOrUndefined()`
|
|
22
|
-
- `toThrow()`
|
|
23
|
-
- `toThrowAsync()`
|
|
24
|
-
- `notToThrow()`
|
|
25
|
-
- `notToThrowAsync()`
|
|
26
|
-
- `toBeTruthy()`
|
|
27
|
-
- `toBeFalsy()`
|
|
28
|
-
- `toBeNaN()`
|
|
29
|
-
- `notToBeNaN()`
|
|
30
|
-
|
|
31
9
|
Example:
|
|
32
10
|
```javascript
|
|
33
11
|
import TestRunner from '@locustjs/test';
|
|
@@ -45,3 +23,144 @@ await runner.run(tests);
|
|
|
45
23
|
runner.report();
|
|
46
24
|
runner.log();
|
|
47
25
|
```
|
|
26
|
+
|
|
27
|
+
Sample output:
|
|
28
|
+
|
|
29
|
+
1. Test 1: number: <span style="color:green">passed</span> (0 sec)
|
|
30
|
+
|
|
31
|
+
2. Test 2: string: <span style="color:green">passed</span> (0 sec)
|
|
32
|
+
|
|
33
|
+
3. Test 3: empty array: <span style="color:green">passed</span> (0 sec)
|
|
34
|
+
|
|
35
|
+
4. Test 4: array: <span style="color:green">passed</span> (0 sec)
|
|
36
|
+
|
|
37
|
+
5. Test 5: empty object: <span style="color:green">passed</span> (0 sec)
|
|
38
|
+
|
|
39
|
+
6. Test 6: object: <span style="color:green">passed</span> (0 sec)
|
|
40
|
+
|
|
41
|
+
7. <b>Test 7: error:</b> <span style="color:red">failed</span> (0.001 sec)
|
|
42
|
+
<div style="color:gray; margin-left: 50px">error 501: test 'Test 7: error' failed.</div>
|
|
43
|
+
<div style="color:yellow; margin-left: 50px">10 is not greater than 20</div>
|
|
44
|
+
|
|
45
|
+
8. <b>Test 8: not expected:</b> <span style="color:magenta">expect not used</span> (0 sec)
|
|
46
|
+
|
|
47
|
+
9. <b>Test 9: error without expect:</b> <span style="color:magenta">expect not used</span> (0 sec)
|
|
48
|
+
<div style="color:gray; margin-left: 50px">error 501: test 'Test 9: error without expect' failed.</div>
|
|
49
|
+
<div style="color:yellow; margin-left: 50px">some err</div>
|
|
50
|
+
|
|
51
|
+
10. Test 10: class: <span style="color:green">passed</span> (0 sec)
|
|
52
|
+
|
|
53
|
+
<div><b>Number of tests: 8</b></div>
|
|
54
|
+
<div><b>Total Time: 0.001</b> sec</div>
|
|
55
|
+
<br/>
|
|
56
|
+
<span style="color:green">7 test(s) passed</span>, <span style="color:red">1 test(s) failed</span>, <span style="color:magenta">2 test(s) are unknown</span>
|
|
57
|
+
|
|
58
|
+
# expect
|
|
59
|
+
Positive
|
|
60
|
+
- `toBe(value)`
|
|
61
|
+
- `toBeGt(value)`
|
|
62
|
+
- `toBeGreaterThan(value)`
|
|
63
|
+
- `toBeGte(value)`
|
|
64
|
+
- `toBeGreaterThanOrEqualTo(value)`
|
|
65
|
+
- `toBeLt(value)`
|
|
66
|
+
- `toBeLowerThan(value)`
|
|
67
|
+
- `toBeLte(value)`
|
|
68
|
+
- `toBeLowerThanOrEqualTo(value)`
|
|
69
|
+
- `toBeBetween(n, m)`
|
|
70
|
+
- `toBeOfType(type)`
|
|
71
|
+
- `toBeString()`
|
|
72
|
+
- `toBeSomeString()`
|
|
73
|
+
- `toBeNumber()`
|
|
74
|
+
- `toBeNumeric()`
|
|
75
|
+
- `toBeDate()`
|
|
76
|
+
- `toBeBool()`
|
|
77
|
+
- `toBeBasicType()`
|
|
78
|
+
- `toBePrimitive()`
|
|
79
|
+
- `toBeEmpty()`
|
|
80
|
+
- `toBeObject()`
|
|
81
|
+
- `toBeSomeObject()`
|
|
82
|
+
- `toBeFunction()`
|
|
83
|
+
- `toBeArray()`
|
|
84
|
+
- `toBeEmptyArray()`
|
|
85
|
+
- `toBeSomeArray()`
|
|
86
|
+
- `toBeIterable()`
|
|
87
|
+
- `toBeSubClassOf(type)`
|
|
88
|
+
- `toBeInstanceOf(type)`
|
|
89
|
+
- `toMatch(pattern, flags)`
|
|
90
|
+
- `toBeDefined()`
|
|
91
|
+
- `toBeUndefined()`
|
|
92
|
+
- `toBeNull()`
|
|
93
|
+
- `toBeNullOrUndefined()`
|
|
94
|
+
- `toBeValid(fnValidation)`
|
|
95
|
+
- `toThrow(ex, shape = false, strict = false)`
|
|
96
|
+
- `async toThrowAsync(ex, shape = false, strict = false)`
|
|
97
|
+
- `toBeTruthy()`
|
|
98
|
+
- `toBeTrue()`
|
|
99
|
+
- `toBeFalsy()`
|
|
100
|
+
- `toBeFalse()`
|
|
101
|
+
- `toBeNaN()`
|
|
102
|
+
|
|
103
|
+
Negative
|
|
104
|
+
- `notToBe(value)`
|
|
105
|
+
- `notToBeBetween(n, m)`
|
|
106
|
+
- `notToBeOfType(type)`
|
|
107
|
+
- `notToBeString()`
|
|
108
|
+
- `notToBeSomeString()`
|
|
109
|
+
- `notToBeNumber()`
|
|
110
|
+
- `notToBeDate()`
|
|
111
|
+
- `notToBeBool()`
|
|
112
|
+
- `notToBeBasicType()`
|
|
113
|
+
- `notToBePrimitive()`
|
|
114
|
+
- `notToBeEmpty()`
|
|
115
|
+
- `notToBeObject()`
|
|
116
|
+
- `notToBeSomeObject()`
|
|
117
|
+
- `notToBeFunction()`
|
|
118
|
+
- `notToBeNumeric()`
|
|
119
|
+
- `notToBeArray()`
|
|
120
|
+
- `notToBeSomeArray()`
|
|
121
|
+
- `notToBeIterable()`
|
|
122
|
+
- `notToBeSubClassOf(type)`
|
|
123
|
+
- `notToBeInstanceOf(type)`
|
|
124
|
+
- `notToMatch(pattern, flags)`
|
|
125
|
+
- `doesNotMatch(pattern, flags)`
|
|
126
|
+
- `notToBeDefined()`
|
|
127
|
+
- `notToBeUndefined()`
|
|
128
|
+
- `notToBeNull()`
|
|
129
|
+
- `notToBeNullOrUndefined()`
|
|
130
|
+
- `notToBeValid(fnValidation)`
|
|
131
|
+
- `notToThrow(ex, shape = false, strict = false)`
|
|
132
|
+
- `async notToThrowAsync(ex, shape = false, strict = false)`
|
|
133
|
+
- `notToBeNaN()`
|
|
134
|
+
|
|
135
|
+
`TestRunner` has a static method `start()` that simplifies running tests.
|
|
136
|
+
|
|
137
|
+
```javascript
|
|
138
|
+
const tests = [
|
|
139
|
+
...
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
TestRunner.start(tests);
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
It is possible to pass multiple tests to `start()` method.
|
|
146
|
+
|
|
147
|
+
```javascript
|
|
148
|
+
import tests1 from './test1.js'
|
|
149
|
+
import tests2 from './test2.js'
|
|
150
|
+
import tests3 from './test3.js'
|
|
151
|
+
|
|
152
|
+
TestRunner.start(tests1, tests2, tests3);
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
The above example is equal to merging all tests arrays and pass one array to `start()`.
|
|
156
|
+
|
|
157
|
+
```javascript
|
|
158
|
+
TestRunner.start([...tests1, ...tests2, ...tests3])
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
By default, test runner shows detailed output only when there is at least one error. However, by passing `true` as the last argument of `start()` method, we can ask the detailed output is always shows.
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
TestRunner.start(tests, true);
|
|
165
|
+
TestRunner.start(tests1, tests2, tests3, true);
|
|
166
|
+
```
|