tape-six 1.5.1 → 1.7.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/README.md CHANGED
@@ -6,9 +6,9 @@
6
6
  `tape-six` is a [TAP](https://en.wikipedia.org/wiki/Test_Anything_Protocol)-based library for unit tests.
7
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
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).
9
+ It runs ES modules (`import`-based code) natively and supports CommonJS modules transparently using the built-in [ESM](https://nodejs.org/api/esm.html).
10
10
 
11
- It can run TypeScript code with modern versions of Node, Bun and Deno without transpilation. Obviously TS bindings are included.
11
+ It can run TypeScript code with modern versions of Node, Bun and Deno **without transpilation**. Obviously TS bindings are included.
12
12
 
13
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.
14
14
 
@@ -33,7 +33,7 @@ with existing unit test libraries:
33
33
  - Tests should work with ES modules natively.
34
34
  - What if I want to debug some CommonJS code with Node? No problem, it just works.
35
35
  - Tests should work with TypeScript natively.
36
- - It just workss: modern runtimes (Node, Deno, Bun) support running TypeScript natively without transpilation by ignoring type information and running the code directly.
36
+ - It just works: modern runtimes (Node, Deno, Bun) support running TypeScript natively without transpilation by ignoring type information and running the code directly.
37
37
  - The [DX](https://en.wikipedia.org/wiki/User_experience#Developer_experience) in browsers are usually abysmal.
38
38
  - Both console-based debugging and a UI to navigate results are properly supported.
39
39
  - Integration with browser automation tools is supported for automated testing.
@@ -316,6 +316,10 @@ test('Sample test', async t => {
316
316
  });
317
317
  ```
318
318
 
319
+ ### Before/after hooks
320
+
321
+ `tape-six` supports scope-based before/after hooks: `beforeAll`, `afterAll`, `beforeEach`, `afterEach`, which can be used to set-up and tear-down a proper environment for tests. Read all about it in [before and after hooks](https://github.com/uhop/tape-six/wiki/Before-and-after-hooks).
322
+
319
323
  ### Running tests
320
324
 
321
325
  It is super easy to run tests:
@@ -328,7 +332,7 @@ It is super easy to run tests:
328
332
  3. Or you can run them in a browser!
329
333
  4. Profit!
330
334
 
331
- If you have a lot of tests, you can organize them using multiple files and directories.
335
+ If you have a lot of tests, you can organize them using multiple files and directories (see configuration below).
332
336
  `tape-six` provides multiple test runners that can run them in different environments.
333
337
 
334
338
  Tests can run in parallel using multiple threads to speed up the whole process.
@@ -341,6 +345,12 @@ tape6 --par 1 # run one test at a time
341
345
 
342
346
  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.
343
347
 
348
+ If you want to run tests sequentially without expenses of threads and processes, you can use the `tape6-seq` command, which uses the same options and configuration as `tape6`:
349
+
350
+ ```bash
351
+ tape6-seq
352
+ ```
353
+
344
354
  ### Configuring test runners
345
355
 
346
356
  TLDR version — add to your `package.json`:
@@ -380,28 +390,9 @@ Test output can be controlled by flags. See [Supported flags](https://github.com
380
390
 
381
391
  The most recent releases:
382
392
 
393
+ - 1.7.0 _New features: after/before hooks for tests, aliases for `suite()`, `describe()`, `it()`, `tape6-seq` — an in-process sequential test runner. Improvements: stricter monochrome detection, refactoring, bugfixes, updated dev dependencies and the documentation._
394
+ - 1.6.0 _New features: support for `AssertionError` and 3rd-party assertion libraries based on it like `node:assert` and `chai`, support for `console.assert()`, support for `signal` to cancel asynchronous operations, tests wait for embedded tests, improved reporting of errors, updated dev dependencies._
383
395
  - 1.5.1 _Better support for stopping parallel tests, better support for "failed to load" errors._
384
396
  - 1.5.0 _Internal refactoring (moved state to reporters), added type identification of values in the DOM and TTY reporters, multiple minor fixes._
385
- - 1.4.5 _Internal: added flags support for custom test runners._
386
- - 1.4.4 _Refreshed the lock file._
387
- - 1.4.3 _Updated dev dependencies + a minor bugfix._
388
- - 1.4.2 _Improved documentation._
389
- - 1.4.1 _Added browser automation support._
390
- - 1.4.0 _Added a high-level helper `OK()` for evaluating simple expressions._
391
- - 1.3.5 _Minor improvements, better docs._
392
- - 1.3.4 _Minor bugfixes and improvements._
393
- - 1.3.3 _Added a way to hide console/streams output, better support for file tests, better TTY formatting._
394
- - 1.3.2 _Internal refactoring (capture console calls), updated dependencies._
395
- - 1.3.1 _Bugfix for web browser using JSONL reporter._
396
- - 1.3.0 _Bugfixes, updated dependencies, new feature: proxied console calls._
397
- - 1.2.0 _Updated dependencies + added an optional prefix for JSON lines._
398
- - 1.1.2 _Updated dependencies._
399
- - 1.1.1 _Technical re-release with the missing `index.d.ts` file._
400
- - 1.1.0 _Added TypeScript support._
401
- - 1.0.4 _Bugfix for platform-specific tests, old platforms, minor updates to accommodate Deno 2, updated dev deps._
402
- - 1.0.3 _Minor update to accommodate changes in Bun and updated dev deps._
403
- - 1.0.2 _Bugfix for Deno using the JSONL reporter._
404
- - 1.0.1 _Technical release: added more links._
405
- - 1.0.0 _The first official release._
406
397
 
407
398
  For more info consult full [release notes](https://github.com/uhop/tape-six/wiki/Release-notes).
package/bin/tape6-bun.js CHANGED
@@ -2,16 +2,12 @@
2
2
 
3
3
  import {fileURLToPath} from 'node:url';
4
4
 
5
- import {
6
- resolveTests,
7
- resolvePatterns,
8
- getReporter as getReporterType
9
- } from '../src/utils/config.js';
5
+ import {resolveTests, resolvePatterns, getReporterType} from '../src/utils/config.js';
10
6
 
11
7
  import {getReporter, setReporter} from '../src/test.js';
12
8
  import {selectTimer} from '../src/utils/timer.js';
13
9
 
14
- import TestWorker from '../src/bun/TestWorker.js';
10
+ import TestWorker from '../src/runners/bun/TestWorker.js';
15
11
 
16
12
  const options = {},
17
13
  rootFolder = Bun.cwd;
@@ -101,8 +97,13 @@ const init = async () => {
101
97
  const reporterType = getReporterType(),
102
98
  reporterFile = reporters[reporterType] || reporters.tty,
103
99
  CustomReporter = (await import('../src/reporters/' + reporterFile)).default,
104
- customOptions =
105
- reporterType === 'tap' ? {useJson: true, hasColors: !options.monochrome} : options,
100
+ hasColors = !(
101
+ options.monochrome ||
102
+ Bun.env.NO_COLOR ||
103
+ Bun.env.NODE_DISABLE_COLORS ||
104
+ Bun.env.FORCE_COLOR === '0'
105
+ ),
106
+ customOptions = reporterType === 'tap' ? {useJson: true, hasColors} : {...options, hasColors},
106
107
  customReporter = new CustomReporter(customOptions);
107
108
  setReporter(customReporter);
108
109
  }
package/bin/tape6-deno.js CHANGED
@@ -2,16 +2,12 @@
2
2
 
3
3
  import {fileURLToPath} from 'node:url';
4
4
 
5
- import {
6
- resolveTests,
7
- resolvePatterns,
8
- getReporter as getReporterType
9
- } from '../src/utils/config.js';
5
+ import {resolveTests, resolvePatterns, getReporterType} from '../src/utils/config.js';
10
6
 
11
7
  import {getReporter, setReporter} from '../src/test.js';
12
8
  import {selectTimer} from '../src/utils/timer.js';
13
9
 
14
- import TestWorker from '../src/deno/TestWorker.js';
10
+ import TestWorker from '../src/runners/deno/TestWorker.js';
15
11
 
16
12
  const options = {},
17
13
  rootFolder = Deno.cwd();
@@ -101,8 +97,13 @@ const init = async () => {
101
97
  const reporterType = getReporterType(),
102
98
  reporterFile = reporters[reporterType] || reporters.tty,
103
99
  CustomReporter = (await import('../src/reporters/' + reporterFile)).default,
104
- customOptions =
105
- reporterType === 'tap' ? {useJson: true, hasColors: !options.monochrome} : options,
100
+ hasColors = !(
101
+ options.monochrome ||
102
+ Deno.env.get('NO_COLOR') ||
103
+ Deno.env.get('NODE_DISABLE_COLORS') ||
104
+ Deno.env.get('FORCE_COLOR') === '0'
105
+ ),
106
+ customOptions = reporterType === 'tap' ? {useJson: true, hasColors} : {...options, hasColors},
106
107
  customReporter = new CustomReporter(customOptions);
107
108
  setReporter(customReporter);
108
109
  }
package/bin/tape6-node.js CHANGED
@@ -3,16 +3,12 @@
3
3
  import process from 'node:process';
4
4
  import {fileURLToPath} from 'node:url';
5
5
 
6
- import {
7
- resolveTests,
8
- resolvePatterns,
9
- getReporter as getReporterType
10
- } from '../src/utils/config.js';
6
+ import {resolveTests, resolvePatterns, getReporterType} from '../src/utils/config.js';
11
7
 
12
8
  import {getReporter, setReporter} from '../src/test.js';
13
9
  import {selectTimer} from '../src/utils/timer.js';
14
10
 
15
- import TestWorker from '../src/node/TestWorker.js';
11
+ import TestWorker from '../src/runners/node/TestWorker.js';
16
12
 
17
13
  const options = {},
18
14
  rootFolder = process.cwd();
@@ -102,8 +98,13 @@ const init = async () => {
102
98
  const reporterType = getReporterType(),
103
99
  reporterFile = reporters[reporterType] || reporters.tty,
104
100
  CustomReporter = (await import('../src/reporters/' + reporterFile)).default,
105
- customOptions =
106
- reporterType === 'tap' ? {useJson: true, hasColors: !options.monochrome} : options,
101
+ hasColors = !(
102
+ options.monochrome ||
103
+ process.env.NO_COLOR ||
104
+ process.env.NODE_DISABLE_COLORS ||
105
+ process.env.FORCE_COLOR === '0'
106
+ ),
107
+ customOptions = reporterType === 'tap' ? {useJson: true, hasColors} : {...options, hasColors},
107
108
  customReporter = new CustomReporter(customOptions);
108
109
  setReporter(customReporter);
109
110
  }
@@ -7,6 +7,7 @@ const runtimeFiles = {
7
7
  node: 'tape6-node.js',
8
8
  deno: 'tape6-deno.js',
9
9
  bun: 'tape6-bun.js',
10
+ seq: 'tape6-seq.js',
10
11
  server: 'tape6-server.js',
11
12
  runner: 'tape6-runner.js',
12
13
  main: 'tape6.js'
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env node
2
+
3
+ import process from 'node:process';
4
+ import {fileURLToPath} from 'node:url';
5
+
6
+ import {resolveTests, resolvePatterns, getReporterType} from '../src/utils/config.js';
7
+
8
+ import {getReporter, setReporter, setConfiguredFlag, testRunner} from '../src/test.js';
9
+ import {selectTimer} from '../src/utils/timer.js';
10
+
11
+ import TestWorker from '../src/runners/seq/TestWorker.js';
12
+
13
+ setConfiguredFlag(true);
14
+
15
+ const options = {},
16
+ rootFolder = process.cwd();
17
+
18
+ let flags = '',
19
+ files = [];
20
+
21
+ const showSelf = () => {
22
+ const self = new URL(import.meta.url);
23
+ if (self.protocol === 'file:') {
24
+ console.log(fileURLToPath(self));
25
+ } else {
26
+ console.log(self);
27
+ }
28
+ process.exit(0);
29
+ };
30
+
31
+ const config = () => {
32
+ if (process.argv.includes('--self')) showSelf();
33
+
34
+ const optionNames = {
35
+ f: 'failureOnly',
36
+ t: 'showTime',
37
+ b: 'showBanner',
38
+ d: 'showData',
39
+ o: 'failOnce',
40
+ n: 'showAssertNumber',
41
+ m: 'monochrome',
42
+ c: 'dontCaptureConsole',
43
+ h: 'hideStreams'
44
+ };
45
+
46
+ for (let i = 2; i < process.argv.length; ++i) {
47
+ const arg = process.argv[i];
48
+ if (arg == '-f' || arg == '--flags') {
49
+ if (++i < process.argv.length) {
50
+ flags += process.argv[i];
51
+ }
52
+ continue;
53
+ }
54
+ if (arg == '-p' || arg == '--par') {
55
+ // skip
56
+ ++i;
57
+ continue;
58
+ }
59
+ files.push(arg);
60
+ }
61
+
62
+ flags = (process.env.TAPE6_FLAGS || '') + flags;
63
+ for (let i = 0; i < flags.length; ++i) {
64
+ const option = flags[i].toLowerCase(),
65
+ name = optionNames[option];
66
+ if (typeof name == 'string') options[name] = option !== flags[i];
67
+ }
68
+ options.flags = flags;
69
+ };
70
+
71
+ const reporters = {
72
+ jsonl: 'JSONLReporter.js',
73
+ tap: 'TapReporter.js',
74
+ tty: 'TTYReporter.js'
75
+ };
76
+
77
+ const init = async () => {
78
+ const currentReporter = getReporter();
79
+ if (!currentReporter) {
80
+ const reporterType = getReporterType(),
81
+ reporterFile = reporters[reporterType] || reporters.tty,
82
+ CustomReporter = (await import('../src/reporters/' + reporterFile)).default,
83
+ hasColors = !(
84
+ options.monochrome ||
85
+ process.env.NO_COLOR ||
86
+ process.env.NODE_DISABLE_COLORS ||
87
+ process.env.FORCE_COLOR === '0'
88
+ ),
89
+ customOptions = reporterType === 'tap' ? {useJson: true, hasColors} : {...options, hasColors},
90
+ customReporter = new CustomReporter(customOptions);
91
+ setReporter(customReporter);
92
+ }
93
+
94
+ if (files.length) {
95
+ files = await resolvePatterns(rootFolder, files);
96
+ } else {
97
+ files = await resolveTests(rootFolder, 'node');
98
+ }
99
+ };
100
+
101
+ const main = async () => {
102
+ config();
103
+ await init();
104
+ await selectTimer();
105
+
106
+ const console = globalThis.console;
107
+
108
+ process.on('uncaughtException', (error, origin) =>
109
+ console.error('UNHANDLED ERROR:', origin, error)
110
+ );
111
+
112
+ const reporter = getReporter(),
113
+ worker = new TestWorker(reporter, 1, {...options, testRunner});
114
+
115
+ reporter.report({type: 'test', test: 0});
116
+
117
+ await new Promise(resolve => {
118
+ worker.done = () => resolve();
119
+ worker.execute(files);
120
+ });
121
+
122
+ const hasFailed = reporter.state && reporter.state.failed > 0;
123
+
124
+ reporter.report({
125
+ type: 'end',
126
+ test: 0,
127
+ fail: hasFailed
128
+ });
129
+
130
+ process.exit(hasFailed ? 1 : 0);
131
+ };
132
+
133
+ main().catch(error => console.error('ERROR:', error));