tape-six 1.3.4 → 1.3.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/README.md +96 -32
- package/bin/tape6-deno.js +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,8 +4,13 @@
|
|
|
4
4
|
[npm-url]: https://npmjs.org/package/tape-six
|
|
5
5
|
|
|
6
6
|
`tape-six` is a [TAP](https://en.wikipedia.org/wiki/Test_Anything_Protocol)-based library for unit tests.
|
|
7
|
-
It is written in the modern JavaScript for the modern JavaScript and works in [Node](https://nodejs.org/),
|
|
8
|
-
|
|
7
|
+
It is written in the modern JavaScript for the modern JavaScript and works in [Node](https://nodejs.org/), [Deno](https://deno.land/), [Bun](https://bun.sh/) and browsers.
|
|
8
|
+
|
|
9
|
+
It runs ES modules (`import`-based code) natively and supports CommonJS modules transparently using built-in [ESM](https://nodejs.org/api/esm.html).
|
|
10
|
+
|
|
11
|
+
It can run TypeScript code with modern versions of Node, Bun and Deno without transpilation. Obviously TS bindings are included.
|
|
12
|
+
|
|
13
|
+
Individual test files can be executed directly with `node`, `deno`, `bun` without a need for a special test runner utility. It facilitates debugging and improves testing.
|
|
9
14
|
|
|
10
15
|
Why `tape-six`? It was supposed to be named `tape6` but `npm` does not allow names "similar"
|
|
11
16
|
to existing packages. Instead of eliminating name-squatting they force to use unintuitive and
|
|
@@ -16,7 +21,7 @@ unmemorable names. That's why all internal names, environment variables, and pub
|
|
|
16
21
|
Why another library? Working on projects written in modern JS (with modules) I found several problems
|
|
17
22
|
with existing unit test libraries:
|
|
18
23
|
|
|
19
|
-
- In my opinion unit test files should be directly executable with
|
|
24
|
+
- In my opinion unit test files should be directly executable with Node, Bun, Deno, browsers
|
|
20
25
|
(with a trivial HTML file to load a test file) without a need for a special test runner utility,
|
|
21
26
|
which wraps and changes my beautiful code.
|
|
22
27
|
- Debugging my tests should be trivial. It should not be different from debugging any regular file.
|
|
@@ -24,11 +29,11 @@ with existing unit test libraries:
|
|
|
24
29
|
- I want to debug my code, not dependencies I've never heard about.
|
|
25
30
|
- I want to see where a problem happens, not some guts of a test harness.
|
|
26
31
|
- Tests should work with ES modules natively.
|
|
27
|
-
- What if I want to debug some CommonJS code with Node?
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
- What if I want to debug some CommonJS code with Node? No problem, it just works.
|
|
33
|
+
- Tests should work with TypeScript natively.
|
|
34
|
+
- It just workss: modern runtimes (Node, Deno, Bun) support running TypeScript natively without transpilation by ignoring type information and running the code directly.
|
|
30
35
|
- The [DX](https://en.wikipedia.org/wiki/User_experience#Developer_experience) in browsers are usually abysmal.
|
|
31
|
-
- Both console-based debugging and a UI to navigate results
|
|
36
|
+
- Both console-based debugging and a UI to navigate results are properly supported.
|
|
32
37
|
|
|
33
38
|
## Docs
|
|
34
39
|
|
|
@@ -43,6 +48,11 @@ The whole API is based on two objects: `test` and `Tester`.
|
|
|
43
48
|
|
|
44
49
|
```js
|
|
45
50
|
import test from 'tape-six';
|
|
51
|
+
// import {test} from 'tape-six';
|
|
52
|
+
|
|
53
|
+
// CommonJS:
|
|
54
|
+
// const {test} = require('tape-six');
|
|
55
|
+
// const {default: test} = require('tape-six');
|
|
46
56
|
```
|
|
47
57
|
|
|
48
58
|
This function registers a test suite. Available options:
|
|
@@ -50,13 +60,14 @@ This function registers a test suite. Available options:
|
|
|
50
60
|
- `async test(name, options, testFn)` — registers a test suite to be executed asynchronously.
|
|
51
61
|
The returned promise is resolved when the test suite is finished.
|
|
52
62
|
- In most cases no need to wait for the returned promise.
|
|
53
|
-
- The test function has the following signature: `testFn(tester)`
|
|
54
|
-
-
|
|
63
|
+
- The test function has the following signature: `async testFn(tester)`
|
|
64
|
+
- The function can be synchronous or asynchronous.
|
|
65
|
+
- `async test.skip(name, options, testFn)` — registers a test suite to be skipped.
|
|
55
66
|
- It is used to mark a test suite to be skipped. It will not be executed.
|
|
56
|
-
- `test.todo(name, options, testFn)` — registers a test suite that is marked as work in progress.
|
|
67
|
+
- `async test.todo(name, options, testFn)` — registers a test suite that is marked as work in progress.
|
|
57
68
|
- Tests in this suite will be executed, errors will be reported but not counted as failures.
|
|
58
69
|
- It is used to mark tests for incomplete features under development.
|
|
59
|
-
- `test.asPromise(name, options, testPromiseFn)` — registers a test suite to be executed asynchronously
|
|
70
|
+
- `async test.asPromise(name, options, testPromiseFn)` — registers a test suite to be executed asynchronously
|
|
60
71
|
using the callback-style API to notify that the test suite is finished.
|
|
61
72
|
- The test function has a different signature: `testPromiseFn(tester, resolve, reject)`.
|
|
62
73
|
|
|
@@ -68,19 +79,22 @@ The arguments mentioned above are:
|
|
|
68
79
|
- `todo` — if `true`, the test suite will be marked as work in progress.
|
|
69
80
|
- `name` — the optional name of the test suite. If not provided, it will be set to the name of the test function or `'(anonymous)'`.
|
|
70
81
|
- Can be overridden by the `name` argument.
|
|
71
|
-
- `testFn` — the optional test function to be executed.
|
|
72
|
-
- Can be overridden by the `testFn` argument.
|
|
73
82
|
- `timeout` — the optional timeout in milliseconds. It is used for asynchronous tests.
|
|
74
83
|
- If the timeout is exceeded, the test suite will be marked as failed.
|
|
75
84
|
- **Important:** JavaScript does not provide a generic way to cancel asynchronous operations.
|
|
76
85
|
When the timeout is exceeded, `tape6` will stop waiting for the test to finish,
|
|
77
86
|
but it will continue running in the background.
|
|
78
87
|
- The default: no timeout.
|
|
79
|
-
- `testFn` — the test function to be executed
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
- `testFn` — the optional test function to be executed (see below).
|
|
89
|
+
- Can be overridden by the `testFn` argument.
|
|
90
|
+
- `testPromiseFn` — the optional callback-based test function to be executed.
|
|
91
|
+
- Can be overridden by the `testPromiseFn` argument.
|
|
92
|
+
- `testFn` — a test function to be executed. It will be called with the `tester` object.
|
|
93
|
+
The result will be ignored.
|
|
94
|
+
- This function can be synchronous or asynchronous.
|
|
95
|
+
- `testPromiseFn` — a callback-based test function to be executed (see below). It will be called with the `tester` object and two callbacks: `resolve` and `reject` modeled on the [Promise API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise).
|
|
96
|
+
- Value supplied to `resolve()` will be ignored.
|
|
97
|
+
- Value supplied to `reject()` will be used as the error message.
|
|
84
98
|
|
|
85
99
|
Given all that `test` and its helpers can be called like this:
|
|
86
100
|
|
|
@@ -111,6 +125,32 @@ test({
|
|
|
111
125
|
});
|
|
112
126
|
```
|
|
113
127
|
|
|
128
|
+
Examples of callback-based tests:
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
test.asPromise(name, options, testPromiseFn);
|
|
132
|
+
test.asPromise(name, testPromiseFn);
|
|
133
|
+
test.asPromise(testPromiseFn);
|
|
134
|
+
test.asPromise(name, options);
|
|
135
|
+
test.asPromise(options, testPromiseFn);
|
|
136
|
+
test.asPromise(options);
|
|
137
|
+
|
|
138
|
+
// examples:
|
|
139
|
+
test.asPromise('foo', (t, resolve, reject) => {
|
|
140
|
+
t.pass();
|
|
141
|
+
const result = someAsyncOperationAsPromise();
|
|
142
|
+
result.then(resolve).catch(reject);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test.asPromise('bar', async (t, resolve, reject) => {
|
|
146
|
+
const nodeStream = fs.createWriteStream('bar.txt');
|
|
147
|
+
nodeStream.on('error', reject);
|
|
148
|
+
nodeStream.on('finish', resolve);
|
|
149
|
+
nodeStream.write('hello');
|
|
150
|
+
nodeStream.end();
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
114
154
|
### `Tester`
|
|
115
155
|
|
|
116
156
|
`Tester` helps to do asserts and provides an interface between a test suite and the test harness.
|
|
@@ -216,15 +256,49 @@ It is super easy to run tests:
|
|
|
216
256
|
2. Write a test. For example, you named it `test.js`.
|
|
217
257
|
3. Run the test: `node test.js`
|
|
218
258
|
1. Or: `bun run test.js`
|
|
219
|
-
2. Or: `deno run -A test.js`
|
|
259
|
+
2. Or: `deno run -A test.js` (you can use appropriate permissions).
|
|
220
260
|
3. Or you can run them in a browser!
|
|
221
261
|
4. Profit!
|
|
222
262
|
|
|
223
263
|
If you have a lot of tests, you can organize them using multiple files and directories.
|
|
224
264
|
`tape-six` provides multiple test runners that can run them in different environments.
|
|
225
265
|
|
|
266
|
+
Tests can run in parallel using multiple threads to speed up the whole process.
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
tape6 # run tests in parallel using all available threads
|
|
270
|
+
tape6 --par 4 # run tests in parallel using 4 threads
|
|
271
|
+
tape6 --par 1 # run one test at a time
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
If you want to run tests in separate processes, check out [tape-six-proc](https://www.npmjs.com/package/tape-six-proc). Why do you want to do that? When tests have to modify globals or use single-threaded binary extensions.
|
|
275
|
+
|
|
226
276
|
### Configuring test runners
|
|
227
277
|
|
|
278
|
+
TLDR version — add to your `package.json`:
|
|
279
|
+
|
|
280
|
+
```jsonc
|
|
281
|
+
{
|
|
282
|
+
// ...
|
|
283
|
+
"scripts": {
|
|
284
|
+
"test": "tape6 --flags FO",
|
|
285
|
+
"start": "tape6-server --trace"
|
|
286
|
+
}
|
|
287
|
+
// ...
|
|
288
|
+
"tape6": {
|
|
289
|
+
"tests": ["/tests/test-*.*js"],
|
|
290
|
+
"importmap": {
|
|
291
|
+
"imports": {
|
|
292
|
+
"tape-six": "/node_modules/tape-six/index.js",
|
|
293
|
+
"tape-six/": "/node_modules/tape-six/src/",
|
|
294
|
+
"my-package": "/index.js",
|
|
295
|
+
"my-package/": "/src/"
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
228
302
|
See [set-up tests](https://github.com/uhop/tape-six/wiki/Set-up-tests) for details.
|
|
229
303
|
|
|
230
304
|
### Command-line utilities
|
|
@@ -232,10 +306,13 @@ See [set-up tests](https://github.com/uhop/tape-six/wiki/Set-up-tests) for detai
|
|
|
232
306
|
- [tape6](https://github.com/uhop/tape-six/wiki/Utility-%E2%80%90-tape6) — the main utility of the package to run tests in different environments.
|
|
233
307
|
- [tape6-server](https://github.com/uhop/tape-six/wiki/Utility-%E2%80%90-tape6-server) — a custom web server with a web application that helps running tests in browsers.
|
|
234
308
|
|
|
309
|
+
Test output can be controlled by flags. See [Supported flags](https://github.com/uhop/tape-six/wiki/Supported-flags) for details.
|
|
310
|
+
|
|
235
311
|
## Release notes
|
|
236
312
|
|
|
237
313
|
The most recent releases:
|
|
238
314
|
|
|
315
|
+
- 1.3.5 _Minor improvements, better docs._
|
|
239
316
|
- 1.3.4 _Minor bugfixes and improvements._
|
|
240
317
|
- 1.3.3 _Added a way to hide console/streams output, better support for file tests, better TTY formatting._
|
|
241
318
|
- 1.3.2 _Internal refactoring (capture console calls), updated dependencies._
|
|
@@ -250,18 +327,5 @@ The most recent releases:
|
|
|
250
327
|
- 1.0.2 _Bugfix for Deno using the JSONL reporter._
|
|
251
328
|
- 1.0.1 _Technical release: added more links._
|
|
252
329
|
- 1.0.0 _The first official release._
|
|
253
|
-
- 0.12.3 _Technical release: exposed internal classes for external utilities._
|
|
254
|
-
- 0.12.2 _Fixed a minor serialization issue._
|
|
255
|
-
- 0.12.1 _Minor Deno-related refactoring, fixed the way tests are triggered._
|
|
256
|
-
- 0.12.0 _Removed data to avoid serializing non-serializable objects._
|
|
257
|
-
- 0.11.0 _Minor improvements to the server: temporary redirects, a hyperlink to the web app._
|
|
258
|
-
- 0.10.0 _Refactored test runners, refactored stopping tests on failure, added JSONL reporter, fixed bugs._
|
|
259
|
-
- 0.9.6 _Updated deps._
|
|
260
|
-
- 0.9.5 _Updated the lock file._
|
|
261
|
-
- 0.9.4 _Updated deps. Added test runners for Bun and Deno._
|
|
262
|
-
- 0.9.3 _Made TTY reporter work with non-TTY streams._
|
|
263
|
-
- 0.9.2 _Fixed Windows runner._
|
|
264
|
-
- 0.9.1 _More updates related to renaming `tape6` ⇒ `tape-six`._
|
|
265
|
-
- 0.9.0 _Initial release._
|
|
266
330
|
|
|
267
331
|
For more info consult full [release notes](https://github.com/uhop/tape-six/wiki/Release-notes).
|
package/bin/tape6-deno.js
CHANGED
package/index.d.ts
CHANGED
package/index.js
CHANGED