tape-six-proc 1.0.2 → 1.1.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.
@@ -0,0 +1,76 @@
1
+ # For most projects, this workflow file will not need changing; you simply need
2
+ # to commit it to your repository.
3
+ #
4
+ # You may wish to alter this file to override the set of languages analyzed,
5
+ # or to provide custom queries or build logic.
6
+ #
7
+ # ******** NOTE ********
8
+ # We have attempted to detect the languages in your repository. Please check
9
+ # the `language` matrix defined below to confirm you have the correct set of
10
+ # supported CodeQL languages.
11
+ #
12
+ name: 'CodeQL'
13
+
14
+ on:
15
+ push:
16
+ branches: ['master']
17
+ pull_request:
18
+ # The branches below must be a subset of the branches above
19
+ branches: ['master']
20
+ schedule:
21
+ - cron: '29 23 * * 0'
22
+
23
+ jobs:
24
+ analyze:
25
+ name: Analyze
26
+ runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
27
+ timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
28
+ permissions:
29
+ actions: read
30
+ contents: read
31
+ security-events: write
32
+
33
+ strategy:
34
+ fail-fast: false
35
+ matrix:
36
+ language: ['javascript']
37
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
38
+ # Use only 'java' to analyze code written in Java, Kotlin or both
39
+ # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
40
+ # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
41
+
42
+ steps:
43
+ - name: Checkout repository
44
+ uses: actions/checkout@v4
45
+
46
+ # Initializes the CodeQL tools for scanning.
47
+ - name: Initialize CodeQL
48
+ uses: github/codeql-action/init@v3
49
+ with:
50
+ languages: ${{ matrix.language }}
51
+ # If you wish to specify custom queries, you can do so here or in a config file.
52
+ # By default, queries listed here will override any specified in a config file.
53
+ # Prefix the list here with "+" to use these queries and those in the config file.
54
+
55
+ # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
56
+ # queries: security-extended,security-and-quality
57
+
58
+ # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
59
+ # If this step fails, then you should remove it and run the build manually (see below)
60
+ - name: Autobuild
61
+ uses: github/codeql-action/autobuild@v3
62
+
63
+ # ℹ️ Command-line programs to run using the OS shell.
64
+ # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
65
+
66
+ # If the Autobuild fails above, remove it and uncomment the following three lines.
67
+ # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
68
+
69
+ # - run: |
70
+ # echo "Run, Build Application using script"
71
+ # ./location_of_script_within_repo/buildscript.sh
72
+
73
+ - name: Perform CodeQL Analysis
74
+ uses: github/codeql-action/analyze@v3
75
+ with:
76
+ category: '/language:${{matrix.language}}'
@@ -0,0 +1,32 @@
1
+ # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
+
4
+ name: Node.js CI
5
+
6
+ on:
7
+ push:
8
+ branches: ['*']
9
+ pull_request:
10
+ branches: [master]
11
+
12
+ jobs:
13
+ tests:
14
+ name: Node.js ${{matrix.node-version}} on ${{matrix.os}}
15
+ runs-on: ${{matrix.os}}
16
+
17
+ strategy:
18
+ matrix:
19
+ os: [ubuntu-latest, windows-latest, macOS-latest]
20
+ node-version: [20, 22, 24, 25]
21
+
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+ with:
25
+ submodules: true
26
+ - uses: actions/setup-node@v4
27
+ with:
28
+ node-version: ${{matrix.node-version}}
29
+ - run: |
30
+ npm ci
31
+ npm run build --if-present
32
+ npm test
@@ -0,0 +1,28 @@
1
+ name: Windows
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ node-version:
7
+ description: 'Node.js version to run tests'
8
+ required: true
9
+ default: 25
10
+ type: number
11
+
12
+ jobs:
13
+ tests:
14
+ name: Node.js ${{inputs.node-version}} (special test)
15
+ runs-on: windows-latest
16
+
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ with:
20
+ submodules: true
21
+ - uses: actions/setup-node@v4
22
+ with:
23
+ node-version: ${{inputs.node-version}}
24
+ - run: |
25
+ npm ci
26
+ npm run build --if-present
27
+ npm test
28
+ node tests/test-sample.js
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # tape-six-proc [![NPM version][npm-img]][npm-url]
2
2
 
3
- [npm-img]: https://img.shields.io/npm/v/tape-six-proc.svg
4
- [npm-url]: https://npmjs.org/package/tape-six-proc
3
+ [npm-img]: https://img.shields.io/npm/v/tape-six-proc.svg
4
+ [npm-url]: https://npmjs.org/package/tape-six-proc
5
5
 
6
6
  `tape-six-proc` is a helper for [tape-six](https://www.npmjs.com/package/tape-six)
7
7
  to run tests in separate processes.
@@ -16,16 +16,17 @@ has the same usage as `tape6`.
16
16
 
17
17
  ### Command-line utilities
18
18
 
19
- * [tape6-proc](https://github.com/uhop/tape-six-proc/wiki/Utility-%E2%80%90-tape6-proc) — the main utility of this package to run tests in different environments.
19
+ - [tape6-proc](https://github.com/uhop/tape-six-proc/wiki/Utility-%E2%80%90-tape6-proc) — the main utility of this package to run tests in different environments.
20
20
 
21
21
  ## Release notes
22
22
 
23
23
  The most recent releases:
24
24
 
25
- * 1.0.2 *Fixed concurrency detection. Updated dependencies.*
26
- * 1.0.1 *Updated dependencies.*
27
- * 1.0.0 *The first official release.*
28
- * 0.12.1 *Updated dependencies, which included fixes for Deno.*
29
- * 0.12.0 *Initial release.*
25
+ - 1.1.0 _Added support for stdout/stderr and `tape-six` 1.3.4._
26
+ - 1.0.2 _Fixed concurrency detection. Updated dependencies._
27
+ - 1.0.1 _Updated dependencies._
28
+ - 1.0.0 _The first official release._
29
+ - 0.12.1 _Updated dependencies, which included fixes for Deno._
30
+ - 0.12.0 _Initial release._
30
31
 
31
32
  For more info consult full [release notes](https://github.com/uhop/tape-six-proc/wiki/Release-notes).
@@ -43,18 +43,18 @@ const config = () => {
43
43
  d: 'showData',
44
44
  o: 'failOnce',
45
45
  n: 'showAssertNumber',
46
- c: 'hasColors'
46
+ m: 'monochrome',
47
+ c: 'dontCaptureConsole',
48
+ h: 'hideStreams'
47
49
  };
48
50
 
49
- let flagIsSet = false,
50
- parIsSet = false;
51
+ let parIsSet = false;
51
52
 
52
53
  for (let i = 2; i < process.argv.length; ++i) {
53
54
  const arg = process.argv[i];
54
55
  if (arg == '-f' || arg == '--flags') {
55
56
  if (++i < process.argv.length) {
56
57
  flags = process.argv[i];
57
- flagIsSet = true;
58
58
  }
59
59
  continue;
60
60
  }
@@ -78,9 +78,7 @@ const config = () => {
78
78
  files.push(arg);
79
79
  }
80
80
 
81
- if (!flagIsSet) {
82
- flags = process.env.TAPE6_FLAGS || flags;
83
- }
81
+ flags = (process.env.TAPE6_FLAGS || '') + flags;
84
82
  for (let i = 0; i < flags.length; ++i) {
85
83
  const option = flags[i].toLowerCase(),
86
84
  name = optionNames[option];
@@ -116,11 +114,11 @@ const init = async () => {
116
114
  let reporter = getReporter();
117
115
  if (!reporter) {
118
116
  if (process.env.TAPE6_JSONL) {
119
- const JSONLReporter = (await import('tape-six/JSONLReporter.js')).default,
117
+ const {JSONLReporter} = await import('tape-six/JSONLReporter.js'),
120
118
  jsonlReporter = new JSONLReporter(options);
121
119
  reporter = jsonlReporter.report.bind(jsonlReporter);
122
120
  } else if (!process.env.TAPE6_TAP) {
123
- const TTYReporter = (await import('tape-six/TTYReporter.js')).default,
121
+ const {TTYReporter} = await import('tape-six/TTYReporter.js'),
124
122
  ttyReporter = new TTYReporter(options);
125
123
  ttyReporter.testCounter = -2;
126
124
  ttyReporter.technicalDepth = 1;
package/package.json CHANGED
@@ -1,11 +1,18 @@
1
1
  {
2
2
  "name": "tape-six-proc",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Helper for TAP the test harness for the modern JavaScript (ES6) to run tests in separate processes.",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "tape6-proc": "bin/tape6-proc.js"
8
8
  },
9
+ "scripts": {
10
+ "lint": "prettier --check .",
11
+ "lint:fix": "prettier --write .",
12
+ "test": "node ./bin/tape6-proc.js",
13
+ "test:bun": "bun run ./bin/tape6-proc.js",
14
+ "test:deno": "deno run -A ./bin/tape6-proc.js -r --allow-read -r --allow-env"
15
+ },
9
16
  "keywords": [
10
17
  "tap",
11
18
  "test",
@@ -26,6 +33,11 @@
26
33
  "homepage": "https://github.com/uhop/tape-six-proc#readme",
27
34
  "dependencies": {
28
35
  "dollar-shell": "^1.1.0",
29
- "tape-six": "^1.1.2"
36
+ "tape-six": "^1.3.4"
37
+ },
38
+ "tape6": {
39
+ "tests": [
40
+ "/tests/test-*.*js"
41
+ ]
30
42
  }
31
43
  }
package/src/TestWorker.js CHANGED
@@ -2,6 +2,7 @@ import process from 'node:process';
2
2
  import os from 'node:os';
3
3
  import {sep} from 'node:path';
4
4
  import {pathToFileURL, fileURLToPath} from 'node:url';
5
+ import crypto from 'node:crypto';
5
6
 
6
7
  import {spawn, currentExecPath, runFileArgs} from 'dollar-shell';
7
8
 
@@ -9,7 +10,8 @@ import {StopTest} from 'tape-six/State.js';
9
10
  import EventServer from 'tape-six/utils/EventServer.js';
10
11
 
11
12
  import lines from './chain/lines.js';
12
- import parse from './chain/jsonl-parse.js';
13
+ import parse from './chain/parse-prefixed-jsonl.js';
14
+ import wrap from './chain/wrap-lines.js';
13
15
 
14
16
  const baseName = pathToFileURL(process.cwd() + sep);
15
17
 
@@ -18,21 +20,24 @@ export default class TestWorker extends EventServer {
18
20
  super(reporter, numberOfTasks, options);
19
21
  this.counter = 0;
20
22
  this.idToWorker = {};
23
+ this.prefix = crypto.randomUUID();
21
24
  }
22
25
  makeTask(fileName) {
23
26
  const testName = new URL(fileName, baseName),
24
27
  id = String(++this.counter),
25
28
  worker = spawn(
26
- [
27
- currentExecPath(),
28
- ...runFileArgs.concat((this.options.runFileArgs || []).filter(x => x)),
29
- fileURLToPath(testName)
30
- ],
29
+ [currentExecPath(), ...runFileArgs, ...this.options.runFileArgs, fileURLToPath(testName)],
31
30
  {
32
31
  stdin: 'ignore',
33
32
  stdout: 'pipe',
34
- stderr: 'inherit',
35
- env: {...process.env, TAPE6_TEST: id, TAPE6_JSONL: 'Y'}
33
+ stderr: 'pipe',
34
+ env: {
35
+ ...process.env,
36
+ TAPE6_TEST: id,
37
+ TAPE6_TEST_FILE_NAME: fileName,
38
+ TAPE6_JSONL: 'Y',
39
+ TAPE6_JSONL_PREFIX: this.prefix
40
+ }
36
41
  }
37
42
  );
38
43
  this.idToWorker[id] = worker;
@@ -40,22 +45,32 @@ export default class TestWorker extends EventServer {
40
45
  worker.stdout
41
46
  .pipeThrough(new TextDecoderStream())
42
47
  .pipeThrough(lines())
43
- .pipeThrough(parse())
48
+ .pipeThrough(parse(this.prefix))
44
49
  .pipeTo(
45
50
  new WritableStream({
46
51
  write(msg) {
47
52
  try {
48
53
  self.report(id, msg);
49
54
  } catch (error) {
50
- if (!(error instanceof StopTest)) throw error;
51
- }
52
- if (msg.type === 'end' && msg.test === 0) {
53
- self.close(id);
54
- return;
55
+ if (!(error instanceof StopTest)) {
56
+ throw error;
57
+ }
55
58
  }
56
59
  }
57
60
  })
58
61
  );
62
+ worker.stderr
63
+ .pipeThrough(new TextDecoderStream())
64
+ .pipeThrough(lines())
65
+ .pipeThrough(wrap('stderr'))
66
+ .pipeTo(
67
+ new WritableStream({
68
+ write(msg) {
69
+ self.report(id, msg);
70
+ }
71
+ })
72
+ );
73
+ worker.exited.finally(() => self.close(id));
59
74
  return id;
60
75
  }
61
76
  destroyTask(id) {
@@ -1,5 +1,3 @@
1
- 'use strict';
2
-
3
1
  export const lines = () => {
4
2
  let rest = '';
5
3
  return new TransformStream({
@@ -12,7 +10,7 @@ export const lines = () => {
12
10
  for (const line of lines) controller.enqueue(line);
13
11
  },
14
12
  flush(controller) {
15
- controller.enqueue(rest);
13
+ if (rest) controller.enqueue(rest);
16
14
  rest = '';
17
15
  }
18
16
  });
@@ -0,0 +1,46 @@
1
+ export const parse = (prefix, type = 'stdout') => {
2
+ let rest = '';
3
+ let haveRest = false;
4
+ let lastLineWasJSON = false;
5
+ return new TransformStream({
6
+ transform(line, controller) {
7
+ if (line.startsWith(prefix)) {
8
+ try {
9
+ const value = JSON.parse(line.slice(prefix.length));
10
+ if (value && typeof value == 'object') {
11
+ controller.enqueue(value);
12
+ }
13
+ lastLineWasJSON = true;
14
+ } catch (_) {
15
+ // squelch
16
+ }
17
+ return;
18
+ }
19
+ if (lastLineWasJSON) {
20
+ rest += line;
21
+ lastLineWasJSON = false;
22
+ haveRest = !!rest;
23
+ } else {
24
+ if (haveRest) {
25
+ controller.enqueue({type, name: rest});
26
+ rest = line;
27
+ haveRest = !!rest;
28
+ } else {
29
+ if (line) {
30
+ rest = line;
31
+ haveRest = true;
32
+ }
33
+ }
34
+ }
35
+ },
36
+ flush(controller) {
37
+ if (haveRest) {
38
+ controller.enqueue({type, name: rest});
39
+ }
40
+ rest = '';
41
+ haveRest = false;
42
+ }
43
+ });
44
+ };
45
+
46
+ export default parse;
@@ -0,0 +1,8 @@
1
+ export const wrap = (type = 'stdout') =>
2
+ new TransformStream({
3
+ transform(line, controller) {
4
+ controller.enqueue({type, name: line});
5
+ }
6
+ });
7
+
8
+ export default wrap;
@@ -0,0 +1,12 @@
1
+ import test from 'tape-six';
2
+
3
+ test('console test', t => {
4
+ console.log('#1');
5
+ t.pass();
6
+ console.log('#2');
7
+ console.error('error #1');
8
+ console.log('#2a');
9
+ t.ok(1 < 2);
10
+ console.log('#3');
11
+ console.error('error #2');
12
+ });
package/wiki/Home.md CHANGED
@@ -1,4 +1,5 @@
1
1
  <!-- markdownlint-disable-next-line first-line-heading -->
2
+
2
3
  `tape-six-proc` is a helper for [tape-six](https://www.npmjs.com/package/tape-six)
3
4
  to run tests in separate processes.
4
5
 
@@ -17,7 +18,7 @@ Test files are directly executable with `node` or `deno` or `bun` or in a browse
17
18
  [tape-six](https://www.npmjs.com/package/tape-six) helps to organize tests. This package
18
19
  provides a utility to run tests in isolated processes:
19
20
 
20
- * [tape6-proc](./Utility-‐-tape6‐proc) to run tests in separate processes.
21
+ - [tape6-proc](./Utility-‐-tape6‐proc) to run tests in separate processes.
21
22
 
22
23
  # Formalities
23
24
 
@@ -25,5 +26,5 @@ The project is distributed under the 3-clause BSD license.
25
26
 
26
27
  Other pertinent information:
27
28
 
28
- * [Release notes](./Release-notes).
29
- * [Working on this project](./Working-on-this-project).
29
+ - [Release notes](./Release-notes).
30
+ - [Working on this project](./Working-on-this-project).
@@ -1,7 +1,8 @@
1
1
  # The current version: 1.x
2
2
 
3
- * 1.0.2 *Fixed concurrency detection. Updated dependencies.*
4
- * 1.0.1 *Updated dependencies.*
5
- * 1.0.0 *The first official release.*
6
- * 0.12.1 *Updated dependencies, which included fixes for Deno.*
7
- * 0.12.0 *Initial release.*
3
+ - 1.1.0 _Added support for stdout/stderr and `tape-six` 1.3.4._
4
+ - 1.0.2 _Fixed concurrency detection. Updated dependencies._
5
+ - 1.0.1 _Updated dependencies._
6
+ - 1.0.0 _The first official release._
7
+ - 0.12.1 _Updated dependencies, which included fixes for Deno._
8
+ - 0.12.0 _Initial release._
@@ -1,4 +1,5 @@
1
1
  <!-- markdownlint-disable-next-line first-line-heading -->
2
+
2
3
  The main utility of the package is `tape6-proc`.
3
4
 
4
5
  # Usage
@@ -21,9 +22,9 @@ and can be used the same way.
21
22
 
22
23
  Additionally it supports the following flags:
23
24
 
24
- * `--runFileArgs ARGS` &mdash; sets the arguments to pass to the test file.
25
- * Shortcut: `-r ARGS`.
26
- * This flag can be used multiple times.
25
+ - `--runFileArgs ARGS` &mdash; sets the arguments to pass to the test file.
26
+ - Shortcut: `-r ARGS`.
27
+ - This flag can be used multiple times.
27
28
 
28
29
  This flag is used mostly with Deno to supply additional arguments to the test file.
29
30
 
@@ -1,4 +1,5 @@
1
1
  <!-- markdownlint-disable-next-line first-line-heading -->
2
+
2
3
  This project uses git submodules, so the correct way to get it is:
3
4
 
4
5
  ```bash
@@ -1,17 +0,0 @@
1
- 'use strict';
2
-
3
- export const parse = () =>
4
- new TransformStream({
5
- transform(line, controller) {
6
- try {
7
- const value = JSON.parse(line);
8
- if (value && typeof value == 'object') {
9
- controller.enqueue(value);
10
- }
11
- } catch (_) {
12
- // squelch
13
- }
14
- }
15
- });
16
-
17
- export default parse;