@supertape/formatter-progress-bar 2.3.0 → 3.0.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
@@ -1,12 +1,9 @@
1
- # @supertape/formatter-progress-bar [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL]
1
+ # @supertape/formatter-progress-bar [![NPM version][NPMIMGURL]][NPMURL]
2
2
 
3
- [NPMIMGURL]: https://img.shields.io/npm/v/@supertape/formatter-progress-bar.svg?style=flat&longCache=true
4
- [NPMURL]: https://npmjs.org/package/@supertape/formatter-progress-bar "npm"
3
+ [NPMIMGURL]: https://img.shields.io/npm/v/@supertape/formatter-progress-bar.svg?style=flat&longCache=true
4
+ [NPMURL]: https://npmjs.org/package/@supertape/formatter-progress-bar "npm"
5
5
 
6
- [DependencyStatusURL]: https://david-dm.org/coderaiser/supertape?path=packages/formatter-progress-bar
7
- [DependencyStatusIMGURL]: https://david-dm.org/coderaiser/supertape.svg?path=packages/formatter-progress-bar
8
-
9
- `supertape` formatter shows progress bar.
6
+ 📼[`Supertape`](https://github.com/coderaiser/supertape) formatter shows progress bar.
10
7
 
11
8
  ## Install
12
9
 
@@ -31,4 +28,3 @@ supertape --format progress-bar lib
31
28
  ## License
32
29
 
33
30
  MIT
34
-
@@ -1,49 +1,67 @@
1
- 'use strict';
1
+ import {Writable} from 'stream';
2
2
 
3
- const {Writable} = require('stream');
3
+ import cliProgress from 'cli-progress';
4
+ import chalk from 'chalk';
5
+ import fullstore from 'fullstore';
6
+ import {isCI} from 'ci-info';
4
7
 
5
- const cliProgress = require('cli-progress');
6
- const chalk = require('chalk');
7
- const once = require('once');
8
- const fullstore = require('fullstore');
9
- const {isCI} = require('ci-info');
8
+ global._isCI = isCI;
10
9
 
11
10
  const OK = '👌';
11
+ const YELLOW = '#f9d472';
12
+
12
13
  const {red} = chalk;
13
14
  const formatErrorsCount = (a) => a ? red(a) : OK;
14
15
 
15
16
  const isStr = (a) => typeof a === 'string';
16
- const out = createOutput();
17
- const store = fullstore();
18
17
 
19
18
  const {stderr} = process;
20
- const {
21
- SUPERTAPE_PROGRESS_BAR,
22
- SUPERTAPE_PROGRESS_BAR_MIN = 100,
23
- SUPERTAPE_PROGRESS_BAR_COLOR,
24
- SUPERTAPE_PROGRESS_BAR_STACK = 1,
25
- } = process.env;
26
19
 
27
- let bar;
20
+ let SUPERTAPE_PROGRESS_BAR;
21
+ let SUPERTAPE_PROGRESS_BAR_MIN = 100;
22
+ let SUPERTAPE_PROGRESS_BAR_COLOR;
23
+ let SUPERTAPE_PROGRESS_BAR_STACK = 1;
24
+
25
+ export function createFormatter(bar) {
26
+ ({
27
+ SUPERTAPE_PROGRESS_BAR,
28
+ SUPERTAPE_PROGRESS_BAR_MIN = 100,
29
+ SUPERTAPE_PROGRESS_BAR_COLOR,
30
+ SUPERTAPE_PROGRESS_BAR_STACK = 1,
31
+ } = process.env);
32
+
33
+ const out = createOutput();
34
+ const store = fullstore();
35
+ const barStore = fullstore(bar);
36
+
37
+ return {
38
+ start: start({barStore, out}),
39
+ test: test({store}),
40
+ testEnd: testEnd({barStore}),
41
+ fail: fail({out, store}),
42
+ end: end({barStore, out}),
43
+ };
44
+ }
28
45
 
29
- module.exports.start = ({total}) => {
46
+ export const start = ({barStore, out}) => ({total}) => {
30
47
  out('TAP version 13');
31
48
 
32
- const color = SUPERTAPE_PROGRESS_BAR_COLOR || '#f9d472';
33
-
34
- bar = createProgress({
49
+ const color = SUPERTAPE_PROGRESS_BAR_COLOR || YELLOW;
50
+ const bar = barStore() || _createProgress({
35
51
  total,
36
52
  color,
37
53
  test: '',
38
54
  });
55
+
56
+ barStore(bar);
39
57
  };
40
58
 
41
- module.exports.test = ({test}) => {
59
+ export const test = ({store}) => ({test}) => {
42
60
  store(`# ${test}`);
43
61
  };
44
62
 
45
- module.exports.testEnd = ({count, total, failed, test}) => {
46
- bar.increment({
63
+ export const testEnd = ({barStore}) => ({count, total, failed, test}) => {
64
+ barStore().increment({
47
65
  count,
48
66
  total,
49
67
  test,
@@ -51,7 +69,7 @@ module.exports.testEnd = ({count, total, failed, test}) => {
51
69
  });
52
70
  };
53
71
 
54
- module.exports.fail = ({at, count, message, operator, actual, expected, output, errorStack}) => {
72
+ export const fail = ({out, store}) => ({at, count, message, operator, result, expected, output, errorStack}) => {
55
73
  out('');
56
74
  out(store());
57
75
  out(`❌ not ok ${count} ${message}`);
@@ -64,8 +82,8 @@ module.exports.fail = ({at, count, message, operator, actual, expected, output,
64
82
  if (!isStr(output)) {
65
83
  out(' expected: |-');
66
84
  out(` ${expected}`);
67
- out(' actual: |-');
68
- out(` ${actual}`);
85
+ out(' result: |-');
86
+ out(` ${result}`);
69
87
  }
70
88
 
71
89
  out(` ${at}`);
@@ -79,8 +97,8 @@ module.exports.fail = ({at, count, message, operator, actual, expected, output,
79
97
  out('');
80
98
  };
81
99
 
82
- module.exports.end = ({count, passed, failed, skiped}) => {
83
- bar.stop();
100
+ export const end = ({barStore, out}) => ({count, passed, failed, skiped}) => {
101
+ barStore().stop();
84
102
 
85
103
  out('');
86
104
 
@@ -92,36 +110,41 @@ module.exports.end = ({count, passed, failed, skiped}) => {
92
110
  out(`# ⚠️ skip ${skiped}`);
93
111
  }
94
112
 
113
+ out('');
114
+
95
115
  if (failed) {
96
116
  out(`# ❌ fail ${failed}`);
97
117
  }
98
118
 
99
- out('');
100
-
101
119
  if (!failed) {
102
120
  out('# ✅ ok');
103
- out('');
104
- out('');
105
121
  }
106
122
 
123
+ out('');
124
+ out('');
125
+
107
126
  return `\r${out()}`;
108
127
  };
109
128
 
110
129
  function createOutput() {
111
- const output = [];
130
+ let output = [];
112
131
 
113
132
  return (...args) => {
114
133
  const [line] = args;
115
134
 
116
- if (!args.length)
117
- return output.join('\n');
135
+ if (!args.length) {
136
+ const result = output.join('\n');
137
+ output = [];
138
+
139
+ return result;
140
+ }
118
141
 
119
142
  output.push(line);
120
143
  };
121
144
  }
122
145
 
123
146
  const getColorFn = (color) => {
124
- if (/^#/.test(color))
147
+ if (color.startsWith('#'))
125
148
  return chalk.hex(color);
126
149
 
127
150
  return chalk[color];
@@ -134,15 +157,15 @@ const defaultStreamOptions = {
134
157
  const getStream = ({total} = defaultStreamOptions) => {
135
158
  const is = total >= SUPERTAPE_PROGRESS_BAR_MIN;
136
159
 
137
- if (is && !isCI || SUPERTAPE_PROGRESS_BAR === '1')
160
+ if (is && !global._isCI || SUPERTAPE_PROGRESS_BAR === '1')
138
161
  return stderr;
139
162
 
140
163
  return new Writable();
141
164
  };
142
165
 
143
- module.exports._getStream = getStream;
166
+ export const _getStream = getStream;
144
167
 
145
- const createProgress = once(({total, color, test}) => {
168
+ function _createProgress({total, color, test}) {
146
169
  const colorFn = getColorFn(color);
147
170
  const bar = new cliProgress.SingleBar({
148
171
  format: `${colorFn('{bar}')} {percentage}% | {failed} | {count}/{total} | {test}`,
@@ -164,5 +187,5 @@ const createProgress = once(({total, color, test}) => {
164
187
  });
165
188
 
166
189
  return bar;
167
- });
190
+ }
168
191
 
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@supertape/formatter-progress-bar",
3
- "version": "2.3.0",
3
+ "version": "3.0.0",
4
4
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
5
- "description": "supertape formatter progress bar",
5
+ "description": "📼 Supertape formatter progress bar",
6
6
  "homepage": "http://github.com/coderaiser/supertape",
7
7
  "main": "./lib/progress-bar.js",
8
+ "commitType": "colon",
8
9
  "release": false,
9
10
  "tag": false,
10
11
  "changelog": false,
11
- "type": "commonjs",
12
+ "type": "module",
12
13
  "repository": {
13
14
  "type": "git",
14
15
  "url": "git://github.com/coderaiser/supertape.git"
@@ -36,18 +37,16 @@
36
37
  ],
37
38
  "devDependencies": {
38
39
  "@babel/core": "^7.12.9",
39
- "@babel/eslint-parser": "^7.12.1",
40
40
  "c8": "^7.3.5",
41
41
  "eslint": "^8.0.0-beta.0",
42
42
  "eslint-plugin-node": "^11.1.0",
43
- "eslint-plugin-putout": "^10.0.1",
44
- "madrun": "^8.0.0",
45
- "mock-require": "^3.0.2",
43
+ "eslint-plugin-putout": "^16.0.1",
44
+ "madrun": "^9.0.0",
46
45
  "montag": "^1.0.0",
47
46
  "nodemon": "^2.0.2",
48
47
  "pullout": "^4.0.0",
49
- "putout": "^20.0.1",
50
- "supertape": "^6.0.1"
48
+ "putout": "^27.2.0",
49
+ "supertape": "^7.0.0"
51
50
  },
52
51
  "license": "MIT",
53
52
  "engines": {