escover 1.6.0 → 1.8.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 +5 -5
- package/lib/config.js +42 -0
- package/lib/escover.js +13 -7
- package/lib/transform.js +20 -7
- package/package.json +2 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
2022.01.19, v1.8.0
|
|
2
|
+
|
|
3
|
+
fix:
|
|
4
|
+
- chore: instrument: rm useless fixture
|
|
5
|
+
|
|
6
|
+
feature:
|
|
7
|
+
- escover: when one of expressions lin line not covered - line not covered
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
2022.01.18, v1.7.2
|
|
11
|
+
|
|
12
|
+
feature:
|
|
13
|
+
- escover: config: isExclude: add ability to drop stars
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
2022.01.17, v1.7.1
|
|
17
|
+
|
|
18
|
+
fix:
|
|
19
|
+
- escover: config: rm once
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
2022.01.17, v1.7.0
|
|
23
|
+
|
|
24
|
+
feature:
|
|
25
|
+
- escover: add ability to read config
|
|
26
|
+
|
|
27
|
+
|
|
1
28
|
2022.01.17, v1.6.0
|
|
2
29
|
|
|
3
30
|
feature:
|
package/README.md
CHANGED
|
@@ -45,15 +45,15 @@ Run to collect and show coverage:
|
|
|
45
45
|
escover npm test
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
##
|
|
48
|
+
## Config
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
`exclude` section of configuration file `.nyrc.json` supported.
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
## How it looks like?
|
|
53
53
|
|
|
54
|
-
When
|
|
54
|
+
When everything is covered:
|
|
55
55
|
|
|
56
|
-

|
|
57
57
|
|
|
58
58
|
## What if I want to use 🎩`ESCover` with `mock-import`?
|
|
59
59
|
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {readFileSync} from 'fs';
|
|
2
|
+
import picomatch from 'picomatch';
|
|
3
|
+
import {findUpSync} from 'find-up';
|
|
4
|
+
|
|
5
|
+
const {parse} = JSON;
|
|
6
|
+
|
|
7
|
+
const addStars = (patterns) => {
|
|
8
|
+
const result = [];
|
|
9
|
+
for (const pattern of patterns) {
|
|
10
|
+
result.push(...[
|
|
11
|
+
`**/${pattern}/**`,
|
|
12
|
+
pattern,
|
|
13
|
+
]);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const isExclude = (name, patterns) => {
|
|
20
|
+
const isMatch = picomatch(addStars(patterns), {
|
|
21
|
+
dot: true,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return isMatch(name);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const defaults = {
|
|
28
|
+
exclude: [],
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const readConfig = () => {
|
|
32
|
+
const name = findUpSync('.nycrc.json');
|
|
33
|
+
|
|
34
|
+
if (!name)
|
|
35
|
+
return defaults;
|
|
36
|
+
|
|
37
|
+
const data = readFileSync(name, 'utf8');
|
|
38
|
+
return {
|
|
39
|
+
...defaults,
|
|
40
|
+
...parse(data),
|
|
41
|
+
};
|
|
42
|
+
};
|
package/lib/escover.js
CHANGED
|
@@ -2,21 +2,27 @@ import montag from 'montag';
|
|
|
2
2
|
import process from 'process';
|
|
3
3
|
|
|
4
4
|
import {instrument} from './instrument/index.js';
|
|
5
|
-
import {exclude} from './exclude.js';
|
|
6
5
|
import {exit} from './exit.js';
|
|
7
6
|
import {createFileEntry} from './c4.js';
|
|
7
|
+
import {
|
|
8
|
+
readConfig,
|
|
9
|
+
isExclude,
|
|
10
|
+
} from './config.js';
|
|
8
11
|
|
|
9
12
|
global.__createC4 = createFileEntry;
|
|
10
13
|
|
|
11
14
|
process.once('exit', exit);
|
|
12
15
|
const CWD = process.cwd();
|
|
13
16
|
|
|
17
|
+
const {exclude} = readConfig();
|
|
18
|
+
|
|
14
19
|
const EXCLUDE = [
|
|
15
|
-
'
|
|
16
|
-
'node_modules',
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
+
'**/*.spec.*',
|
|
21
|
+
'**/node_modules/**',
|
|
22
|
+
'**/fixture/**',
|
|
23
|
+
'**/.madrun.*',
|
|
24
|
+
'**/test/**',
|
|
25
|
+
...exclude,
|
|
20
26
|
];
|
|
21
27
|
|
|
22
28
|
export async function load(url, context, defaultLoad) {
|
|
@@ -33,7 +39,7 @@ export async function load(url, context, defaultLoad) {
|
|
|
33
39
|
source: rawSource,
|
|
34
40
|
};
|
|
35
41
|
|
|
36
|
-
if (
|
|
42
|
+
if (isExclude(url, EXCLUDE))
|
|
37
43
|
return {
|
|
38
44
|
format,
|
|
39
45
|
source: rawSource,
|
package/lib/transform.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
const sort = (a) => new Map(Array.from(a.entries()).sort());
|
|
2
2
|
|
|
3
|
+
const isBool = (a) => typeof a === 'boolean';
|
|
4
|
+
|
|
3
5
|
export const transform = (files) => {
|
|
4
6
|
const result = [];
|
|
5
7
|
const sorted = sort(files);
|
|
6
8
|
|
|
7
9
|
for (const [rawName, places] of sorted.entries()) {
|
|
8
|
-
const rawLines =
|
|
9
|
-
|
|
10
|
-
for (const [place, covered] of places.entries()) {
|
|
11
|
-
const [line] = place.split(':');
|
|
12
|
-
|
|
13
|
-
rawLines[line] = covered;
|
|
14
|
-
}
|
|
10
|
+
const rawLines = mergeLines(places);
|
|
15
11
|
|
|
16
12
|
result.push({
|
|
17
13
|
rawName,
|
|
@@ -22,3 +18,20 @@ export const transform = (files) => {
|
|
|
22
18
|
return result;
|
|
23
19
|
};
|
|
24
20
|
|
|
21
|
+
function mergeLines(places) {
|
|
22
|
+
const result = {};
|
|
23
|
+
|
|
24
|
+
for (const [place, covered] of places.entries()) {
|
|
25
|
+
const [line] = place.split(':');
|
|
26
|
+
|
|
27
|
+
if (isBool(result[line])) {
|
|
28
|
+
result[line] &= covered;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
result[line] = covered;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "escover",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.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",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"mock-import": "^2.11.1",
|
|
43
43
|
"montag": "^1.2.1",
|
|
44
44
|
"once": "^1.4.0",
|
|
45
|
+
"picomatch": "^2.3.1",
|
|
45
46
|
"putout": "^24.0.2",
|
|
46
47
|
"table": "^6.8.0",
|
|
47
48
|
"try-catch": "^3.0.0",
|