escover 1.4.1 → 1.6.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 +24 -0
- package/lib/cli/cli.js +17 -5
- package/lib/formatters/files.js +90 -0
- package/lib/{report.js → formatters/lines.js} +1 -1
- package/lib/transform.js +5 -1
- package/package.json +2 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
2022.01.17, v1.6.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- escover: add sorting
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
2022.01.17, v1.5.2
|
|
8
|
+
|
|
9
|
+
fix:
|
|
10
|
+
- escover: add ability to override ZENLOAD && NODE_OPTIONS
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
2022.01.17, v1.5.1
|
|
14
|
+
|
|
15
|
+
feature:
|
|
16
|
+
- escover: add lines %
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
2022.01.17, v1.5.0
|
|
20
|
+
|
|
21
|
+
feature:
|
|
22
|
+
- escover: add formatter table
|
|
23
|
+
|
|
24
|
+
|
|
1
25
|
2022.01.15, v1.4.1
|
|
2
26
|
|
|
3
27
|
feature:
|
package/lib/cli/cli.js
CHANGED
|
@@ -3,17 +3,26 @@ import tryCatch from 'try-catch';
|
|
|
3
3
|
import yargsParser from 'yargs-parser';
|
|
4
4
|
|
|
5
5
|
import {version} from './version.js';
|
|
6
|
-
import
|
|
6
|
+
import reportLines from '../formatters/lines.js';
|
|
7
|
+
import reportFiles from '../formatters/files.js';
|
|
8
|
+
|
|
9
|
+
const {ESCOVER_FORMAT, NODE_OPTIONS = ''} = process.env;
|
|
7
10
|
|
|
8
11
|
export const cli = ({argv, exit, read}) => {
|
|
9
12
|
const args = yargsParser(argv.slice(2), {
|
|
13
|
+
string: [
|
|
14
|
+
'format',
|
|
15
|
+
],
|
|
10
16
|
boolean: [
|
|
11
17
|
'version',
|
|
12
18
|
],
|
|
13
19
|
alias: {
|
|
14
20
|
v: 'version',
|
|
21
|
+
f: 'format',
|
|
22
|
+
},
|
|
23
|
+
default: {
|
|
24
|
+
format: ESCOVER_FORMAT || 'files',
|
|
15
25
|
},
|
|
16
|
-
configuration: {},
|
|
17
26
|
});
|
|
18
27
|
|
|
19
28
|
if (args.version) {
|
|
@@ -29,16 +38,19 @@ export const cli = ({argv, exit, read}) => {
|
|
|
29
38
|
|
|
30
39
|
const coverage = read();
|
|
31
40
|
|
|
32
|
-
|
|
41
|
+
if (args.format === 'lines')
|
|
42
|
+
return reportLines(coverage);
|
|
43
|
+
|
|
44
|
+
reportFiles(coverage);
|
|
33
45
|
};
|
|
34
46
|
|
|
35
47
|
function execute(cmd, exit) {
|
|
36
48
|
const [error] = tryCatch(execSync, cmd, {
|
|
37
49
|
stdio: [0, 1, 2],
|
|
38
50
|
env: {
|
|
39
|
-
...process.env,
|
|
40
|
-
NODE_OPTIONS: '--no-warnings --loader zenload',
|
|
41
51
|
ZENLOAD: 'escover,mock-import',
|
|
52
|
+
...process.env,
|
|
53
|
+
NODE_OPTIONS: `--no-warnings --loader zenload ${NODE_OPTIONS} `,
|
|
42
54
|
},
|
|
43
55
|
});
|
|
44
56
|
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
table,
|
|
3
|
+
getBorderCharacters,
|
|
4
|
+
} from 'table';
|
|
5
|
+
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
|
|
8
|
+
const CWD = process.cwd();
|
|
9
|
+
const {
|
|
10
|
+
entries,
|
|
11
|
+
keys,
|
|
12
|
+
} = Object;
|
|
13
|
+
|
|
14
|
+
export default (coverageFile) => {
|
|
15
|
+
const files = parseCoverageFile(coverageFile);
|
|
16
|
+
|
|
17
|
+
const tableData = [
|
|
18
|
+
['File', '% Lines', 'Uncovered Lines #s'],
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
for (const {filename, covered, lines, percentLines} of files) {
|
|
22
|
+
const uncoveredLines = lines.join(', ');
|
|
23
|
+
|
|
24
|
+
if (covered) {
|
|
25
|
+
tableData.push([chalk.green(filename), chalk.green(percentLines), '']);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
tableData.push([chalk.red(filename), chalk.red(percentLines), chalk.red(uncoveredLines)]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
process.stdout.write(table(tableData, {
|
|
33
|
+
drawHorizontalLine: (raw) => {
|
|
34
|
+
return !raw || raw === 1 || raw === files.length + 1;
|
|
35
|
+
},
|
|
36
|
+
columns: [{
|
|
37
|
+
paddingLeft: 0,
|
|
38
|
+
}],
|
|
39
|
+
border: {
|
|
40
|
+
...getBorderCharacters('void'),
|
|
41
|
+
topBody: '-',
|
|
42
|
+
bottomBody: '-',
|
|
43
|
+
joinBody: '-',
|
|
44
|
+
topJoin: '|',
|
|
45
|
+
bottomJoin: '|',
|
|
46
|
+
joinJoin: '|',
|
|
47
|
+
bodyJoin: '|',
|
|
48
|
+
},
|
|
49
|
+
}));
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
function parseUncoveredLines(lines) {
|
|
53
|
+
const uncoveredLines = [];
|
|
54
|
+
|
|
55
|
+
for (const [line, covered] of entries(lines)) {
|
|
56
|
+
if (covered)
|
|
57
|
+
continue;
|
|
58
|
+
|
|
59
|
+
uncoveredLines.push(line);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return uncoveredLines;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function parseCoverageFile(coverageFile) {
|
|
66
|
+
const files = [];
|
|
67
|
+
for (const {name, lines} of coverageFile) {
|
|
68
|
+
const filename = name.replace(CWD + '/', '');
|
|
69
|
+
const uncoveredLines = parseUncoveredLines(lines);
|
|
70
|
+
|
|
71
|
+
const linesCount = keys(lines).length;
|
|
72
|
+
const percentLines = getPercentLines(linesCount, uncoveredLines);
|
|
73
|
+
|
|
74
|
+
files.push({
|
|
75
|
+
filename,
|
|
76
|
+
covered: !uncoveredLines.length,
|
|
77
|
+
lines: uncoveredLines,
|
|
78
|
+
percentLines,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return files;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function getPercentLines(linesCount, uncoveredLines) {
|
|
86
|
+
if (!linesCount)
|
|
87
|
+
return 100;
|
|
88
|
+
|
|
89
|
+
return 100 - Math.round(100 / linesCount * uncoveredLines.length);
|
|
90
|
+
}
|
package/lib/transform.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
const sort = (a) => new Map(Array.from(a.entries()).sort());
|
|
2
|
+
|
|
1
3
|
export const transform = (files) => {
|
|
2
4
|
const result = [];
|
|
5
|
+
const sorted = sort(files);
|
|
3
6
|
|
|
4
|
-
for (const [rawName, places] of
|
|
7
|
+
for (const [rawName, places] of sorted.entries()) {
|
|
5
8
|
const rawLines = {};
|
|
6
9
|
|
|
7
10
|
for (const [place, covered] of places.entries()) {
|
|
@@ -18,3 +21,4 @@ export const transform = (files) => {
|
|
|
18
21
|
|
|
19
22
|
return result;
|
|
20
23
|
};
|
|
24
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "escover",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
5
|
"description": "Coverage for EcmaScript Modules",
|
|
6
6
|
"main": "lib/escover.js",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"montag": "^1.2.1",
|
|
44
44
|
"once": "^1.4.0",
|
|
45
45
|
"putout": "^24.0.2",
|
|
46
|
+
"table": "^6.8.0",
|
|
46
47
|
"try-catch": "^3.0.0",
|
|
47
48
|
"yargs-parser": "^21.0.0",
|
|
48
49
|
"zenload": "^1.4.0"
|