supertape 10.6.1 → 10.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/ChangeLog CHANGED
@@ -1,3 +1,11 @@
1
+ 2024.06.04, v10.7.0
2
+
3
+ feature:
4
+ - dcb4dfb supertape: add ability to use console.log in worker mode
5
+ - 188ab81 @supertape/formatter-progress-bar: add comment
6
+ - 79a0e2f supertape: rm unused quiet
7
+ - 5f3d825 @putout/formatter-progress-bar: ✅ ok in WebStorm
8
+
1
9
  2024.06.04, v10.6.1
2
10
 
3
11
  feature:
@@ -2,12 +2,14 @@ import {EventEmitter} from 'node:events';
2
2
  import {parentPort, workerData} from 'node:worker_threads';
3
3
 
4
4
  const {assign} = Object;
5
+ const returns = (a) => () => a;
5
6
 
6
7
  export const createCommunication = (argv) => {
7
8
  if (parentPort)
8
9
  return {
9
10
  parentPort,
10
11
  workerData,
12
+ isMaster: returns(false),
11
13
  };
12
14
 
13
15
  const {newWorker, newParentPort} = fakeWorkers();
@@ -16,6 +18,7 @@ export const createCommunication = (argv) => {
16
18
  worker: newWorker,
17
19
  parentPort: newParentPort,
18
20
  workerData: argv,
21
+ isMaster: returns(true),
19
22
  };
20
23
  };
21
24
 
package/bin/subscribe.mjs CHANGED
@@ -1,22 +1,34 @@
1
1
  import keyPress from '@putout/cli-keypress';
2
2
  import harnessCreator from '../lib/formatter/harness.js';
3
+ import {parse} from 'flatted';
4
+ import {
5
+ SPLITTER,
6
+ CONSOLE_LOG,
7
+ CONSOLE_ERROR,
8
+ } from '../lib/worker/create-console-log.js';
3
9
 
4
- const {createHarness} = harnessCreator;
10
+ const one = (fn) => (a) => fn(a);
5
11
 
12
+ const {createHarness} = harnessCreator;
6
13
  const resolveFormatter = async (name) => await import(`@supertape/formatter-${name}`);
7
14
 
8
- export async function subscribe({name, quiet, exit, worker, stdout}) {
15
+ export async function subscribe({name, exit, worker, stdout}) {
9
16
  const {isStop} = keyPress();
10
17
  const harness = createHarness(await resolveFormatter(name));
11
18
 
12
- if (!quiet)
13
- harness.pipe(stdout);
19
+ harness.pipe(stdout);
14
20
 
15
21
  worker.on('exit', (code) => {
16
22
  exit(code);
17
23
  });
18
24
 
19
25
  worker.on('message', ([type, a]) => {
26
+ if (type === CONSOLE_LOG)
27
+ return consoleLog(a);
28
+
29
+ if (type === CONSOLE_ERROR)
30
+ return consoleError(a);
31
+
20
32
  harness.write({
21
33
  type,
22
34
  ...a,
@@ -26,3 +38,19 @@ export async function subscribe({name, quiet, exit, worker, stdout}) {
26
38
  worker.postMessage(['stop']);
27
39
  });
28
40
  }
41
+
42
+ function consoleLog({message}) {
43
+ const messages = message
44
+ .split(SPLITTER)
45
+ .map(one(parse));
46
+
47
+ console.log(...messages);
48
+ }
49
+
50
+ function consoleError({message}) {
51
+ const messages = message
52
+ .split(SPLITTER)
53
+ .map(one(parse));
54
+
55
+ console.error(...messages);
56
+ }
package/bin/supertape.mjs CHANGED
@@ -5,11 +5,16 @@ import {createIsStop} from './is-stop.mjs';
5
5
  import {createFormatter} from './formatter.mjs';
6
6
  import {parseArgs} from '../lib/cli/parse-args.js';
7
7
  import cli from '../lib/cli.js';
8
+ import {
9
+ overrideConsoleError,
10
+ overrideConsoleLog,
11
+ } from '../lib/worker/create-console-log.js';
8
12
 
9
13
  const {
10
14
  worker,
11
15
  parentPort,
12
16
  workerData,
17
+ isMaster,
13
18
  } = createCommunication(process.argv);
14
19
 
15
20
  const args = parseArgs(process.argv.slice(2));
@@ -23,14 +28,22 @@ const {
23
28
  const workerFormatter = createFormatter(parentPort);
24
29
  const isStop = createIsStop(parentPort);
25
30
 
26
- if (worker)
31
+ if (isMaster()) {
27
32
  subscribe({
28
33
  name: args.format,
29
- quiet: args.quiet,
30
34
  exit,
31
35
  worker,
32
36
  stdout,
33
37
  });
38
+ } else {
39
+ overrideConsoleLog(parentPort, {
40
+ console,
41
+ });
42
+
43
+ overrideConsoleError(parentPort, {
44
+ console,
45
+ });
46
+ }
34
47
 
35
48
  export default await cli({
36
49
  stdout,
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {Transform: _Transform} = require('node:stream');
4
+
4
5
  const {assign} = Object;
5
6
 
6
7
  module.exports.createHarness = (reporter, {Transform = _Transform} = {}) => {
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ const {stringify} = require('flatted');
4
+ const SPLITTER = '>[supertape-splitter]<';
5
+ const CONSOLE_LOG = 'console:log';
6
+ const CONSOLE_ERROR = 'console:error';
7
+
8
+ module.exports.CONSOLE_ERROR = CONSOLE_ERROR;
9
+ module.exports.CONSOLE_LOG = CONSOLE_LOG;
10
+ module.exports.SPLITTER = SPLITTER;
11
+
12
+ module.exports.overrideConsoleLog = (parentPort, {console = global.console} = {}) => {
13
+ const {log} = console;
14
+
15
+ console.log = createConsoleMethod(CONSOLE_LOG, parentPort);
16
+ return {
17
+ getBackConsoleLog: () => {
18
+ console.log = log;
19
+ },
20
+ };
21
+ };
22
+
23
+ module.exports.overrideConsoleError = (parentPort, {console = global.console} = {}) => {
24
+ const {error} = console;
25
+
26
+ console.error = createConsoleMethod(CONSOLE_ERROR, parentPort);
27
+ return {
28
+ getBackConsoleError: () => {
29
+ console.error = error;
30
+ },
31
+ };
32
+ };
33
+
34
+ const createConsoleMethod = (type, parentPort) => (...messages) => {
35
+ const prepared = [];
36
+
37
+ for (const message of messages)
38
+ prepared.push(stringify(message));
39
+
40
+ parentPort.postMessage([
41
+ type, {
42
+ message: prepared.join(SPLITTER),
43
+ },
44
+ ]);
45
+ };
46
+
47
+ module.exports._createConsoleLog = createConsoleMethod;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supertape",
3
- "version": "10.6.1",
3
+ "version": "10.7.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",
@@ -51,6 +51,7 @@
51
51
  "@supertape/formatter-time": "^1.0.0",
52
52
  "@supertape/operator-stub": "^3.0.0",
53
53
  "cli-progress": "^3.8.2",
54
+ "flatted": "^3.3.1",
54
55
  "fullstore": "^3.0.0",
55
56
  "glob": "^10.3.10",
56
57
  "jest-diff": "^29.0.1",
@@ -88,7 +89,7 @@
88
89
  "pullout": "^5.0.1",
89
90
  "putout": "^35.0.0",
90
91
  "runsome": "^1.0.0",
91
- "try-catch": "^3.0.0",
92
+ "try-catch": "^3.0.1",
92
93
  "typescript": "^5.1.6"
93
94
  },
94
95
  "license": "MIT",