escover 1.12.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
CHANGED
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.
|
|
@@ -8,15 +8,13 @@ import {getFileEntries} from '../c4.js';
|
|
|
8
8
|
import {transform} from '../transform.js';
|
|
9
9
|
import {merge} from '../merge.js';
|
|
10
10
|
import {findCacheDir} from './find-cache-dir.js';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
parse,
|
|
16
|
-
} = JSON;
|
|
11
|
+
import {
|
|
12
|
+
generateLcov,
|
|
13
|
+
parseLcov,
|
|
14
|
+
} from './lcov.js';
|
|
17
15
|
|
|
18
16
|
const NAME = 'escover';
|
|
19
|
-
const
|
|
17
|
+
const LCOV = 'lcov.info';
|
|
20
18
|
|
|
21
19
|
export const writeCoverage = () => {
|
|
22
20
|
const files = getFileEntries();
|
|
@@ -26,27 +24,26 @@ export const writeCoverage = () => {
|
|
|
26
24
|
|
|
27
25
|
const parsed = transform(files);
|
|
28
26
|
const merged = merge(parsed);
|
|
29
|
-
const lcov =
|
|
27
|
+
const lcov = generateLcov(merged);
|
|
30
28
|
|
|
31
29
|
const dir = findCacheDir({
|
|
32
30
|
name: NAME,
|
|
33
31
|
create: true,
|
|
34
32
|
});
|
|
35
33
|
|
|
36
|
-
writeFileSync(join(dir,
|
|
37
|
-
writeFileSync(buildName(dir), stringify(merged, null, 4));
|
|
34
|
+
writeFileSync(join(dir, LCOV), lcov);
|
|
38
35
|
};
|
|
39
36
|
|
|
40
37
|
export const readCoverage = () => {
|
|
41
|
-
const
|
|
38
|
+
const dir = findCacheDir({
|
|
42
39
|
name: NAME,
|
|
43
40
|
});
|
|
44
41
|
|
|
45
|
-
const [error, data] = tryCatch(readFileSync,
|
|
42
|
+
const [error, data] = tryCatch(readFileSync, join(dir, LCOV), 'utf8');
|
|
46
43
|
|
|
47
44
|
if (error)
|
|
48
45
|
return [];
|
|
49
46
|
|
|
50
|
-
return
|
|
47
|
+
return parseLcov(data);
|
|
51
48
|
};
|
|
52
49
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const {entries} = Object;
|
|
2
2
|
|
|
3
|
-
export const
|
|
3
|
+
export const generateLcov = (files) => {
|
|
4
4
|
const result = [];
|
|
5
5
|
|
|
6
6
|
for (const {name, lines} of files) {
|
|
@@ -9,9 +9,44 @@ export const createLcov = (files) => {
|
|
|
9
9
|
const count = covered ? 1 : 0;
|
|
10
10
|
result.push(`DA:${line},${count}`);
|
|
11
11
|
}
|
|
12
|
+
|
|
13
|
+
result.push('end_of_record');
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
result.push('end_of_record');
|
|
15
|
-
|
|
16
16
|
return result.join('\n');
|
|
17
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
|
+
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
import {addMarkToReturn} from './return.js';
|
|
8
8
|
import {addMarkToArrowFunction} from './arrow.js';
|
|
9
9
|
import {addMarkToThrow} from './throw.js';
|
|
10
|
-
import {addMarkToContinue} from './continue.js';
|
|
11
10
|
|
|
12
11
|
const {
|
|
13
12
|
NumericLiteral,
|
|
@@ -19,6 +18,7 @@ const {
|
|
|
19
18
|
replaceWith,
|
|
20
19
|
compareAny,
|
|
21
20
|
compare,
|
|
21
|
+
replaceWithMultiple,
|
|
22
22
|
} = operator;
|
|
23
23
|
|
|
24
24
|
const LINE = `__c4['๐งจ'](__l, __c)`;
|
|
@@ -102,8 +102,11 @@ export const fix = (path, {options}) => {
|
|
|
102
102
|
if (path.isThrowStatement())
|
|
103
103
|
return addMarkToThrow(path, lineNode);
|
|
104
104
|
|
|
105
|
-
if (path.isContinueStatement())
|
|
106
|
-
return
|
|
105
|
+
if (path.isContinueStatement() || path.isBreakStatement())
|
|
106
|
+
return replaceWithMultiple(path, [
|
|
107
|
+
lineNode,
|
|
108
|
+
path.node,
|
|
109
|
+
]);
|
|
107
110
|
|
|
108
111
|
replaceWith(path, BlockStatement([
|
|
109
112
|
node,
|
|
@@ -140,7 +143,7 @@ export const traverse = ({push}) => ({
|
|
|
140
143
|
|
|
141
144
|
push(path);
|
|
142
145
|
},
|
|
143
|
-
ContinueStatement(path) {
|
|
146
|
+
'ContinueStatement|BreakStatement'(path) {
|
|
144
147
|
if (!path.parentPath.isBlockStatement())
|
|
145
148
|
return;
|
|
146
149
|
|
package/package.json
CHANGED