escover 1.9.0 โ 1.13.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 +27 -0
- package/README.md +14 -1
- package/bin/escover.js +4 -2
- package/lib/cli/cli.js +2 -2
- package/lib/coverage-file/coverage-file.js +49 -0
- package/lib/coverage-file/find-cache-dir.js +14 -0
- package/lib/coverage-file/lcov.js +52 -0
- package/lib/exit.js +2 -2
- package/lib/formatters/files.js +7 -6
- package/lib/instrument/plugin-mark/index.js +21 -2
- package/package.json +3 -1
- package/lib/coverage-file.js +0 -48
package/ChangeLog
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
2022.01.20, v1.13.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- escover: add ability to read lcov
|
|
5
|
+
- coverage-file: add ability to parse lcov
|
|
6
|
+
- escover: mark: add support of break
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
2022.01.19, v1.12.0
|
|
10
|
+
|
|
11
|
+
feature:
|
|
12
|
+
- escover: add lcov support
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
2022.01.19, v1.11.0
|
|
16
|
+
|
|
17
|
+
feature:
|
|
18
|
+
- escover: mark: add support of continue
|
|
19
|
+
- escover: coverage-file: read -> readCoverage
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
2022.01.19, v1.10.0
|
|
23
|
+
|
|
24
|
+
feature:
|
|
25
|
+
- escover: add .. when to many lines to display
|
|
26
|
+
|
|
27
|
+
|
|
1
28
|
2022.01.19, v1.9.0
|
|
2
29
|
|
|
3
30
|
feature:
|
package/README.md
CHANGED
|
@@ -31,7 +31,11 @@ which are needed to load module again, and apply mocks.
|
|
|
31
31
|
|
|
32
32
|
### ๐คทโ How to get coverage when mocks are used?
|
|
33
33
|
|
|
34
|
-
โ๏ธ Use
|
|
34
|
+
โ๏ธ Use ๐ฉ`ESCover`! It supports loaders, `ESM` and collects coverage as a loader!
|
|
35
|
+
|
|
36
|
+
### ๐คทโ What with [`coveralls`](https://coveralls.io/)? Does [`lcov`](https://github.com/StevenLooman/mocha-lcov-reporter) supported?
|
|
37
|
+
|
|
38
|
+
โ๏ธ Sure! `coverage/lcov.info` is main coverage file for ๐ฉ`ESCover`.
|
|
35
39
|
|
|
36
40
|
## Install
|
|
37
41
|
|
|
@@ -55,6 +59,15 @@ When everything is covered:
|
|
|
55
59
|
|
|
56
60
|

|
|
57
61
|
|
|
62
|
+
## What formatters exists?
|
|
63
|
+
|
|
64
|
+
There is two types of formatters:
|
|
65
|
+
|
|
66
|
+
- `lines` adds links to each line;
|
|
67
|
+
- `files` shows information in table;
|
|
68
|
+
|
|
69
|
+
You can choose formatter with `ESCOVER_FORMAT` env variable.
|
|
70
|
+
|
|
58
71
|
## What if I want to use ๐ฉ`ESCover` with `mock-import`?
|
|
59
72
|
|
|
60
73
|
Experimental `loaders` supports only one, for now. So [zenload](https://github.com/coderaiser/zenload) should be used.
|
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,7 +36,7 @@ export const cli = ({argv, exit, read}) => {
|
|
|
36
36
|
execute('"' + cmd.join(`" "`) + '"', exit);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const coverage =
|
|
39
|
+
const coverage = readCoverage();
|
|
40
40
|
|
|
41
41
|
let output = '';
|
|
42
42
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
writeFileSync,
|
|
3
|
+
readFileSync,
|
|
4
|
+
} from 'fs';
|
|
5
|
+
import tryCatch from 'try-catch';
|
|
6
|
+
import {join} from 'path';
|
|
7
|
+
import {getFileEntries} from '../c4.js';
|
|
8
|
+
import {transform} from '../transform.js';
|
|
9
|
+
import {merge} from '../merge.js';
|
|
10
|
+
import {findCacheDir} from './find-cache-dir.js';
|
|
11
|
+
import {
|
|
12
|
+
generateLcov,
|
|
13
|
+
parseLcov,
|
|
14
|
+
} from './lcov.js';
|
|
15
|
+
|
|
16
|
+
const NAME = 'escover';
|
|
17
|
+
const LCOV = 'lcov.info';
|
|
18
|
+
|
|
19
|
+
export const writeCoverage = () => {
|
|
20
|
+
const files = getFileEntries();
|
|
21
|
+
|
|
22
|
+
if (!files.size)
|
|
23
|
+
return;
|
|
24
|
+
|
|
25
|
+
const parsed = transform(files);
|
|
26
|
+
const merged = merge(parsed);
|
|
27
|
+
const lcov = generateLcov(merged);
|
|
28
|
+
|
|
29
|
+
const dir = findCacheDir({
|
|
30
|
+
name: NAME,
|
|
31
|
+
create: true,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
writeFileSync(join(dir, LCOV), lcov);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const readCoverage = () => {
|
|
38
|
+
const dir = findCacheDir({
|
|
39
|
+
name: NAME,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const [error, data] = tryCatch(readFileSync, join(dir, LCOV), 'utf8');
|
|
43
|
+
|
|
44
|
+
if (error)
|
|
45
|
+
return [];
|
|
46
|
+
|
|
47
|
+
return parseLcov(data);
|
|
48
|
+
};
|
|
49
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const {entries} = Object;
|
|
2
|
+
|
|
3
|
+
export const generateLcov = (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
|
+
};
|
|
18
|
+
|
|
19
|
+
const isEnd = (a) => a === 'end_of_record';
|
|
20
|
+
|
|
21
|
+
export const parseLcov = (lcov) => {
|
|
22
|
+
const files = [];
|
|
23
|
+
let name = '';
|
|
24
|
+
let lines = {};
|
|
25
|
+
|
|
26
|
+
for (const current of lcov.split('\n')) {
|
|
27
|
+
const [cmd, arg] = current.split(':');
|
|
28
|
+
|
|
29
|
+
if (cmd === 'SF') {
|
|
30
|
+
name = arg;
|
|
31
|
+
lines = {};
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (cmd === 'DA') {
|
|
36
|
+
const [line, covered] = arg.split(',');
|
|
37
|
+
lines[line] = Boolean(Number(covered));
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (isEnd(cmd)) {
|
|
42
|
+
files.push({
|
|
43
|
+
name,
|
|
44
|
+
lines,
|
|
45
|
+
});
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return files;
|
|
51
|
+
};
|
|
52
|
+
|
package/lib/exit.js
CHANGED
package/lib/formatters/files.js
CHANGED
|
@@ -50,13 +50,13 @@ export default (coverageFile) => {
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
export function formatLines(array) {
|
|
53
|
-
console.log(array);
|
|
54
53
|
const lines = array.slice(0, 10).join(', ');
|
|
55
54
|
|
|
56
55
|
if (array.length <= 10)
|
|
57
56
|
return lines;
|
|
58
57
|
|
|
59
|
-
|
|
58
|
+
const latest = array[array.length - 1];
|
|
59
|
+
return `${lines}..${latest}`;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
function parseUncoveredLines(lines) {
|
|
@@ -79,11 +79,12 @@ function parseCoverageFile(coverageFile) {
|
|
|
79
79
|
const uncoveredLines = parseUncoveredLines(lines);
|
|
80
80
|
|
|
81
81
|
const linesCount = keys(lines).length;
|
|
82
|
-
const
|
|
82
|
+
const uncoveredLinesCount = uncoveredLines.length;
|
|
83
|
+
const percentLines = getLinesPercent(linesCount, uncoveredLinesCount);
|
|
83
84
|
|
|
84
85
|
files.push({
|
|
85
86
|
filename,
|
|
86
|
-
covered: !
|
|
87
|
+
covered: !uncoveredLinesCount,
|
|
87
88
|
lines: uncoveredLines,
|
|
88
89
|
percentLines,
|
|
89
90
|
});
|
|
@@ -92,9 +93,9 @@ function parseCoverageFile(coverageFile) {
|
|
|
92
93
|
return files;
|
|
93
94
|
}
|
|
94
95
|
|
|
95
|
-
function
|
|
96
|
+
export function getLinesPercent(linesCount, uncoveredLinesCount) {
|
|
96
97
|
if (!linesCount)
|
|
97
98
|
return 100;
|
|
98
99
|
|
|
99
|
-
return 100 - Math.round(100 / linesCount *
|
|
100
|
+
return 100 - Math.round(100 / linesCount * uncoveredLinesCount);
|
|
100
101
|
}
|
|
@@ -3,6 +3,7 @@ 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';
|
|
@@ -16,6 +17,8 @@ const {
|
|
|
16
17
|
const {
|
|
17
18
|
replaceWith,
|
|
18
19
|
compareAny,
|
|
20
|
+
compare,
|
|
21
|
+
replaceWithMultiple,
|
|
19
22
|
} = operator;
|
|
20
23
|
|
|
21
24
|
const LINE = `__c4['๐งจ'](__l, __c)`;
|
|
@@ -93,13 +96,18 @@ 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() || path.isBreakStatement())
|
|
106
|
+
return replaceWithMultiple(path, [
|
|
107
|
+
lineNode,
|
|
108
|
+
path.node,
|
|
109
|
+
]);
|
|
110
|
+
|
|
103
111
|
replaceWith(path, BlockStatement([
|
|
104
112
|
node,
|
|
105
113
|
]));
|
|
@@ -135,6 +143,17 @@ export const traverse = ({push}) => ({
|
|
|
135
143
|
|
|
136
144
|
push(path);
|
|
137
145
|
},
|
|
146
|
+
'ContinueStatement|BreakStatement'(path) {
|
|
147
|
+
if (!path.parentPath.isBlockStatement())
|
|
148
|
+
return;
|
|
149
|
+
|
|
150
|
+
const {body} = path.parentPath.node;
|
|
151
|
+
|
|
152
|
+
if (compare(body[0], LINE))
|
|
153
|
+
return;
|
|
154
|
+
|
|
155
|
+
push(path);
|
|
156
|
+
},
|
|
138
157
|
LogicalExpression(path) {
|
|
139
158
|
if (compareAny(path.get('left'), EXCLUDE))
|
|
140
159
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "escover",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.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",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"fix:lint": "madrun fix:lint",
|
|
28
28
|
"report": "madrun report",
|
|
29
29
|
"watcher": "madrun watcher",
|
|
30
|
+
"watch:test": "madrun watch:test",
|
|
30
31
|
"watch:lint": "madrun watch:lint",
|
|
31
32
|
"watch:tape": "madrun watch:tape",
|
|
32
33
|
"prewisdom": "madrun prewisdom"
|
|
@@ -40,6 +41,7 @@
|
|
|
40
41
|
"once": "^1.4.0",
|
|
41
42
|
"picomatch": "^2.3.1",
|
|
42
43
|
"putout": "^24.0.2",
|
|
44
|
+
"strip-ansi": "^7.0.1",
|
|
43
45
|
"table": "^6.8.0",
|
|
44
46
|
"try-catch": "^3.0.0",
|
|
45
47
|
"yargs-parser": "^21.0.0",
|
package/lib/coverage-file.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import tryCatch from 'try-catch';
|
|
2
|
-
import {
|
|
3
|
-
writeFileSync,
|
|
4
|
-
readFileSync,
|
|
5
|
-
} from 'fs';
|
|
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';
|
|
10
|
-
|
|
11
|
-
const {
|
|
12
|
-
stringify,
|
|
13
|
-
parse,
|
|
14
|
-
} = JSON;
|
|
15
|
-
|
|
16
|
-
const NAME = 'escover';
|
|
17
|
-
const buildName = (a) => `${a}/${NAME}.json`;
|
|
18
|
-
|
|
19
|
-
export const write = () => {
|
|
20
|
-
const files = getFileEntries();
|
|
21
|
-
|
|
22
|
-
if (!files.size)
|
|
23
|
-
return;
|
|
24
|
-
|
|
25
|
-
const parsed = transform(files);
|
|
26
|
-
|
|
27
|
-
const merged = merge(parsed);
|
|
28
|
-
const name = findCacheDir({
|
|
29
|
-
name: NAME,
|
|
30
|
-
create: true,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
writeFileSync(buildName(name), stringify(merged, null, 4));
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const read = () => {
|
|
37
|
-
const name = findCacheDir({
|
|
38
|
-
name: NAME,
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const [error, data] = tryCatch(readFileSync, buildName(name), 'utf8');
|
|
42
|
-
|
|
43
|
-
if (error)
|
|
44
|
-
return [];
|
|
45
|
-
|
|
46
|
-
return parse(data);
|
|
47
|
-
};
|
|
48
|
-
|