escover 1.0.4 โ 1.1.2
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/README.md +42 -4
- package/bin/escover.js +11 -0
- package/lib/cli/cli.js +62 -0
- package/lib/cli/version.js +12 -0
- package/lib/config.js +43 -0
- package/lib/escover.js +2 -2
- package/lib/exit.js +2 -5
- package/lib/instrument/plugin-mark/index.js +2 -1
- package/lib/report.js +11 -12
- package/lib/{parse.js โ transform.js} +1 -1
- package/package.json +14 -2
- package/c4.json +0 -15
- package/coverage.json +0 -1
- package/lib/save.js +0 -14
package/ChangeLog
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
2022.01.11, v1.1.2
|
|
2
|
+
|
|
3
|
+
fix:
|
|
4
|
+
- escover: get back running support
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
2022.01.11, v1.1.1
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- escover: bin only shows report
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
2022.01.11, v1.1.0
|
|
14
|
+
|
|
15
|
+
feature:
|
|
16
|
+
- (escover) add bin
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
2022.01.08, v1.0.5
|
|
20
|
+
|
|
21
|
+
feature:
|
|
22
|
+
- escover: report
|
|
23
|
+
|
|
24
|
+
|
|
1
25
|
2022.01.08, v1.0.4
|
|
2
26
|
|
|
3
27
|
feature:
|
package/README.md
CHANGED
|
@@ -9,18 +9,36 @@
|
|
|
9
9
|
[CoverageURL]: https://coveralls.io/github/coderaiser/escover?branch=master
|
|
10
10
|
[CoverageIMGURL]: https://coveralls.io/repos/coderaiser/escover/badge.svg?branch=master&service=github
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Coverage for EcmaScript Modules based on ๐[`Putout`](https://github.com/coderaiser/putout) and [loaders](https://nodejs.org/dist/latest-v16.x/docs/api/esm.html#loaders).
|
|
13
|
+
|
|
14
|
+
## Why another coverage tool?
|
|
15
|
+
|
|
16
|
+
When you want to use `ESM` in `Node.js` without transpiling to `CommonJS` (that's what `jest`, `ava`, `tap` does),
|
|
17
|
+
you have a couple problems to solve.
|
|
18
|
+
|
|
19
|
+
### ๐คทโ What test runner does no transpiling to `CommonJS`?
|
|
20
|
+
โ๏ธ that's easy! ๐ผ [`Supertape`](https://github.com/coderaiser/supertape) supports `ESM` from the box;
|
|
21
|
+
|
|
22
|
+
### ๐คทโ How to mock modules without [mock-require](https://github.com/boblauer/mock-require) (we in `ESM`!);
|
|
23
|
+
โ๏ธ that's solved! [`mock-import`](https://github.com/coderaiser/mock-import) does the thing using `loaders`;
|
|
24
|
+
|
|
25
|
+
### ๐คทโ How to get coverage when `nyc` doesn't supported?
|
|
26
|
+
โ๏ธ `c8` could help, but [no](https://github.com/coderaiser/c8-reproduce) it supports no `query paramters`
|
|
27
|
+
which are needed to load module again, and apply mocks.
|
|
28
|
+
|
|
29
|
+
### ๐คทโ How to get coverage when mocks are used?
|
|
30
|
+
โ๏ธ Use ๐ฉ `ESCover`! It supports loaders, `ESM` and collects coverage as a loader!
|
|
13
31
|
|
|
14
32
|
## Install
|
|
15
33
|
|
|
16
34
|
```
|
|
17
|
-
npm i escover -
|
|
35
|
+
npm i escover -D
|
|
18
36
|
```
|
|
19
37
|
|
|
20
|
-
|
|
38
|
+
Run to collect and show coverage:
|
|
21
39
|
|
|
22
40
|
```sh
|
|
23
|
-
|
|
41
|
+
escover npm test
|
|
24
42
|
```
|
|
25
43
|
|
|
26
44
|
## How it looks like?
|
|
@@ -33,6 +51,26 @@ When some lines missing coverage:
|
|
|
33
51
|
|
|
34
52
|

|
|
35
53
|
|
|
54
|
+
## What if I want to use ๐ฉ`ESCover` with `mock-import`?
|
|
55
|
+
|
|
56
|
+
Experimental `loaders` supports only one, for now. So [zenload](https://github.com/coderaiser/zenload) should be used.
|
|
57
|
+
|
|
58
|
+
Install it with:
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
npm i escover mock-import zenload
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Then run:
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
NODE_OPTIONS="'--loader zenlend'" ZENLOAD='escover,mock-import' escover npm test
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
This configuration will add coverage collectors and then apply mocks with help of `mock-import`.
|
|
71
|
+
Of course the most comfortable way of doing this things will be [madrun](https://github.com/coderaiser/madrun).
|
|
72
|
+
Run you `package-scripts` in `JavaScript` :)!
|
|
73
|
+
|
|
36
74
|
## License
|
|
37
75
|
|
|
38
76
|
MIT
|
package/bin/escover.js
ADDED
package/lib/cli/cli.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
execSync,
|
|
3
|
+
spawnSync,
|
|
4
|
+
} from 'child_process';
|
|
5
|
+
import {promisify} from 'util';
|
|
6
|
+
import tryCatch from 'try-catch';
|
|
7
|
+
import yargsParser from 'yargs-parser';
|
|
8
|
+
import _foreground from 'foreground-child';
|
|
9
|
+
|
|
10
|
+
import {version} from './version.js';
|
|
11
|
+
import {report} from '../report.js';
|
|
12
|
+
|
|
13
|
+
const foreground = promisify((cmd, fn) => {
|
|
14
|
+
_foreground(cmd, (done) => {
|
|
15
|
+
fn();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
process.env.ZENLOAD = 'escover,mock-import';
|
|
20
|
+
|
|
21
|
+
export const cli = ({argv, exit, read}) => {
|
|
22
|
+
const args = yargsParser(argv.slice(2), {
|
|
23
|
+
boolean: [
|
|
24
|
+
'version',
|
|
25
|
+
],
|
|
26
|
+
alias: {
|
|
27
|
+
v: 'version',
|
|
28
|
+
},
|
|
29
|
+
configuration: {},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (args.version) {
|
|
33
|
+
console.log(`v${version()}`);
|
|
34
|
+
return exit();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const cmd = argv.slice(2);
|
|
38
|
+
|
|
39
|
+
if (cmd.length) {
|
|
40
|
+
execute('"' + cmd.join(`" "`) + '"', exit);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const coverage = read();
|
|
44
|
+
|
|
45
|
+
report(coverage);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
function execute(cmd, exit) {
|
|
49
|
+
const [error] = tryCatch(execSync, cmd, {
|
|
50
|
+
stdio: [0, 1, 2],
|
|
51
|
+
env: {
|
|
52
|
+
...process.env,
|
|
53
|
+
NODE_OPTIONS: '--no-warnings --loader zenload',
|
|
54
|
+
ZENLOAD: 'escover,mock-import',
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
if (error) {
|
|
59
|
+
console.error(error.message);
|
|
60
|
+
return exit(1);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {readFileSync} from 'fs';
|
|
2
|
+
const {parse} = JSON;
|
|
3
|
+
|
|
4
|
+
const packageJson = new URL('../../package.json', import.meta.url);
|
|
5
|
+
|
|
6
|
+
export const version = () => {
|
|
7
|
+
const data = readFileSync(packageJson, 'utf8');
|
|
8
|
+
const {version} = parse(data);
|
|
9
|
+
|
|
10
|
+
return version;
|
|
11
|
+
};
|
|
12
|
+
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import tryCatch from 'try-catch';
|
|
2
|
+
import {
|
|
3
|
+
writeFileSync,
|
|
4
|
+
readFileSync,
|
|
5
|
+
} from 'fs';
|
|
6
|
+
import {getFiles} 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 = getFiles();
|
|
21
|
+
const parsed = transform(files);
|
|
22
|
+
const merged = merge(parsed);
|
|
23
|
+
const name = findCacheDir({
|
|
24
|
+
name: NAME,
|
|
25
|
+
create: true,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
writeFileSync(buildName(name), stringify(merged, null, 4));
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const read = () => {
|
|
32
|
+
const name = findCacheDir({
|
|
33
|
+
name: NAME,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const [error, data] = tryCatch(readFileSync, buildName(name), 'utf8');
|
|
37
|
+
|
|
38
|
+
if (error)
|
|
39
|
+
return [];
|
|
40
|
+
|
|
41
|
+
return parse(data);
|
|
42
|
+
};
|
|
43
|
+
|
package/lib/escover.js
CHANGED
|
@@ -8,6 +8,8 @@ import {createFileEntry} from './c4.js';
|
|
|
8
8
|
|
|
9
9
|
global.__createC4 = createFileEntry;
|
|
10
10
|
|
|
11
|
+
process.once('exit', exit);
|
|
12
|
+
|
|
11
13
|
export async function load(url, context, defaultLoad) {
|
|
12
14
|
const {format, source: rawSource} = await defaultLoad(url, context, defaultLoad);
|
|
13
15
|
|
|
@@ -33,5 +35,3 @@ export async function load(url, context, defaultLoad) {
|
|
|
33
35
|
};
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
process.once('exit', exit);
|
|
37
|
-
|
package/lib/exit.js
CHANGED
|
@@ -99,8 +99,9 @@ export const fix = (path, {options}) => {
|
|
|
99
99
|
if (path.isReturnStatement())
|
|
100
100
|
return addMarkToReturn(path, lineNode);
|
|
101
101
|
|
|
102
|
-
if (path.isArrowFunctionExpression())
|
|
102
|
+
if (path.isArrowFunctionExpression()) {
|
|
103
103
|
return addMarkToArrowFunction(path, lineNode);
|
|
104
|
+
}
|
|
104
105
|
|
|
105
106
|
if (path.isThrowStatement())
|
|
106
107
|
return addMarkToThrow(path, lineNode);
|
package/lib/report.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import {readFileSync} from 'fs';
|
|
3
|
-
|
|
4
|
-
const {parse} = JSON;
|
|
5
2
|
const {entries} = Object;
|
|
6
3
|
|
|
7
|
-
export const report = () => {
|
|
8
|
-
const coverageFile = parse(readFileSync('./coverage.json', 'utf8'));
|
|
9
|
-
|
|
4
|
+
export const report = (coverageFile) => {
|
|
10
5
|
const files = [];
|
|
11
6
|
const coverage = {
|
|
12
7
|
files,
|
|
@@ -47,24 +42,28 @@ export const report = () => {
|
|
|
47
42
|
console.log(`# ${name}`);
|
|
48
43
|
console.log('๐งจ should be covered');
|
|
49
44
|
console.log('---');
|
|
50
|
-
console.log(`lines
|
|
45
|
+
console.log(`lines:`);
|
|
46
|
+
for (const line of uncoveredLines) {
|
|
47
|
+
console.log(`๏ธ- ${chalk.red(line)} at file://${name}:${line}`);
|
|
48
|
+
}
|
|
49
|
+
console.log('');
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
if (coverage.uncoveredCount)
|
|
55
|
-
console.log('');
|
|
56
|
-
|
|
57
53
|
console.log(`1..${files.length}`);
|
|
58
54
|
console.log(`# files: ${files.length}`);
|
|
59
55
|
console.log(`# covered: ${coverage.coveredCount}`);
|
|
60
56
|
|
|
57
|
+
console.log('');
|
|
58
|
+
|
|
61
59
|
if (!coverage.uncoveredCount) {
|
|
62
|
-
console.log('');
|
|
63
|
-
console.log('# โ๏ธ ok');
|
|
60
|
+
console.log('#๏ธ ๐ด ok');
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
if (coverage.uncoveredCount) {
|
|
67
64
|
console.log(`# ๐งจ fail: ${coverage.uncoveredCount}`);
|
|
68
65
|
}
|
|
66
|
+
|
|
67
|
+
console.log('');
|
|
69
68
|
};
|
|
70
69
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "escover",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.2",
|
|
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",
|
|
7
7
|
"type": "module",
|
|
8
|
+
"commitType": "colon",
|
|
9
|
+
"bin": {
|
|
10
|
+
"escover": "bin/escover.js"
|
|
11
|
+
},
|
|
8
12
|
"repository": {
|
|
9
13
|
"type": "git",
|
|
10
14
|
"url": "git://github.com/coderaiser/escover.git"
|
|
@@ -15,8 +19,11 @@
|
|
|
15
19
|
"loader"
|
|
16
20
|
],
|
|
17
21
|
"scripts": {
|
|
22
|
+
"loader": "madrun loader",
|
|
18
23
|
"test": "madrun test",
|
|
24
|
+
"test:only": "madrun test:only",
|
|
19
25
|
"coverage": "madrun coverage",
|
|
26
|
+
"c4": "madrun c4",
|
|
20
27
|
"lint": "madrun lint",
|
|
21
28
|
"fresh:lint": "madrun fresh:lint",
|
|
22
29
|
"lint:fresh": "madrun lint:fresh",
|
|
@@ -30,9 +37,13 @@
|
|
|
30
37
|
},
|
|
31
38
|
"dependencies": {
|
|
32
39
|
"chalk": "^5.0.0",
|
|
40
|
+
"find-cache-dir": "^3.3.2",
|
|
41
|
+
"find-up": "^6.2.0",
|
|
33
42
|
"montag": "^1.2.1",
|
|
34
43
|
"once": "^1.4.0",
|
|
35
|
-
"putout": "^23.5.0"
|
|
44
|
+
"putout": "^23.5.0",
|
|
45
|
+
"try-catch": "^3.0.0",
|
|
46
|
+
"yargs-parser": "^21.0.0"
|
|
36
47
|
},
|
|
37
48
|
"engines": {
|
|
38
49
|
"node": ">=14"
|
|
@@ -41,6 +52,7 @@
|
|
|
41
52
|
"devDependencies": {
|
|
42
53
|
"@putout/test": "^4.1.0",
|
|
43
54
|
"c8": "^7.8.0",
|
|
55
|
+
"escover": ".",
|
|
44
56
|
"eslint": "^8.3.0",
|
|
45
57
|
"eslint-plugin-node": "^11.1.0",
|
|
46
58
|
"eslint-plugin-putout": "^12.2.0",
|
package/c4.json
DELETED
package/coverage.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
[]
|
package/lib/save.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {writeFileSync} from 'fs';
|
|
2
|
-
import {getFiles} from './c4.js';
|
|
3
|
-
import {parse} from './parse.js';
|
|
4
|
-
import {merge} from './merge.js';
|
|
5
|
-
|
|
6
|
-
const {stringify} = JSON;
|
|
7
|
-
|
|
8
|
-
export const save = () => {
|
|
9
|
-
const files = getFiles();
|
|
10
|
-
const parsed = parse(files);
|
|
11
|
-
const merged = merge(parsed);
|
|
12
|
-
|
|
13
|
-
writeFileSync('./coverage.json', stringify(merged, null, 4));
|
|
14
|
-
};
|