supertape 10.2.2 → 10.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/ChangeLog +5 -0
- package/README.md +31 -38
- package/bin/communication.mjs +1 -1
- package/lib/run-tests.js +22 -6
- package/lib/supertape.d.ts +1 -0
- package/lib/supertape.js +9 -2
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -38,6 +38,24 @@
|
|
|
38
38
|
|
|
39
39
|
For a list of all built-in assertions, see [Operators](#operators).
|
|
40
40
|
|
|
41
|
+
## How 📼**Supertape** test looks like?
|
|
42
|
+
|
|
43
|
+
You can use both **CommonJS** and **ESM**, here is **ESM** example:
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
import {test} from 'supertape';
|
|
47
|
+
|
|
48
|
+
const sump = (a, b) => a + b;
|
|
49
|
+
|
|
50
|
+
test('calc: sum', (t) => {
|
|
51
|
+
const result = sum(1, 2);
|
|
52
|
+
const expected = 3;
|
|
53
|
+
|
|
54
|
+
t.equal(result, expected);
|
|
55
|
+
t.end();
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
41
59
|
## Install
|
|
42
60
|
|
|
43
61
|
```
|
|
@@ -61,7 +79,7 @@ Options
|
|
|
61
79
|
|
|
62
80
|
## Environment variables
|
|
63
81
|
|
|
64
|
-
- `SUPERTAPE_TIMEOUT` - timeout for long running processes;
|
|
82
|
+
- `SUPERTAPE_TIMEOUT` - timeout for long running processes, defaults to `3000` (3 seconds);
|
|
65
83
|
- `SUPERTAPE_CHECK_DUPLICATES` - toggle check duplicates;
|
|
66
84
|
- `SUPERTAPE_CHECK_SCOPES` - check that test message has a scope: `scope: subject`;
|
|
67
85
|
- `SUPERTAPE_CHECK_ASSERTIONS_COUNT` - check that assertion count is no more then 1;
|
|
@@ -179,55 +197,30 @@ There is a list of built-int `formatters` to customize output:
|
|
|
179
197
|
|
|
180
198
|
## API
|
|
181
199
|
|
|
182
|
-
###
|
|
183
|
-
|
|
184
|
-
The assertion methods in `supertape` are heavily influenced by [tape](https://github.com/substack/tape).
|
|
185
|
-
|
|
186
|
-
```js
|
|
187
|
-
const test = require('supertape');
|
|
188
|
-
const {sum} = require('./calc.js');
|
|
189
|
-
|
|
190
|
-
test('calc: sum', (t) => {
|
|
191
|
-
const result = sum(1, 2);
|
|
192
|
-
const expected = 3;
|
|
193
|
-
|
|
194
|
-
t.equal(result, expected);
|
|
195
|
-
t.end();
|
|
196
|
-
});
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
or in `ESM`:
|
|
200
|
-
|
|
201
|
-
```js
|
|
202
|
-
import {test} from 'supertape';
|
|
203
|
-
import {sum} from './calc.js';
|
|
200
|
+
### test(message: string, fn: (t: Test) => void, options?: TestOptions)
|
|
204
201
|
|
|
205
|
-
test
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
t.equal(result, expected);
|
|
210
|
-
t.end();
|
|
211
|
-
});
|
|
212
|
-
```
|
|
202
|
+
Create a new test with `message` string.
|
|
203
|
+
`fn(t)` fires with the new test object `t` once all preceding tests have
|
|
204
|
+
finished. Tests execute serially.
|
|
213
205
|
|
|
214
|
-
|
|
206
|
+
Here is Possible `options` similar to [Environment Variables](#environment-variables) but relates to one test:
|
|
215
207
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
208
|
+
- `checkDuplicates`;
|
|
209
|
+
- `checkScopes`;-
|
|
210
|
+
- `checkAssertionsCount`;
|
|
211
|
+
- `timeout`;
|
|
219
212
|
|
|
220
|
-
|
|
213
|
+
### test.only(message, fn, options?)
|
|
221
214
|
|
|
222
215
|
Like `test(name, cb)` except if you use `.only` this is the only test case
|
|
223
216
|
that will run for the entire process, all other test cases using `tape` will
|
|
224
217
|
be ignored.
|
|
225
218
|
|
|
226
|
-
|
|
219
|
+
### test.skip(message, fn, options?)
|
|
227
220
|
|
|
228
221
|
Generate a new test that will be skipped over.
|
|
229
222
|
|
|
230
|
-
|
|
223
|
+
### test.extend(extensions)
|
|
231
224
|
|
|
232
225
|
Extend base assertions with more:
|
|
233
226
|
|
package/bin/communication.mjs
CHANGED
package/lib/run-tests.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const process = require('process');
|
|
4
3
|
const fullstore = require('fullstore');
|
|
5
4
|
const wraptile = require('wraptile');
|
|
6
5
|
const tryToCatch = require('try-to-catch');
|
|
@@ -15,10 +14,9 @@ const notSkip = ({skip}) => !skip;
|
|
|
15
14
|
|
|
16
15
|
const getInitOperators = async () => await import('./operators.mjs');
|
|
17
16
|
|
|
18
|
-
const {SUPERTAPE_TIMEOUT = 3000} = process.env;
|
|
19
17
|
const DEBUG_TIME = 3000 * 1000;
|
|
20
18
|
|
|
21
|
-
const
|
|
19
|
+
const doTimeout = (time, value) => {
|
|
22
20
|
let stop;
|
|
23
21
|
|
|
24
22
|
if (isDebug)
|
|
@@ -73,7 +71,7 @@ async function runTests(tests, {formatter, operators, skiped, isStop}) {
|
|
|
73
71
|
tests,
|
|
74
72
|
});
|
|
75
73
|
|
|
76
|
-
for (const {fn, message, extensions, at, validations} of tests) {
|
|
74
|
+
for (const {fn, message, timeout, extensions, at, validations} of tests) {
|
|
77
75
|
if (wasStop())
|
|
78
76
|
break;
|
|
79
77
|
|
|
@@ -95,6 +93,7 @@ async function runTests(tests, {formatter, operators, skiped, isStop}) {
|
|
|
95
93
|
incPassed,
|
|
96
94
|
getValidationMessage,
|
|
97
95
|
validations,
|
|
96
|
+
timeout,
|
|
98
97
|
|
|
99
98
|
extensions: {
|
|
100
99
|
...operators,
|
|
@@ -118,7 +117,24 @@ async function runTests(tests, {formatter, operators, skiped, isStop}) {
|
|
|
118
117
|
};
|
|
119
118
|
}
|
|
120
119
|
|
|
121
|
-
async function runOneTest(
|
|
120
|
+
async function runOneTest(options) {
|
|
121
|
+
const {
|
|
122
|
+
message,
|
|
123
|
+
at,
|
|
124
|
+
fn,
|
|
125
|
+
extensions,
|
|
126
|
+
formatter,
|
|
127
|
+
count,
|
|
128
|
+
total,
|
|
129
|
+
failed,
|
|
130
|
+
incCount,
|
|
131
|
+
incPassed,
|
|
132
|
+
incFailed,
|
|
133
|
+
getValidationMessage,
|
|
134
|
+
validations,
|
|
135
|
+
timeout,
|
|
136
|
+
} = options;
|
|
137
|
+
|
|
122
138
|
const isReturn = fullstore(false);
|
|
123
139
|
const assertionsCount = fullstore(0);
|
|
124
140
|
const isEnded = fullstore(false);
|
|
@@ -145,7 +161,7 @@ async function runOneTest({message, at, fn, extensions, formatter, count, total,
|
|
|
145
161
|
});
|
|
146
162
|
|
|
147
163
|
if (!isReturn()) {
|
|
148
|
-
const [timer, stopTimer] = timeout
|
|
164
|
+
const [timer, stopTimer] = doTimeout(timeout, ['timeout']);
|
|
149
165
|
const [error] = await Promise.race([tryToCatch(fn, t), timer]);
|
|
150
166
|
|
|
151
167
|
stopTimer();
|
package/lib/supertape.d.ts
CHANGED
package/lib/supertape.js
CHANGED
|
@@ -20,7 +20,10 @@ const {assign} = Object;
|
|
|
20
20
|
const {stdout} = process;
|
|
21
21
|
|
|
22
22
|
// 5ms ought to be enough for anybody
|
|
23
|
-
const {
|
|
23
|
+
const {
|
|
24
|
+
SUPERTAPE_LOAD_LOOP_TIMEOUT = 5,
|
|
25
|
+
SUPERTAPE_TIMEOUT = 3000,
|
|
26
|
+
} = process.env;
|
|
24
27
|
|
|
25
28
|
let mainEmitter;
|
|
26
29
|
|
|
@@ -44,13 +47,14 @@ const defaultOptions = {
|
|
|
44
47
|
checkIfEnded: true,
|
|
45
48
|
checkAssertionsCount: true,
|
|
46
49
|
checkScopes: true,
|
|
50
|
+
timeout: SUPERTAPE_TIMEOUT,
|
|
47
51
|
};
|
|
48
52
|
|
|
49
53
|
function _createEmitter({quiet, stream = stdout, format, getOperators, isStop, readyFormatter, workerFormatter}) {
|
|
50
54
|
const tests = [];
|
|
51
55
|
const emitter = new EventEmitter();
|
|
52
56
|
|
|
53
|
-
emitter.on('test', (message, fn, {skip, only, extensions, at, validations}) => {
|
|
57
|
+
emitter.on('test', (message, fn, {skip, only, extensions, at, validations, timeout}) => {
|
|
54
58
|
tests.push({
|
|
55
59
|
message,
|
|
56
60
|
fn,
|
|
@@ -59,6 +63,7 @@ function _createEmitter({quiet, stream = stdout, format, getOperators, isStop, r
|
|
|
59
63
|
extensions,
|
|
60
64
|
at,
|
|
61
65
|
validations,
|
|
66
|
+
timeout,
|
|
62
67
|
});
|
|
63
68
|
});
|
|
64
69
|
|
|
@@ -154,6 +159,7 @@ function test(message, fn, options = {}) {
|
|
|
154
159
|
checkAssertionsCount,
|
|
155
160
|
checkIfEnded,
|
|
156
161
|
workerFormatter,
|
|
162
|
+
timeout,
|
|
157
163
|
} = {
|
|
158
164
|
...defaultOptions,
|
|
159
165
|
...initedOptions,
|
|
@@ -186,6 +192,7 @@ function test(message, fn, options = {}) {
|
|
|
186
192
|
extensions,
|
|
187
193
|
at,
|
|
188
194
|
validations,
|
|
195
|
+
timeout,
|
|
189
196
|
});
|
|
190
197
|
|
|
191
198
|
if (run)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "supertape",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.3.0",
|
|
4
4
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
5
|
"description": "📼 Supertape simplest high speed test runner with superpowers",
|
|
6
6
|
"homepage": "http://github.com/coderaiser/supertape",
|