@supertape/formatter-progress-bar 2.4.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/lib/progress-bar.js +55 -35
- package/package.json +7 -7
package/lib/progress-bar.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import {Writable} from 'stream';
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
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 = '👌';
|
|
12
11
|
const YELLOW = '#f9d472';
|
|
@@ -15,37 +14,54 @@ const {red} = chalk;
|
|
|
15
14
|
const formatErrorsCount = (a) => a ? red(a) : OK;
|
|
16
15
|
|
|
17
16
|
const isStr = (a) => typeof a === 'string';
|
|
18
|
-
const out = createOutput();
|
|
19
|
-
const store = fullstore();
|
|
20
17
|
|
|
21
18
|
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
19
|
|
|
29
|
-
let
|
|
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
|
+
}
|
|
30
45
|
|
|
31
|
-
|
|
46
|
+
export const start = ({barStore, out}) => ({total}) => {
|
|
32
47
|
out('TAP version 13');
|
|
33
48
|
|
|
34
49
|
const color = SUPERTAPE_PROGRESS_BAR_COLOR || YELLOW;
|
|
35
|
-
|
|
36
|
-
bar = createProgress({
|
|
50
|
+
const bar = barStore() || _createProgress({
|
|
37
51
|
total,
|
|
38
52
|
color,
|
|
39
53
|
test: '',
|
|
40
54
|
});
|
|
55
|
+
|
|
56
|
+
barStore(bar);
|
|
41
57
|
};
|
|
42
58
|
|
|
43
|
-
|
|
59
|
+
export const test = ({store}) => ({test}) => {
|
|
44
60
|
store(`# ${test}`);
|
|
45
61
|
};
|
|
46
62
|
|
|
47
|
-
|
|
48
|
-
|
|
63
|
+
export const testEnd = ({barStore}) => ({count, total, failed, test}) => {
|
|
64
|
+
barStore().increment({
|
|
49
65
|
count,
|
|
50
66
|
total,
|
|
51
67
|
test,
|
|
@@ -53,7 +69,7 @@ module.exports.testEnd = ({count, total, failed, test}) => {
|
|
|
53
69
|
});
|
|
54
70
|
};
|
|
55
71
|
|
|
56
|
-
|
|
72
|
+
export const fail = ({out, store}) => ({at, count, message, operator, result, expected, output, errorStack}) => {
|
|
57
73
|
out('');
|
|
58
74
|
out(store());
|
|
59
75
|
out(`❌ not ok ${count} ${message}`);
|
|
@@ -66,8 +82,8 @@ module.exports.fail = ({at, count, message, operator, actual, expected, output,
|
|
|
66
82
|
if (!isStr(output)) {
|
|
67
83
|
out(' expected: |-');
|
|
68
84
|
out(` ${expected}`);
|
|
69
|
-
out('
|
|
70
|
-
out(` ${
|
|
85
|
+
out(' result: |-');
|
|
86
|
+
out(` ${result}`);
|
|
71
87
|
}
|
|
72
88
|
|
|
73
89
|
out(` ${at}`);
|
|
@@ -81,8 +97,8 @@ module.exports.fail = ({at, count, message, operator, actual, expected, output,
|
|
|
81
97
|
out('');
|
|
82
98
|
};
|
|
83
99
|
|
|
84
|
-
|
|
85
|
-
|
|
100
|
+
export const end = ({barStore, out}) => ({count, passed, failed, skiped}) => {
|
|
101
|
+
barStore().stop();
|
|
86
102
|
|
|
87
103
|
out('');
|
|
88
104
|
|
|
@@ -111,20 +127,24 @@ module.exports.end = ({count, passed, failed, skiped}) => {
|
|
|
111
127
|
};
|
|
112
128
|
|
|
113
129
|
function createOutput() {
|
|
114
|
-
|
|
130
|
+
let output = [];
|
|
115
131
|
|
|
116
132
|
return (...args) => {
|
|
117
133
|
const [line] = args;
|
|
118
134
|
|
|
119
|
-
if (!args.length)
|
|
120
|
-
|
|
135
|
+
if (!args.length) {
|
|
136
|
+
const result = output.join('\n');
|
|
137
|
+
output = [];
|
|
138
|
+
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
121
141
|
|
|
122
142
|
output.push(line);
|
|
123
143
|
};
|
|
124
144
|
}
|
|
125
145
|
|
|
126
146
|
const getColorFn = (color) => {
|
|
127
|
-
if (
|
|
147
|
+
if (color.startsWith('#'))
|
|
128
148
|
return chalk.hex(color);
|
|
129
149
|
|
|
130
150
|
return chalk[color];
|
|
@@ -137,15 +157,15 @@ const defaultStreamOptions = {
|
|
|
137
157
|
const getStream = ({total} = defaultStreamOptions) => {
|
|
138
158
|
const is = total >= SUPERTAPE_PROGRESS_BAR_MIN;
|
|
139
159
|
|
|
140
|
-
if (is && !
|
|
160
|
+
if (is && !global._isCI || SUPERTAPE_PROGRESS_BAR === '1')
|
|
141
161
|
return stderr;
|
|
142
162
|
|
|
143
163
|
return new Writable();
|
|
144
164
|
};
|
|
145
165
|
|
|
146
|
-
|
|
166
|
+
export const _getStream = getStream;
|
|
147
167
|
|
|
148
|
-
|
|
168
|
+
function _createProgress({total, color, test}) {
|
|
149
169
|
const colorFn = getColorFn(color);
|
|
150
170
|
const bar = new cliProgress.SingleBar({
|
|
151
171
|
format: `${colorFn('{bar}')} {percentage}% | {failed} | {count}/{total} | {test}`,
|
|
@@ -167,5 +187,5 @@ const createProgress = once(({total, color, test}) => {
|
|
|
167
187
|
});
|
|
168
188
|
|
|
169
189
|
return bar;
|
|
170
|
-
}
|
|
190
|
+
}
|
|
171
191
|
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supertape/formatter-progress-bar",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.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",
|
|
7
7
|
"main": "./lib/progress-bar.js",
|
|
8
|
+
"commitType": "colon",
|
|
8
9
|
"release": false,
|
|
9
10
|
"tag": false,
|
|
10
11
|
"changelog": false,
|
|
11
|
-
"type": "
|
|
12
|
+
"type": "module",
|
|
12
13
|
"repository": {
|
|
13
14
|
"type": "git",
|
|
14
15
|
"url": "git://github.com/coderaiser/supertape.git"
|
|
@@ -39,14 +40,13 @@
|
|
|
39
40
|
"c8": "^7.3.5",
|
|
40
41
|
"eslint": "^8.0.0-beta.0",
|
|
41
42
|
"eslint-plugin-node": "^11.1.0",
|
|
42
|
-
"eslint-plugin-putout": "^
|
|
43
|
-
"madrun": "^
|
|
44
|
-
"mock-require": "^3.0.2",
|
|
43
|
+
"eslint-plugin-putout": "^16.0.1",
|
|
44
|
+
"madrun": "^9.0.0",
|
|
45
45
|
"montag": "^1.0.0",
|
|
46
46
|
"nodemon": "^2.0.2",
|
|
47
47
|
"pullout": "^4.0.0",
|
|
48
|
-
"putout": "^
|
|
49
|
-
"supertape": "^
|
|
48
|
+
"putout": "^27.2.0",
|
|
49
|
+
"supertape": "^7.0.0"
|
|
50
50
|
},
|
|
51
51
|
"license": "MIT",
|
|
52
52
|
"engines": {
|