escover 1.8.0 → 1.11.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 +26 -0
- package/bin/escover.js +4 -2
- package/lib/cli/cli.js +8 -4
- package/lib/{coverage-file.js → coverage-file/coverage-file.js} +7 -7
- package/lib/coverage-file/find-cache-dir.js +14 -0
- package/lib/coverage-file/lcov.js +17 -0
- package/lib/exit.js +2 -2
- package/lib/formatters/files.js +18 -7
- package/lib/formatters/lines.js +20 -15
- package/lib/instrument/plugin-mark/continue.js +10 -0
- package/lib/instrument/plugin-mark/index.js +18 -2
- package/package.json +3 -5
- package/example/example.js +0 -4
package/ChangeLog
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
2022.01.19, v1.11.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- escover: mark: add support of continue
|
|
5
|
+
- escover: coverage-file: read -> readCoverage
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
2022.01.19, v1.10.0
|
|
9
|
+
|
|
10
|
+
feature:
|
|
11
|
+
- escover: add .. when to many lines to display
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
2022.01.19, v1.9.0
|
|
15
|
+
|
|
16
|
+
feature:
|
|
17
|
+
- escover: formatters: files: add ability to cut lines, when count more then 10
|
|
18
|
+
- escover: formatters returning a string
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
2022.01.19, v1.8.1
|
|
22
|
+
|
|
23
|
+
fix:
|
|
24
|
+
- npmignore: add example
|
|
25
|
+
|
|
26
|
+
|
|
1
27
|
2022.01.19, v1.8.0
|
|
2
28
|
|
|
3
29
|
fix:
|
package/bin/escover.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import {cli} from '../lib/cli/cli.js';
|
|
4
|
-
import {
|
|
4
|
+
import {readCoverage} from '../lib/coverage-file/coverage-file.js';
|
|
5
|
+
import {readConfig} from '../lib/config.js';
|
|
5
6
|
|
|
6
7
|
cli({
|
|
7
8
|
argv: process.argv,
|
|
8
9
|
exit: process.exit,
|
|
9
|
-
|
|
10
|
+
readCoverage,
|
|
11
|
+
readConfig,
|
|
10
12
|
});
|
|
11
13
|
|
package/lib/cli/cli.js
CHANGED
|
@@ -8,7 +8,7 @@ import reportFiles from '../formatters/files.js';
|
|
|
8
8
|
|
|
9
9
|
const {ESCOVER_FORMAT, NODE_OPTIONS = ''} = process.env;
|
|
10
10
|
|
|
11
|
-
export const cli = ({argv, exit,
|
|
11
|
+
export const cli = ({argv, exit, readCoverage}) => {
|
|
12
12
|
const args = yargsParser(argv.slice(2), {
|
|
13
13
|
string: [
|
|
14
14
|
'format',
|
|
@@ -36,12 +36,16 @@ export const cli = ({argv, exit, read}) => {
|
|
|
36
36
|
execute('"' + cmd.join(`" "`) + '"', exit);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const coverage =
|
|
39
|
+
const coverage = readCoverage();
|
|
40
|
+
|
|
41
|
+
let output = '';
|
|
40
42
|
|
|
41
43
|
if (args.format === 'lines')
|
|
42
|
-
|
|
44
|
+
output = reportLines(coverage);
|
|
45
|
+
else
|
|
46
|
+
output = reportFiles(coverage);
|
|
43
47
|
|
|
44
|
-
|
|
48
|
+
process.stdout.write(output);
|
|
45
49
|
};
|
|
46
50
|
|
|
47
51
|
function execute(cmd, exit) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import tryCatch from 'try-catch';
|
|
2
1
|
import {
|
|
3
2
|
writeFileSync,
|
|
4
3
|
readFileSync,
|
|
5
4
|
} from 'fs';
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
5
|
+
import tryCatch from 'try-catch';
|
|
6
|
+
import {getFileEntries} from '../c4.js';
|
|
7
|
+
import {transform} from '../transform.js';
|
|
8
|
+
import {merge} from '../merge.js';
|
|
9
|
+
import {findCacheDir} from './find-cache-dir.js';
|
|
10
10
|
|
|
11
11
|
const {
|
|
12
12
|
stringify,
|
|
@@ -16,7 +16,7 @@ const {
|
|
|
16
16
|
const NAME = 'escover';
|
|
17
17
|
const buildName = (a) => `${a}/${NAME}.json`;
|
|
18
18
|
|
|
19
|
-
export const
|
|
19
|
+
export const writeCoverage = () => {
|
|
20
20
|
const files = getFileEntries();
|
|
21
21
|
|
|
22
22
|
if (!files.size)
|
|
@@ -33,7 +33,7 @@ export const write = () => {
|
|
|
33
33
|
writeFileSync(buildName(name), stringify(merged, null, 4));
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
export const
|
|
36
|
+
export const readCoverage = () => {
|
|
37
37
|
const name = findCacheDir({
|
|
38
38
|
name: NAME,
|
|
39
39
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const {entries} = Object;
|
|
2
|
+
|
|
3
|
+
export const createLcov = (files) => {
|
|
4
|
+
const result = [];
|
|
5
|
+
|
|
6
|
+
for (const {name, lines} of files) {
|
|
7
|
+
result.push(`SF:${name}`);
|
|
8
|
+
for (const [line, covered] of entries(lines)) {
|
|
9
|
+
const count = covered ? 1 : 0;
|
|
10
|
+
result.push(`DA:${line},${count}`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
result.push('end_of_record');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return result.join('\n');
|
|
17
|
+
};
|
package/lib/exit.js
CHANGED
package/lib/formatters/files.js
CHANGED
|
@@ -19,7 +19,7 @@ export default (coverageFile) => {
|
|
|
19
19
|
];
|
|
20
20
|
|
|
21
21
|
for (const {filename, covered, lines, percentLines} of files) {
|
|
22
|
-
const uncoveredLines = lines
|
|
22
|
+
const uncoveredLines = formatLines(lines);
|
|
23
23
|
|
|
24
24
|
if (covered) {
|
|
25
25
|
tableData.push([chalk.green(filename), chalk.green(percentLines), '']);
|
|
@@ -29,7 +29,7 @@ export default (coverageFile) => {
|
|
|
29
29
|
tableData.push([chalk.red(filename), chalk.red(percentLines), chalk.red(uncoveredLines)]);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
return table(tableData, {
|
|
33
33
|
drawHorizontalLine: (raw) => {
|
|
34
34
|
return !raw || raw === 1 || raw === files.length + 1;
|
|
35
35
|
},
|
|
@@ -46,9 +46,19 @@ export default (coverageFile) => {
|
|
|
46
46
|
joinJoin: '|',
|
|
47
47
|
bodyJoin: '|',
|
|
48
48
|
},
|
|
49
|
-
})
|
|
49
|
+
});
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
+
export function formatLines(array) {
|
|
53
|
+
const lines = array.slice(0, 10).join(', ');
|
|
54
|
+
|
|
55
|
+
if (array.length <= 10)
|
|
56
|
+
return lines;
|
|
57
|
+
|
|
58
|
+
const latest = array[array.length - 1];
|
|
59
|
+
return `${lines}..${latest}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
52
62
|
function parseUncoveredLines(lines) {
|
|
53
63
|
const uncoveredLines = [];
|
|
54
64
|
|
|
@@ -69,11 +79,12 @@ function parseCoverageFile(coverageFile) {
|
|
|
69
79
|
const uncoveredLines = parseUncoveredLines(lines);
|
|
70
80
|
|
|
71
81
|
const linesCount = keys(lines).length;
|
|
72
|
-
const
|
|
82
|
+
const uncoveredLinesCount = uncoveredLines.length;
|
|
83
|
+
const percentLines = getLinesPercent(linesCount, uncoveredLinesCount);
|
|
73
84
|
|
|
74
85
|
files.push({
|
|
75
86
|
filename,
|
|
76
|
-
covered: !
|
|
87
|
+
covered: !uncoveredLinesCount,
|
|
77
88
|
lines: uncoveredLines,
|
|
78
89
|
percentLines,
|
|
79
90
|
});
|
|
@@ -82,9 +93,9 @@ function parseCoverageFile(coverageFile) {
|
|
|
82
93
|
return files;
|
|
83
94
|
}
|
|
84
95
|
|
|
85
|
-
function
|
|
96
|
+
export function getLinesPercent(linesCount, uncoveredLinesCount) {
|
|
86
97
|
if (!linesCount)
|
|
87
98
|
return 100;
|
|
88
99
|
|
|
89
|
-
return 100 - Math.round(100 / linesCount *
|
|
100
|
+
return 100 - Math.round(100 / linesCount * uncoveredLinesCount);
|
|
90
101
|
}
|
package/lib/formatters/lines.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
const {entries} = Object;
|
|
3
3
|
|
|
4
|
+
const createOut = (output) => (a) => output.push(a);
|
|
4
5
|
export default (coverageFile) => {
|
|
6
|
+
const output = [];
|
|
7
|
+
const out = createOut(output);
|
|
5
8
|
const files = [];
|
|
6
9
|
const coverage = {
|
|
7
10
|
files,
|
|
@@ -9,8 +12,8 @@ export default (coverageFile) => {
|
|
|
9
12
|
uncoveredCount: 0,
|
|
10
13
|
};
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
out('# CAP version 13');
|
|
16
|
+
out('');
|
|
14
17
|
|
|
15
18
|
for (const {name, lines} of coverageFile) {
|
|
16
19
|
const uncoveredLines = [];
|
|
@@ -39,31 +42,33 @@ export default (coverageFile) => {
|
|
|
39
42
|
|
|
40
43
|
for (const {name, covered, uncoveredLines} of files) {
|
|
41
44
|
if (!covered) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
out(`# ${name}`);
|
|
46
|
+
out('🧨 should be covered');
|
|
47
|
+
out('---');
|
|
48
|
+
out(`lines:`);
|
|
46
49
|
for (const line of uncoveredLines) {
|
|
47
|
-
|
|
50
|
+
out(`️- ${chalk.red(line)} at file://${name}:${line}`);
|
|
48
51
|
}
|
|
49
|
-
|
|
52
|
+
out('');
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
out(`1..${files.length}`);
|
|
57
|
+
out(`# files: ${files.length}`);
|
|
58
|
+
out(`# covered: ${coverage.coveredCount}`);
|
|
56
59
|
|
|
57
|
-
|
|
60
|
+
out('');
|
|
58
61
|
|
|
59
62
|
if (!coverage.uncoveredCount) {
|
|
60
|
-
|
|
63
|
+
out('#️ 🌴 ok');
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
if (coverage.uncoveredCount) {
|
|
64
|
-
|
|
67
|
+
out(`# 🧨 fail: ${coverage.uncoveredCount}`);
|
|
65
68
|
}
|
|
66
69
|
|
|
67
|
-
|
|
70
|
+
out('');
|
|
71
|
+
|
|
72
|
+
return output.join('\n');
|
|
68
73
|
};
|
|
69
74
|
|
|
@@ -3,9 +3,11 @@ import {
|
|
|
3
3
|
types,
|
|
4
4
|
operator,
|
|
5
5
|
} from 'putout';
|
|
6
|
+
|
|
6
7
|
import {addMarkToReturn} from './return.js';
|
|
7
8
|
import {addMarkToArrowFunction} from './arrow.js';
|
|
8
9
|
import {addMarkToThrow} from './throw.js';
|
|
10
|
+
import {addMarkToContinue} from './continue.js';
|
|
9
11
|
|
|
10
12
|
const {
|
|
11
13
|
NumericLiteral,
|
|
@@ -16,6 +18,7 @@ const {
|
|
|
16
18
|
const {
|
|
17
19
|
replaceWith,
|
|
18
20
|
compareAny,
|
|
21
|
+
compare,
|
|
19
22
|
} = operator;
|
|
20
23
|
|
|
21
24
|
const LINE = `__c4['🧨'](__l, __c)`;
|
|
@@ -93,13 +96,15 @@ export const fix = (path, {options}) => {
|
|
|
93
96
|
if (path.isReturnStatement())
|
|
94
97
|
return addMarkToReturn(path, lineNode);
|
|
95
98
|
|
|
96
|
-
if (path.isArrowFunctionExpression())
|
|
99
|
+
if (path.isArrowFunctionExpression())
|
|
97
100
|
return addMarkToArrowFunction(path, lineNode);
|
|
98
|
-
}
|
|
99
101
|
|
|
100
102
|
if (path.isThrowStatement())
|
|
101
103
|
return addMarkToThrow(path, lineNode);
|
|
102
104
|
|
|
105
|
+
if (path.isContinueStatement())
|
|
106
|
+
return addMarkToContinue(path, lineNode);
|
|
107
|
+
|
|
103
108
|
replaceWith(path, BlockStatement([
|
|
104
109
|
node,
|
|
105
110
|
]));
|
|
@@ -135,6 +140,17 @@ export const traverse = ({push}) => ({
|
|
|
135
140
|
|
|
136
141
|
push(path);
|
|
137
142
|
},
|
|
143
|
+
ContinueStatement(path) {
|
|
144
|
+
if (!path.parentPath.isBlockStatement())
|
|
145
|
+
return;
|
|
146
|
+
|
|
147
|
+
const {body} = path.parentPath.node;
|
|
148
|
+
|
|
149
|
+
if (compare(body[0], LINE))
|
|
150
|
+
return;
|
|
151
|
+
|
|
152
|
+
push(path);
|
|
153
|
+
},
|
|
138
154
|
LogicalExpression(path) {
|
|
139
155
|
if (compareAny(path.get('left'), EXCLUDE))
|
|
140
156
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "escover",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.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",
|
|
@@ -19,11 +19,8 @@
|
|
|
19
19
|
"loader"
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
|
-
"loader": "madrun loader",
|
|
23
22
|
"test": "madrun test",
|
|
24
|
-
"test:only": "madrun test:only",
|
|
25
23
|
"coverage": "madrun coverage",
|
|
26
|
-
"c4": "madrun c4",
|
|
27
24
|
"lint": "madrun lint",
|
|
28
25
|
"fresh:lint": "madrun fresh:lint",
|
|
29
26
|
"lint:fresh": "madrun lint:fresh",
|
|
@@ -33,7 +30,7 @@
|
|
|
33
30
|
"watch:test": "madrun watch:test",
|
|
34
31
|
"watch:lint": "madrun watch:lint",
|
|
35
32
|
"watch:tape": "madrun watch:tape",
|
|
36
|
-
"
|
|
33
|
+
"prewisdom": "madrun prewisdom"
|
|
37
34
|
},
|
|
38
35
|
"dependencies": {
|
|
39
36
|
"chalk": "^5.0.0",
|
|
@@ -44,6 +41,7 @@
|
|
|
44
41
|
"once": "^1.4.0",
|
|
45
42
|
"picomatch": "^2.3.1",
|
|
46
43
|
"putout": "^24.0.2",
|
|
44
|
+
"strip-ansi": "^7.0.1",
|
|
47
45
|
"table": "^6.8.0",
|
|
48
46
|
"try-catch": "^3.0.0",
|
|
49
47
|
"yargs-parser": "^21.0.0",
|
package/example/example.js
DELETED