escover 1.1.0 → 1.1.1

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
@@ -1,3 +1,9 @@
1
+ 2022.01.11, v1.1.1
2
+
3
+ feature:
4
+ - escover: bin only shows report
5
+
6
+
1
7
  2022.01.11, v1.1.0
2
8
 
3
9
  feature:
package/README.md CHANGED
@@ -9,24 +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
+ ☝️ 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 -g
35
+ npm i escover -D
18
36
  ```
19
37
 
20
- Then run using:
38
+ Run to collect coverage:
21
39
 
22
40
  ```sh
23
- escover npm test
41
+ NODE_OPTIONS="'--loader escover'" escover npm test
24
42
  ```
25
43
 
26
- Or as [loader](https://nodejs.org/dist/latest-v16.x/docs/api/esm.html#loaders):
44
+ Run to show coverage report:
27
45
 
28
46
  ```sh
29
- NODE_OPTIONS="'--loader escover'" escover npm test
47
+ escover
30
48
  ```
31
49
 
32
50
  ## How it looks like?
@@ -39,6 +57,26 @@ When some lines missing coverage:
39
57
 
40
58
  ![image](https://user-images.githubusercontent.com/1573141/147944130-9b901646-05ff-4a76-86c9-30631b0a0dd4.png)
41
59
 
60
+ ## What if I want to use with `mock-import`?
61
+
62
+ Experimental `loaders` supports only one, for now. So [zenload](https://github.com/coderaiser/zenload) should be used.
63
+
64
+ Install it with:
65
+
66
+ ```sh
67
+ npm i escover mock-import zenload
68
+ ```
69
+
70
+ Then run:
71
+
72
+ ```sh
73
+ NODE_OPTIONS="'--loader zenlend'" ZENLOAD='escover,mock-import' escover npm test
74
+ ```
75
+
76
+ This configuration will add coverage collectors and then apply mocks with help of `mock-import`.
77
+ Of course the most comfortable way of doing this things will be [madrun](https://github.com/coderaiser/madrun).
78
+ Run you `package-scripts` in `JavaScript` :)!
79
+
42
80
  ## License
43
81
 
44
82
  MIT
package/lib/cli/cli.js CHANGED
@@ -1,19 +1,9 @@
1
- import {promisify} from 'util';
2
1
  import yargsParser from 'yargs-parser';
3
- import _foreground from 'foreground-child';
4
2
 
5
3
  import {version} from './version.js';
6
4
  import {report} from '../report.js';
7
5
 
8
- const foreground = promisify((cmd, fn) => {
9
- _foreground(cmd, () => {
10
- fn();
11
- });
12
- });
13
-
14
- process.env.ZENLOAD = 'escover,mock-import';
15
-
16
- export const cli = async ({argv, exit, read}) => {
6
+ export const cli = ({argv, exit, read}) => {
17
7
  const args = yargsParser(argv.slice(2), {
18
8
  boolean: [
19
9
  'version',
@@ -29,26 +19,6 @@ export const cli = async ({argv, exit, read}) => {
29
19
  return exit();
30
20
  }
31
21
 
32
- const cmd = hideInstrumenterArgs(args);
33
-
34
- if (!cmd.length)
35
- return;
36
-
37
- await foreground(cmd);
38
22
  const coverage = read();
39
-
40
23
  report(coverage);
41
24
  };
42
-
43
- function hideInstrumenterArgs(yargv) {
44
- let argv = process.argv.slice(1);
45
-
46
- argv = argv.slice(argv.indexOf(yargv._[0]));
47
-
48
- if (argv[0][0] === '-') {
49
- argv.unshift(process.execPath);
50
- }
51
-
52
- return argv;
53
- }
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
- if (!name)
36
- return null;
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,6 +1,6 @@
1
1
  {
2
2
  "name": "escover",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
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",
@@ -38,7 +38,6 @@
38
38
  "chalk": "^5.0.0",
39
39
  "find-cache-dir": "^3.3.2",
40
40
  "find-up": "^6.2.0",
41
- "foreground-child": "^2.0.0",
42
41
  "montag": "^1.2.1",
43
42
  "once": "^1.4.0",
44
43
  "putout": "^23.5.0",