supertape 10.2.1 → 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 CHANGED
@@ -1,3 +1,13 @@
1
+ 2024.03.01, v10.3.0
2
+
3
+ feature:
4
+ - 4aeb021 supertape: add per-test timeout option (#9)
5
+
6
+ 2024.02.29, v10.2.2
7
+
8
+ fix:
9
+ - 8b457ff supertape: formatter: comment
10
+
1
11
  2024.02.28, v10.2.1
2
12
 
3
13
  fix:
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
- ### Methods
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('calc: sum', (t) => {
206
- const result = sum(1, 2);
207
- const expected = 3;
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
- ## test(name, cb)
206
+ Here is Possible `options` similar to [Environment Variables](#environment-variables) but relates to one test:
215
207
 
216
- Create a new test with `name` string.
217
- `cb(t)` fires with the new test object `t` once all preceding tests have
218
- finished. Tests execute serially.
208
+ - `checkDuplicates`;
209
+ - `checkScopes`;-
210
+ - `checkAssertionsCount`;
211
+ - `timeout`;
219
212
 
220
- ## test.only(name, cb)
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
- ## test.skip(name, cb)
219
+ ### test.skip(message, fn, options?)
227
220
 
228
221
  Generate a new test that will be skipped over.
229
222
 
230
- ## test.extend(extensions)
223
+ ### test.extend(extensions)
231
224
 
232
225
  Extend base assertions with more:
233
226
 
@@ -1,8 +1,8 @@
1
+ import {EventEmitter} from 'node:events';
1
2
  import {
2
3
  parentPort,
3
4
  workerData,
4
5
  } from 'node:worker_threads';
5
- import {EventEmitter} from 'node:events';
6
6
 
7
7
  const {assign} = Object;
8
8
 
package/bin/formatter.mjs CHANGED
@@ -24,8 +24,8 @@ export const createFormatter = (parentPort) => {
24
24
  }]);
25
25
  });
26
26
 
27
- formatter.on('comment', (message) => {
28
- parentPort.postMessage(['test:end', {
27
+ formatter.on('comment', ({message}) => {
28
+ parentPort.postMessage(['comment', {
29
29
  message,
30
30
  }]);
31
31
  });
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 timeout = (time, value) => {
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({message, at, fn, extensions, formatter, count, total, failed, incCount, incPassed, incFailed, getValidationMessage, validations}) {
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(SUPERTAPE_TIMEOUT, ['timeout']);
164
+ const [timer, stopTimer] = doTimeout(timeout, ['timeout']);
149
165
  const [error] = await Promise.race([tryToCatch(fn, t), timer]);
150
166
 
151
167
  stopTimer();
@@ -34,6 +34,7 @@ type TestOptions = {
34
34
  checkAssertionsCount?: boolean;
35
35
  checkScopes?: boolean;
36
36
  checkDuplicates?: boolean;
37
+ timeout?: number;
37
38
  };
38
39
 
39
40
  declare function test(message: string, fn: (t: Test) => void, options?: TestOptions): void;
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 {SUPERTAPE_LOAD_LOOP_TIMEOUT = 5} = process.env;
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.2.1",
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",
@@ -1,37 +0,0 @@
1
- 'use strict';
2
-
3
- const {parentPort, workerData} = require('node:worker_threads');
4
-
5
- const {EventEmitter} = require('node:events');
6
- const process = require('node:process');
7
-
8
- const {assign} = Object;
9
-
10
- module.exports.createCommunication = () => {
11
- if (parentPort)
12
- return {
13
- parentPort,
14
- workerData,
15
- };
16
-
17
- const newWorker = new EventEmitter();
18
- const newParentPort = new EventEmitter();
19
-
20
- assign(newWorker, {
21
- postMessage: (a) => {
22
- newParentPort.emit('message', a);
23
- },
24
- });
25
-
26
- assign(newParentPort, {
27
- postMessage: (a) => {
28
- newWorker.emit('message', a);
29
- },
30
- });
31
-
32
- return {
33
- worker: newWorker,
34
- parentPort: newParentPort,
35
- workerData: process.argv,
36
- };
37
- };