@supertape/formatter-progress-bar 2.4.0 → 4.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/lib/progress-bar.js +69 -37
- package/package.json +10 -11
package/lib/progress-bar.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import {Writable} from 'node:stream';
|
|
2
|
+
import cliProgress from 'cli-progress';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import fullstore from 'fullstore';
|
|
5
|
+
import {isCI} from 'ci-info';
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
|
|
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');
|
|
7
|
+
global._isCI = isCI;
|
|
10
8
|
|
|
11
9
|
const OK = '👌';
|
|
12
10
|
const YELLOW = '#f9d472';
|
|
@@ -15,37 +13,67 @@ const {red} = chalk;
|
|
|
15
13
|
const formatErrorsCount = (a) => a ? red(a) : OK;
|
|
16
14
|
|
|
17
15
|
const isStr = (a) => typeof a === 'string';
|
|
18
|
-
const out = createOutput();
|
|
19
|
-
const store = fullstore();
|
|
20
16
|
|
|
21
17
|
const {stderr} = process;
|
|
22
|
-
const {
|
|
23
|
-
SUPERTAPE_PROGRESS_BAR,
|
|
24
|
-
SUPERTAPE_PROGRESS_BAR_MIN = 100,
|
|
25
|
-
SUPERTAPE_PROGRESS_BAR_COLOR,
|
|
26
|
-
SUPERTAPE_PROGRESS_BAR_STACK = 1,
|
|
27
|
-
} = process.env;
|
|
28
18
|
|
|
29
|
-
let
|
|
19
|
+
let SUPERTAPE_PROGRESS_BAR;
|
|
20
|
+
let SUPERTAPE_PROGRESS_BAR_MIN = 100;
|
|
21
|
+
let SUPERTAPE_PROGRESS_BAR_COLOR;
|
|
22
|
+
let SUPERTAPE_PROGRESS_BAR_STACK = 1;
|
|
23
|
+
|
|
24
|
+
export function createFormatter(bar) {
|
|
25
|
+
({
|
|
26
|
+
SUPERTAPE_PROGRESS_BAR,
|
|
27
|
+
SUPERTAPE_PROGRESS_BAR_MIN = 100,
|
|
28
|
+
SUPERTAPE_PROGRESS_BAR_COLOR,
|
|
29
|
+
SUPERTAPE_PROGRESS_BAR_STACK = 1,
|
|
30
|
+
} = process.env);
|
|
31
|
+
|
|
32
|
+
const out = createOutput();
|
|
33
|
+
const store = fullstore();
|
|
34
|
+
const barStore = fullstore(bar);
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
start: start({
|
|
38
|
+
barStore,
|
|
39
|
+
out,
|
|
40
|
+
}),
|
|
41
|
+
test: test({
|
|
42
|
+
store,
|
|
43
|
+
}),
|
|
44
|
+
testEnd: testEnd({
|
|
45
|
+
barStore,
|
|
46
|
+
}),
|
|
47
|
+
fail: fail({
|
|
48
|
+
out,
|
|
49
|
+
store,
|
|
50
|
+
}),
|
|
51
|
+
end: end({
|
|
52
|
+
barStore,
|
|
53
|
+
out,
|
|
54
|
+
}),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
30
57
|
|
|
31
|
-
|
|
58
|
+
export const start = ({barStore, out}) => ({total}) => {
|
|
32
59
|
out('TAP version 13');
|
|
33
60
|
|
|
34
61
|
const color = SUPERTAPE_PROGRESS_BAR_COLOR || YELLOW;
|
|
35
|
-
|
|
36
|
-
bar = createProgress({
|
|
62
|
+
const bar = barStore() || _createProgress({
|
|
37
63
|
total,
|
|
38
64
|
color,
|
|
39
65
|
test: '',
|
|
40
66
|
});
|
|
67
|
+
|
|
68
|
+
barStore(bar);
|
|
41
69
|
};
|
|
42
70
|
|
|
43
|
-
|
|
71
|
+
export const test = ({store}) => ({test}) => {
|
|
44
72
|
store(`# ${test}`);
|
|
45
73
|
};
|
|
46
74
|
|
|
47
|
-
|
|
48
|
-
|
|
75
|
+
export const testEnd = ({barStore}) => ({count, total, failed, test}) => {
|
|
76
|
+
barStore().increment({
|
|
49
77
|
count,
|
|
50
78
|
total,
|
|
51
79
|
test,
|
|
@@ -53,7 +81,7 @@ module.exports.testEnd = ({count, total, failed, test}) => {
|
|
|
53
81
|
});
|
|
54
82
|
};
|
|
55
83
|
|
|
56
|
-
|
|
84
|
+
export const fail = ({out, store}) => ({at, count, message, operator, result, expected, output, errorStack}) => {
|
|
57
85
|
out('');
|
|
58
86
|
out(store());
|
|
59
87
|
out(`❌ not ok ${count} ${message}`);
|
|
@@ -66,8 +94,8 @@ module.exports.fail = ({at, count, message, operator, actual, expected, output,
|
|
|
66
94
|
if (!isStr(output)) {
|
|
67
95
|
out(' expected: |-');
|
|
68
96
|
out(` ${expected}`);
|
|
69
|
-
out('
|
|
70
|
-
out(` ${
|
|
97
|
+
out(' result: |-');
|
|
98
|
+
out(` ${result}`);
|
|
71
99
|
}
|
|
72
100
|
|
|
73
101
|
out(` ${at}`);
|
|
@@ -81,8 +109,8 @@ module.exports.fail = ({at, count, message, operator, actual, expected, output,
|
|
|
81
109
|
out('');
|
|
82
110
|
};
|
|
83
111
|
|
|
84
|
-
|
|
85
|
-
|
|
112
|
+
export const end = ({barStore, out}) => ({count, passed, failed, skiped}) => {
|
|
113
|
+
barStore().stop();
|
|
86
114
|
|
|
87
115
|
out('');
|
|
88
116
|
|
|
@@ -111,20 +139,25 @@ module.exports.end = ({count, passed, failed, skiped}) => {
|
|
|
111
139
|
};
|
|
112
140
|
|
|
113
141
|
function createOutput() {
|
|
114
|
-
|
|
142
|
+
let output = [];
|
|
115
143
|
|
|
116
144
|
return (...args) => {
|
|
117
145
|
const [line] = args;
|
|
118
146
|
|
|
119
|
-
if (!args.length)
|
|
120
|
-
|
|
147
|
+
if (!args.length) {
|
|
148
|
+
const result = output.join('\n');
|
|
149
|
+
|
|
150
|
+
output = [];
|
|
151
|
+
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
121
154
|
|
|
122
155
|
output.push(line);
|
|
123
156
|
};
|
|
124
157
|
}
|
|
125
158
|
|
|
126
159
|
const getColorFn = (color) => {
|
|
127
|
-
if (
|
|
160
|
+
if (color.startsWith('#'))
|
|
128
161
|
return chalk.hex(color);
|
|
129
162
|
|
|
130
163
|
return chalk[color];
|
|
@@ -137,15 +170,15 @@ const defaultStreamOptions = {
|
|
|
137
170
|
const getStream = ({total} = defaultStreamOptions) => {
|
|
138
171
|
const is = total >= SUPERTAPE_PROGRESS_BAR_MIN;
|
|
139
172
|
|
|
140
|
-
if (is && !
|
|
173
|
+
if (is && !global._isCI || SUPERTAPE_PROGRESS_BAR === '1')
|
|
141
174
|
return stderr;
|
|
142
175
|
|
|
143
176
|
return new Writable();
|
|
144
177
|
};
|
|
145
178
|
|
|
146
|
-
|
|
179
|
+
export const _getStream = getStream;
|
|
147
180
|
|
|
148
|
-
|
|
181
|
+
function _createProgress({total, color, test}) {
|
|
149
182
|
const colorFn = getColorFn(color);
|
|
150
183
|
const bar = new cliProgress.SingleBar({
|
|
151
184
|
format: `${colorFn('{bar}')} {percentage}% | {failed} | {count}/{total} | {test}`,
|
|
@@ -167,5 +200,4 @@ const createProgress = once(({total, color, test}) => {
|
|
|
167
200
|
});
|
|
168
201
|
|
|
169
202
|
return bar;
|
|
170
|
-
}
|
|
171
|
-
|
|
203
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supertape/formatter-progress-bar",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
5
|
"description": "📼 Supertape formatter progress bar",
|
|
6
6
|
"homepage": "http://github.com/coderaiser/supertape",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"release": false,
|
|
9
9
|
"tag": false,
|
|
10
10
|
"changelog": false,
|
|
11
|
-
"type": "
|
|
11
|
+
"type": "module",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "git://github.com/coderaiser/supertape.git"
|
|
@@ -36,21 +36,20 @@
|
|
|
36
36
|
],
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@babel/core": "^7.12.9",
|
|
39
|
-
"c8": "^
|
|
39
|
+
"c8": "^8.0.0",
|
|
40
40
|
"eslint": "^8.0.0-beta.0",
|
|
41
|
-
"eslint-plugin-
|
|
42
|
-
"eslint-plugin-putout": "^
|
|
43
|
-
"madrun": "^
|
|
44
|
-
"mock-require": "^3.0.2",
|
|
41
|
+
"eslint-plugin-n": "^16.0.1",
|
|
42
|
+
"eslint-plugin-putout": "^19.0.3",
|
|
43
|
+
"madrun": "^9.0.0",
|
|
45
44
|
"montag": "^1.0.0",
|
|
46
|
-
"nodemon": "^
|
|
45
|
+
"nodemon": "^3.0.1",
|
|
47
46
|
"pullout": "^4.0.0",
|
|
48
|
-
"putout": "^
|
|
49
|
-
"supertape": "^
|
|
47
|
+
"putout": "^31.0.3",
|
|
48
|
+
"supertape": "^8.0.0"
|
|
50
49
|
},
|
|
51
50
|
"license": "MIT",
|
|
52
51
|
"engines": {
|
|
53
|
-
"node": ">=
|
|
52
|
+
"node": ">=16"
|
|
54
53
|
},
|
|
55
54
|
"publishConfig": {
|
|
56
55
|
"access": "public"
|