escover 1.1.0 → 1.1.4
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 +25 -0
- package/README.md +45 -9
- package/lib/cli/cli.js +19 -24
- package/lib/config.js +6 -3
- package/package.json +4 -4
package/ChangeLog
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
2022.01.13, v1.1.4
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- (package) eslint-plugin-putout v13.0.1
|
|
5
|
+
- (package) putout v24.0.2
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
2022.01.11, v1.1.3
|
|
9
|
+
|
|
10
|
+
fix:
|
|
11
|
+
- escover: rm unused
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
2022.01.11, v1.1.2
|
|
15
|
+
|
|
16
|
+
fix:
|
|
17
|
+
- escover: get back running support
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
2022.01.11, v1.1.1
|
|
21
|
+
|
|
22
|
+
feature:
|
|
23
|
+
- escover: bin only shows report
|
|
24
|
+
|
|
25
|
+
|
|
1
26
|
2022.01.11, v1.1.0
|
|
2
27
|
|
|
3
28
|
feature:
|
package/README.md
CHANGED
|
@@ -9,26 +9,42 @@
|
|
|
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
|
-
Coverage for EcmaScript Modules based on 🐊[`Putout`](https://github.com/coderaiser/putout).
|
|
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
|
+
|
|
21
|
+
☝️ that's easy! 📼 [`Supertape`](https://github.com/coderaiser/supertape) supports `ESM` from the box;
|
|
22
|
+
|
|
23
|
+
### 🤷 How to mock modules without [mock-require](https://github.com/boblauer/mock-require) (we in `ESM`!);
|
|
24
|
+
|
|
25
|
+
☝️ that's solved! [`mock-import`](https://github.com/coderaiser/mock-import) does the thing using `loaders`;
|
|
26
|
+
|
|
27
|
+
### 🤷 How to get coverage when `nyc` doesn't supported?
|
|
28
|
+
|
|
29
|
+
☝️ `c8` could help, but [no](https://github.com/coderaiser/c8-reproduce) it supports no `query paramters`
|
|
30
|
+
which are needed to load module again, and apply mocks.
|
|
31
|
+
|
|
32
|
+
### 🤷 How to get coverage when mocks are used?
|
|
33
|
+
|
|
34
|
+
☝️ Use 🎩 `ESCover`! It supports loaders, `ESM` and collects coverage as a loader!
|
|
13
35
|
|
|
14
36
|
## Install
|
|
15
37
|
|
|
16
38
|
```
|
|
17
|
-
npm i escover -
|
|
39
|
+
npm i escover -D
|
|
18
40
|
```
|
|
19
41
|
|
|
20
|
-
|
|
42
|
+
Run to collect and show coverage:
|
|
21
43
|
|
|
22
44
|
```sh
|
|
23
45
|
escover npm test
|
|
24
46
|
```
|
|
25
47
|
|
|
26
|
-
Or as [loader](https://nodejs.org/dist/latest-v16.x/docs/api/esm.html#loaders):
|
|
27
|
-
|
|
28
|
-
```sh
|
|
29
|
-
NODE_OPTIONS="'--loader escover'" escover npm test
|
|
30
|
-
```
|
|
31
|
-
|
|
32
48
|
## How it looks like?
|
|
33
49
|
|
|
34
50
|
When everything is covered:
|
|
@@ -39,6 +55,26 @@ When some lines missing coverage:
|
|
|
39
55
|
|
|
40
56
|

|
|
41
57
|
|
|
58
|
+
## What if I want to use 🎩`ESCover` with `mock-import`?
|
|
59
|
+
|
|
60
|
+
Experimental `loaders` supports only one, for now. So [zenload](https://github.com/coderaiser/zenload) should be used.
|
|
61
|
+
|
|
62
|
+
Install it with:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
npm i escover mock-import zenload
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Then run:
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
NODE_OPTIONS="'--loader zenlend'" ZENLOAD='escover,mock-import' escover npm test
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
This configuration will add coverage collectors and then apply mocks with help of `mock-import`.
|
|
75
|
+
Of course the most comfortable way of doing this things will be [madrun](https://github.com/coderaiser/madrun).
|
|
76
|
+
Run you `package-scripts` in `JavaScript` :)!
|
|
77
|
+
|
|
42
78
|
## License
|
|
43
79
|
|
|
44
80
|
MIT
|
package/lib/cli/cli.js
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {execSync} from 'child_process';
|
|
2
|
+
import tryCatch from 'try-catch';
|
|
2
3
|
import yargsParser from 'yargs-parser';
|
|
3
|
-
import _foreground from 'foreground-child';
|
|
4
4
|
|
|
5
5
|
import {version} from './version.js';
|
|
6
6
|
import {report} from '../report.js';
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
_foreground(cmd, () => {
|
|
10
|
-
fn();
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
process.env.ZENLOAD = 'escover,mock-import';
|
|
15
|
-
|
|
16
|
-
export const cli = async ({argv, exit, read}) => {
|
|
8
|
+
export const cli = ({argv, exit, read}) => {
|
|
17
9
|
const args = yargsParser(argv.slice(2), {
|
|
18
10
|
boolean: [
|
|
19
11
|
'version',
|
|
@@ -29,26 +21,29 @@ export const cli = async ({argv, exit, read}) => {
|
|
|
29
21
|
return exit();
|
|
30
22
|
}
|
|
31
23
|
|
|
32
|
-
const cmd =
|
|
24
|
+
const cmd = argv.slice(2);
|
|
33
25
|
|
|
34
|
-
if (
|
|
35
|
-
|
|
26
|
+
if (cmd.length) {
|
|
27
|
+
execute('"' + cmd.join(`" "`) + '"', exit);
|
|
28
|
+
}
|
|
36
29
|
|
|
37
|
-
await foreground(cmd);
|
|
38
30
|
const coverage = read();
|
|
39
31
|
|
|
40
32
|
report(coverage);
|
|
41
33
|
};
|
|
42
34
|
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
function execute(cmd, exit) {
|
|
36
|
+
const [error] = tryCatch(execSync, cmd, {
|
|
37
|
+
stdio: [0, 1, 2],
|
|
38
|
+
env: {
|
|
39
|
+
...process.env,
|
|
40
|
+
NODE_OPTIONS: '--no-warnings --loader zenload',
|
|
41
|
+
ZENLOAD: 'escover,mock-import',
|
|
42
|
+
},
|
|
43
|
+
});
|
|
47
44
|
|
|
48
|
-
if (
|
|
49
|
-
|
|
45
|
+
if (error) {
|
|
46
|
+
console.error(error.message);
|
|
47
|
+
return exit(1);
|
|
50
48
|
}
|
|
51
|
-
|
|
52
|
-
return argv;
|
|
53
49
|
}
|
|
54
|
-
|
package/lib/config.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import tryCatch from 'try-catch';
|
|
1
2
|
import {
|
|
2
3
|
writeFileSync,
|
|
3
4
|
readFileSync,
|
|
@@ -32,9 +33,11 @@ export const read = () => {
|
|
|
32
33
|
name: NAME,
|
|
33
34
|
});
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
const [error, data] = tryCatch(readFileSync, buildName(name), 'utf8');
|
|
37
|
+
|
|
38
|
+
if (error)
|
|
39
|
+
return [];
|
|
37
40
|
|
|
38
|
-
const data = readFileSync(buildName(name), 'utf8');
|
|
39
41
|
return parse(data);
|
|
40
42
|
};
|
|
43
|
+
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "escover",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
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",
|
|
8
9
|
"bin": {
|
|
9
10
|
"escover": "bin/escover.js"
|
|
10
11
|
},
|
|
@@ -38,10 +39,9 @@
|
|
|
38
39
|
"chalk": "^5.0.0",
|
|
39
40
|
"find-cache-dir": "^3.3.2",
|
|
40
41
|
"find-up": "^6.2.0",
|
|
41
|
-
"foreground-child": "^2.0.0",
|
|
42
42
|
"montag": "^1.2.1",
|
|
43
43
|
"once": "^1.4.0",
|
|
44
|
-
"putout": "^
|
|
44
|
+
"putout": "^24.0.2",
|
|
45
45
|
"try-catch": "^3.0.0",
|
|
46
46
|
"yargs-parser": "^21.0.0"
|
|
47
47
|
},
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"escover": ".",
|
|
56
56
|
"eslint": "^8.3.0",
|
|
57
57
|
"eslint-plugin-node": "^11.1.0",
|
|
58
|
-
"eslint-plugin-putout": "^
|
|
58
|
+
"eslint-plugin-putout": "^13.0.1",
|
|
59
59
|
"madrun": "^8.8.1",
|
|
60
60
|
"mock-import": "^2.0.0",
|
|
61
61
|
"supertape": "^6.0.5",
|