supertape 12.0.4 → 12.0.6
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 +13 -0
- package/lib/cli/parse-args.js +1 -0
- package/lib/cli.js +6 -6
- package/lib/emitter.mjs +61 -0
- package/lib/is-debug.js +1 -1
- package/lib/run-tests.js +28 -7
- package/lib/supertape.js +72 -84
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/lib/cli/parse-args.js
CHANGED
package/lib/cli.js
CHANGED
|
@@ -159,10 +159,6 @@ async function _cli(overrides) {
|
|
|
159
159
|
workerFormatter,
|
|
160
160
|
});
|
|
161
161
|
|
|
162
|
-
const stream = await supertape.createStream();
|
|
163
|
-
|
|
164
|
-
stream.pipe(stdout);
|
|
165
|
-
|
|
166
162
|
const files = removeDuplicates(allFiles);
|
|
167
163
|
|
|
168
164
|
filesCount(files.length);
|
|
@@ -170,6 +166,9 @@ async function _cli(overrides) {
|
|
|
170
166
|
if (!files.length)
|
|
171
167
|
return OK;
|
|
172
168
|
|
|
169
|
+
const stream = await supertape.createStream();
|
|
170
|
+
stream.pipe(stdout);
|
|
171
|
+
|
|
173
172
|
const resolvedNames = [];
|
|
174
173
|
|
|
175
174
|
// always resolve before import for windows
|
|
@@ -177,8 +176,9 @@ async function _cli(overrides) {
|
|
|
177
176
|
resolvedNames.push(pathToFileURL(resolvePath(cwd, file)));
|
|
178
177
|
}
|
|
179
178
|
|
|
180
|
-
|
|
181
|
-
|
|
179
|
+
if (!args.dryRun)
|
|
180
|
+
for (const resolved of resolvedNames)
|
|
181
|
+
await import(resolved);
|
|
182
182
|
|
|
183
183
|
const [result] = await once(supertape.run(), 'end');
|
|
184
184
|
|
package/lib/emitter.mjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {stdout} from 'node:process';
|
|
2
|
+
import {EventEmitter} from 'node:events';
|
|
3
|
+
import runTests from './run-tests.js';
|
|
4
|
+
|
|
5
|
+
export const createEmitter = (overrides = {}) => {
|
|
6
|
+
const {
|
|
7
|
+
quiet,
|
|
8
|
+
stream = stdout,
|
|
9
|
+
format,
|
|
10
|
+
getOperators,
|
|
11
|
+
isStop,
|
|
12
|
+
readyFormatter,
|
|
13
|
+
workerFormatter,
|
|
14
|
+
createFormatter,
|
|
15
|
+
loop,
|
|
16
|
+
isDebug,
|
|
17
|
+
} = overrides;
|
|
18
|
+
|
|
19
|
+
const tests = [];
|
|
20
|
+
const emitter = new EventEmitter();
|
|
21
|
+
|
|
22
|
+
emitter.on('test', (message, fn, {skip, only, extensions, at, validations, timeout}) => {
|
|
23
|
+
tests.push({
|
|
24
|
+
message,
|
|
25
|
+
fn,
|
|
26
|
+
skip,
|
|
27
|
+
only,
|
|
28
|
+
extensions,
|
|
29
|
+
at,
|
|
30
|
+
validations,
|
|
31
|
+
timeout,
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
emitter.on('loop', () => {
|
|
36
|
+
loop({
|
|
37
|
+
emitter,
|
|
38
|
+
tests,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
emitter.on('run', async () => {
|
|
43
|
+
const {harness, formatter} = readyFormatter || await createFormatter(format);
|
|
44
|
+
|
|
45
|
+
if (!quiet)
|
|
46
|
+
harness.pipe(stream);
|
|
47
|
+
|
|
48
|
+
const operators = await getOperators();
|
|
49
|
+
|
|
50
|
+
const result = await runTests(tests, {
|
|
51
|
+
formatter: workerFormatter || formatter,
|
|
52
|
+
operators,
|
|
53
|
+
isStop,
|
|
54
|
+
isDebug,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
emitter.emit('end', result);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return emitter;
|
|
61
|
+
};
|
package/lib/is-debug.js
CHANGED
package/lib/run-tests.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const fullstore = require('fullstore');
|
|
4
4
|
const wraptile = require('wraptile');
|
|
5
5
|
const {tryToCatch} = require('try-to-catch');
|
|
6
|
-
const
|
|
6
|
+
const _isDebug = require('./is-debug');
|
|
7
7
|
|
|
8
8
|
const {createValidator} = require('./validator');
|
|
9
9
|
|
|
@@ -17,10 +17,10 @@ const getInitOperators = async () => await import('./operators.mjs');
|
|
|
17
17
|
|
|
18
18
|
const DEBUG_TIME = 3000 * 1000;
|
|
19
19
|
|
|
20
|
-
const doTimeout = (time, value) => {
|
|
20
|
+
const doTimeout = (time, value, {isDebug}) => {
|
|
21
21
|
let stop;
|
|
22
22
|
|
|
23
|
-
if (isDebug)
|
|
23
|
+
if (isDebug())
|
|
24
24
|
time = DEBUG_TIME;
|
|
25
25
|
|
|
26
26
|
const promise = new Promise((resolve) => {
|
|
@@ -31,7 +31,14 @@ const doTimeout = (time, value) => {
|
|
|
31
31
|
return [promise, stop];
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
module.exports = async (tests,
|
|
34
|
+
module.exports = async (tests, overrides = {}) => {
|
|
35
|
+
const {
|
|
36
|
+
formatter,
|
|
37
|
+
operators,
|
|
38
|
+
isStop,
|
|
39
|
+
isDebug = _isDebug,
|
|
40
|
+
} = overrides;
|
|
41
|
+
|
|
35
42
|
const onlyTests = tests.filter(isOnly);
|
|
36
43
|
|
|
37
44
|
if (onlyTests.length)
|
|
@@ -40,6 +47,7 @@ module.exports = async (tests, {formatter, operators, isStop}) => {
|
|
|
40
47
|
operators,
|
|
41
48
|
skipped: tests.length - onlyTests.length,
|
|
42
49
|
isStop,
|
|
50
|
+
isDebug,
|
|
43
51
|
});
|
|
44
52
|
|
|
45
53
|
const notSkippedTests = tests.filter(notSkip);
|
|
@@ -50,10 +58,19 @@ module.exports = async (tests, {formatter, operators, isStop}) => {
|
|
|
50
58
|
operators,
|
|
51
59
|
skipped,
|
|
52
60
|
isStop,
|
|
61
|
+
isDebug,
|
|
53
62
|
});
|
|
54
63
|
};
|
|
55
64
|
|
|
56
|
-
async function runTests(tests,
|
|
65
|
+
async function runTests(tests, overrides = {}) {
|
|
66
|
+
const {
|
|
67
|
+
formatter,
|
|
68
|
+
operators,
|
|
69
|
+
skipped,
|
|
70
|
+
isStop,
|
|
71
|
+
isDebug,
|
|
72
|
+
} = overrides;
|
|
73
|
+
|
|
57
74
|
const count = fullstore(0);
|
|
58
75
|
const failed = fullstore(0);
|
|
59
76
|
const passed = fullstore(0);
|
|
@@ -95,7 +112,7 @@ async function runTests(tests, {formatter, operators, skipped, isStop}) {
|
|
|
95
112
|
getValidationMessage,
|
|
96
113
|
validations,
|
|
97
114
|
timeout,
|
|
98
|
-
|
|
115
|
+
isDebug,
|
|
99
116
|
extensions: {
|
|
100
117
|
...operators,
|
|
101
118
|
...extensions,
|
|
@@ -134,6 +151,7 @@ async function runOneTest(options) {
|
|
|
134
151
|
getValidationMessage,
|
|
135
152
|
validations,
|
|
136
153
|
timeout,
|
|
154
|
+
isDebug,
|
|
137
155
|
} = options;
|
|
138
156
|
|
|
139
157
|
const isReturn = fullstore(false);
|
|
@@ -162,7 +180,10 @@ async function runOneTest(options) {
|
|
|
162
180
|
});
|
|
163
181
|
|
|
164
182
|
if (!isReturn()) {
|
|
165
|
-
const [timer, stopTimer] = doTimeout(timeout, ['timeout']
|
|
183
|
+
const [timer, stopTimer] = doTimeout(timeout, ['timeout'], {
|
|
184
|
+
isDebug,
|
|
185
|
+
});
|
|
186
|
+
|
|
166
187
|
const [error] = await Promise.race([tryToCatch(fn, t), timer]);
|
|
167
188
|
|
|
168
189
|
stopTimer();
|
package/lib/supertape.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const process = require('node:process');
|
|
4
3
|
const {EventEmitter} = require('node:events');
|
|
4
|
+
const process = require('node:process');
|
|
5
5
|
const {PassThrough} = require('node:stream');
|
|
6
6
|
|
|
7
7
|
const stub = require('@cloudcmd/stub');
|
|
@@ -12,20 +12,32 @@ const {maybeOnce} = require('./maybe-once');
|
|
|
12
12
|
const options = require('../supertape.json');
|
|
13
13
|
|
|
14
14
|
const {getAt, setValidations} = require('./validator');
|
|
15
|
-
const runTests = require('./run-tests');
|
|
16
|
-
const _createFormatter = require('./formatter').createFormatter;
|
|
17
|
-
const createFormatter = once(_createFormatter);
|
|
18
|
-
|
|
19
|
-
const createEmitter = once(_createEmitter);
|
|
20
15
|
|
|
16
|
+
const {createEmitter: _createEmitter} = require('./emitter.mjs');
|
|
17
|
+
const _createFormatter = require('./formatter').createFormatter;
|
|
18
|
+
const {env} = process;
|
|
21
19
|
const {assign} = Object;
|
|
22
|
-
const
|
|
20
|
+
const createEmitter = once(_createEmitter);
|
|
21
|
+
const createFormatter = once(_createFormatter);
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
const createExtend = (test) => (extensions) => {
|
|
24
|
+
const extendedTest = getExtend(test, extensions);
|
|
25
|
+
|
|
26
|
+
assign(extendedTest, {
|
|
27
|
+
test: extendedTest,
|
|
28
|
+
stub,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
extendedTest.only = getExtend(test, extensions, {
|
|
32
|
+
only: true,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
extendedTest.skip = getExtend(test, extensions, {
|
|
36
|
+
skip: true,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return extendedTest;
|
|
40
|
+
};
|
|
29
41
|
|
|
30
42
|
let mainEmitter;
|
|
31
43
|
|
|
@@ -36,7 +48,7 @@ const getOperators = once(async () => {
|
|
|
36
48
|
return await loadOperators(operators);
|
|
37
49
|
});
|
|
38
50
|
|
|
39
|
-
const
|
|
51
|
+
const getDefaultOptions = () => ({
|
|
40
52
|
skip: false,
|
|
41
53
|
only: false,
|
|
42
54
|
extensions: {},
|
|
@@ -49,52 +61,8 @@ const defaultOptions = {
|
|
|
49
61
|
checkIfEnded: true,
|
|
50
62
|
checkAssertionsCount: true,
|
|
51
63
|
checkScopes: true,
|
|
52
|
-
timeout: SUPERTAPE_TIMEOUT,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
function _createEmitter({quiet, stream = stdout, format, getOperators, isStop, readyFormatter, workerFormatter}) {
|
|
56
|
-
const tests = [];
|
|
57
|
-
const emitter = new EventEmitter();
|
|
58
|
-
|
|
59
|
-
emitter.on('test', (message, fn, {skip, only, extensions, at, validations, timeout}) => {
|
|
60
|
-
tests.push({
|
|
61
|
-
message,
|
|
62
|
-
fn,
|
|
63
|
-
skip,
|
|
64
|
-
only,
|
|
65
|
-
extensions,
|
|
66
|
-
at,
|
|
67
|
-
validations,
|
|
68
|
-
timeout,
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
emitter.on('loop', () => {
|
|
73
|
-
loop({
|
|
74
|
-
emitter,
|
|
75
|
-
tests,
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
emitter.on('run', async () => {
|
|
80
|
-
const {harness, formatter} = readyFormatter || await createFormatter(format);
|
|
81
|
-
|
|
82
|
-
if (!quiet)
|
|
83
|
-
harness.pipe(stream);
|
|
84
|
-
|
|
85
|
-
const operators = await getOperators();
|
|
86
|
-
|
|
87
|
-
const result = await runTests(tests, {
|
|
88
|
-
formatter: workerFormatter || formatter,
|
|
89
|
-
operators,
|
|
90
|
-
isStop,
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
emitter.emit('end', result);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
return emitter;
|
|
97
|
-
}
|
|
64
|
+
timeout: env.SUPERTAPE_TIMEOUT || 3000,
|
|
65
|
+
});
|
|
98
66
|
|
|
99
67
|
module.exports = test;
|
|
100
68
|
|
|
@@ -115,15 +83,23 @@ const createStream = async () => {
|
|
|
115
83
|
|
|
116
84
|
module.exports.createStream = createStream;
|
|
117
85
|
module.exports.createTest = async (testOptions = {}) => {
|
|
118
|
-
const {
|
|
86
|
+
const {
|
|
87
|
+
format = 'tap',
|
|
88
|
+
formatter,
|
|
89
|
+
isDebug,
|
|
90
|
+
} = testOptions;
|
|
91
|
+
|
|
119
92
|
const readyFormatter = await _createFormatter(formatter || format);
|
|
120
93
|
|
|
121
94
|
const stream = new PassThrough();
|
|
122
95
|
const emitter = _createEmitter({
|
|
123
|
-
...
|
|
96
|
+
...getDefaultOptions(),
|
|
124
97
|
...testOptions,
|
|
125
98
|
readyFormatter,
|
|
126
99
|
stream,
|
|
100
|
+
loop,
|
|
101
|
+
createFormatter,
|
|
102
|
+
isDebug,
|
|
127
103
|
});
|
|
128
104
|
|
|
129
105
|
const fn = (message, fn, options = {}) => {
|
|
@@ -137,6 +113,7 @@ module.exports.createTest = async (testOptions = {}) => {
|
|
|
137
113
|
assign(fn, {
|
|
138
114
|
stream,
|
|
139
115
|
...test,
|
|
116
|
+
extend: createExtend(fn),
|
|
140
117
|
test: fn,
|
|
141
118
|
run: () => {
|
|
142
119
|
emitter.emit('run');
|
|
@@ -146,7 +123,7 @@ module.exports.createTest = async (testOptions = {}) => {
|
|
|
146
123
|
return fn;
|
|
147
124
|
};
|
|
148
125
|
|
|
149
|
-
function test(message, fn, options = {}) {
|
|
126
|
+
function test(message, fn, options = {}, overrides = {}) {
|
|
150
127
|
const {
|
|
151
128
|
run,
|
|
152
129
|
quiet,
|
|
@@ -163,11 +140,13 @@ function test(message, fn, options = {}) {
|
|
|
163
140
|
workerFormatter,
|
|
164
141
|
timeout,
|
|
165
142
|
} = {
|
|
166
|
-
...
|
|
143
|
+
...getDefaultOptions(),
|
|
167
144
|
...initedOptions,
|
|
168
145
|
...options,
|
|
169
146
|
};
|
|
170
147
|
|
|
148
|
+
const {StackTracey} = overrides;
|
|
149
|
+
|
|
171
150
|
const validations = {
|
|
172
151
|
checkDuplicates,
|
|
173
152
|
checkScopes,
|
|
@@ -177,13 +156,18 @@ function test(message, fn, options = {}) {
|
|
|
177
156
|
|
|
178
157
|
setValidations(validations);
|
|
179
158
|
|
|
180
|
-
const at = getAt(
|
|
159
|
+
const at = getAt({
|
|
160
|
+
StackTracey,
|
|
161
|
+
});
|
|
162
|
+
|
|
181
163
|
const emitter = options.emitter || createEmitter({
|
|
164
|
+
loop,
|
|
182
165
|
format,
|
|
183
166
|
quiet,
|
|
184
167
|
getOperators,
|
|
185
168
|
isStop,
|
|
186
169
|
workerFormatter,
|
|
170
|
+
createFormatter,
|
|
187
171
|
});
|
|
188
172
|
|
|
189
173
|
mainEmitter = emitter;
|
|
@@ -217,7 +201,7 @@ test.only = (message, fn, options) => {
|
|
|
217
201
|
});
|
|
218
202
|
};
|
|
219
203
|
|
|
220
|
-
const getExtend = (extensions, type) => (message, fn, options) => {
|
|
204
|
+
const getExtend = (test, extensions, type) => (message, fn, options) => {
|
|
221
205
|
return test(message, fn, {
|
|
222
206
|
extensions,
|
|
223
207
|
...options,
|
|
@@ -228,28 +212,16 @@ const getExtend = (extensions, type) => (message, fn, options) => {
|
|
|
228
212
|
test.stub = stub;
|
|
229
213
|
test.test = test;
|
|
230
214
|
|
|
231
|
-
test.extend = (
|
|
232
|
-
const extendedTest = getExtend(extensions);
|
|
233
|
-
|
|
234
|
-
assign(extendedTest, {
|
|
235
|
-
test: extendedTest,
|
|
236
|
-
stub,
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
extendedTest.only = getExtend(extensions, {
|
|
240
|
-
only: true,
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
extendedTest.skip = getExtend(extensions, {
|
|
244
|
-
skip: true,
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
return extendedTest;
|
|
248
|
-
};
|
|
215
|
+
test.extend = createExtend(test);
|
|
249
216
|
|
|
250
217
|
const loop = maybeOnce(({emitter, tests}) => {
|
|
251
218
|
let previousCount = 0;
|
|
252
219
|
|
|
220
|
+
// 5ms ought to be enough for anybody
|
|
221
|
+
const {
|
|
222
|
+
SUPERTAPE_LOAD_LOOP_TIMEOUT = 5,
|
|
223
|
+
} = env;
|
|
224
|
+
|
|
253
225
|
(function loop() {
|
|
254
226
|
if (previousCount === tests.length) {
|
|
255
227
|
emitter.emit('run');
|
|
@@ -262,7 +234,23 @@ const loop = maybeOnce(({emitter, tests}) => {
|
|
|
262
234
|
})();
|
|
263
235
|
});
|
|
264
236
|
|
|
265
|
-
module.exports.run = () => {
|
|
237
|
+
module.exports.run = ({fake} = {}) => {
|
|
238
|
+
if (!mainEmitter || fake)
|
|
239
|
+
return fakeEmitter();
|
|
240
|
+
|
|
266
241
|
mainEmitter.emit('loop');
|
|
242
|
+
|
|
267
243
|
return mainEmitter;
|
|
268
244
|
};
|
|
245
|
+
|
|
246
|
+
function fakeEmitter() {
|
|
247
|
+
const emitter = new EventEmitter();
|
|
248
|
+
|
|
249
|
+
process.nextTick(() => {
|
|
250
|
+
emitter.emit('end', {
|
|
251
|
+
failed: 0,
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
return emitter;
|
|
256
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "supertape",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.6",
|
|
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",
|