supertape 12.0.4 → 12.0.5

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 CHANGED
@@ -1,3 +1,11 @@
1
+ 2026.01.08, v12.0.5
2
+
3
+ fix:
4
+ - f11518b supertape: get back fakeEmitter
5
+
6
+ feature:
7
+ - 6f60aff supertape: get rid of mock-require
8
+
1
9
  2026.01.08, v12.0.4
2
10
 
3
11
  feature:
@@ -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
@@ -3,4 +3,4 @@
3
3
  const process = require('node:process');
4
4
  const argv = process.execArgv.join();
5
5
 
6
- module.exports = argv.includes('inspect') || argv.includes('debug');
6
+ module.exports = () => argv.includes('inspect') || argv.includes('debug');
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 isDebug = require('./is-debug');
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, {formatter, operators, isStop}) => {
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, {formatter, operators, skipped, isStop}) {
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 {stdout} = process;
20
+ const createEmitter = once(_createEmitter);
21
+ const createFormatter = once(_createFormatter);
23
22
 
24
- // 5ms ought to be enough for anybody
25
- const {
26
- SUPERTAPE_LOAD_LOOP_TIMEOUT = 5,
27
- SUPERTAPE_TIMEOUT = 3000,
28
- } = process.env;
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 defaultOptions = {
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 {format = 'tap', formatter} = testOptions;
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
- ...defaultOptions,
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
- ...defaultOptions,
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 = (extensions) => {
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');
@@ -263,6 +235,26 @@ const loop = maybeOnce(({emitter, tests}) => {
263
235
  });
264
236
 
265
237
  module.exports.run = () => {
238
+ /* c8 ignore start */
239
+ if (!mainEmitter)
240
+ return fakeEmitter();
241
+
242
+ /* c8 ignore end */
266
243
  mainEmitter.emit('loop');
244
+
267
245
  return mainEmitter;
268
246
  };
247
+
248
+ /* c8 ignore start */
249
+ function fakeEmitter() {
250
+ const emitter = new EventEmitter();
251
+
252
+ process.nextTick(() => {
253
+ emitter.emit('end', {
254
+ failed: 0,
255
+ });
256
+ });
257
+
258
+ return emitter;
259
+ }/* c8 ignore end */
260
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supertape",
3
- "version": "12.0.4",
3
+ "version": "12.0.5",
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",