escover 1.1.1 → 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 CHANGED
@@ -1,3 +1,9 @@
1
+ 2022.01.11, v1.1.2
2
+
3
+ fix:
4
+ - escover: get back running support
5
+
6
+
1
7
  2022.01.11, v1.1.1
2
8
 
3
9
  feature:
package/README.md CHANGED
@@ -11,22 +11,22 @@
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
13
 
14
- # Why another coverage tool?
14
+ ## Why another coverage tool?
15
15
 
16
16
  When you want to use `ESM` in `Node.js` without transpiling to `CommonJS` (that's what `jest`, `ava`, `tap` does),
17
17
  you have a couple problems to solve.
18
18
 
19
- 🤷‍ What test runner does no transpiling to `CommonJS`?
19
+ ### 🤷‍ What test runner does no transpiling to `CommonJS`?
20
20
  ☝️ that's easy! 📼 [`Supertape`](https://github.com/coderaiser/supertape) supports `ESM` from the box;
21
21
 
22
- 🤷‍ How to mock modules without [mock-require](https://github.com/boblauer/mock-require) (we in `ESM`!);
22
+ ### 🤷‍ How to mock modules without [mock-require](https://github.com/boblauer/mock-require) (we in `ESM`!);
23
23
  ☝️ that's solved! [`mock-import`](https://github.com/coderaiser/mock-import) does the thing using `loaders`;
24
24
 
25
- 🤷‍ How to get coverage when `nyc` doesn't supported?
25
+ ### 🤷‍ How to get coverage when `nyc` doesn't supported?
26
26
  ☝️ `c8` could help, but [no](https://github.com/coderaiser/c8-reproduce) it supports no `query paramters`
27
27
  which are needed to load module again, and apply mocks.
28
28
 
29
- 🤷‍ How to get coverage when mocks are used?
29
+ ### 🤷‍ How to get coverage when mocks are used?
30
30
  ☝️ Use 🎩 `ESCover`! It supports loaders, `ESM` and collects coverage as a loader!
31
31
 
32
32
  ## Install
@@ -35,16 +35,10 @@ which are needed to load module again, and apply mocks.
35
35
  npm i escover -D
36
36
  ```
37
37
 
38
- Run to collect coverage:
38
+ Run to collect and show coverage:
39
39
 
40
40
  ```sh
41
- NODE_OPTIONS="'--loader escover'" escover npm test
42
- ```
43
-
44
- Run to show coverage report:
45
-
46
- ```sh
47
- escover
41
+ escover npm test
48
42
  ```
49
43
 
50
44
  ## How it looks like?
@@ -57,7 +51,7 @@ When some lines missing coverage:
57
51
 
58
52
  ![image](https://user-images.githubusercontent.com/1573141/147944130-9b901646-05ff-4a76-86c9-30631b0a0dd4.png)
59
53
 
60
- ## What if I want to use with `mock-import`?
54
+ ## What if I want to use 🎩`ESCover` with `mock-import`?
61
55
 
62
56
  Experimental `loaders` supports only one, for now. So [zenload](https://github.com/coderaiser/zenload) should be used.
63
57
 
package/lib/cli/cli.js CHANGED
@@ -1,8 +1,23 @@
1
+ import {
2
+ execSync,
3
+ spawnSync,
4
+ } from 'child_process';
5
+ import {promisify} from 'util';
6
+ import tryCatch from 'try-catch';
1
7
  import yargsParser from 'yargs-parser';
8
+ import _foreground from 'foreground-child';
2
9
 
3
10
  import {version} from './version.js';
4
11
  import {report} from '../report.js';
5
12
 
13
+ const foreground = promisify((cmd, fn) => {
14
+ _foreground(cmd, (done) => {
15
+ fn();
16
+ });
17
+ });
18
+
19
+ process.env.ZENLOAD = 'escover,mock-import';
20
+
6
21
  export const cli = ({argv, exit, read}) => {
7
22
  const args = yargsParser(argv.slice(2), {
8
23
  boolean: [
@@ -19,6 +34,29 @@ export const cli = ({argv, exit, read}) => {
19
34
  return exit();
20
35
  }
21
36
 
37
+ const cmd = argv.slice(2);
38
+
39
+ if (cmd.length) {
40
+ execute('"' + cmd.join(`" "`) + '"', exit);
41
+ }
42
+
22
43
  const coverage = read();
44
+
23
45
  report(coverage);
24
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
+ }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "escover",
3
- "version": "1.1.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",
8
9
  "bin": {
9
10
  "escover": "bin/escover.js"
10
11
  },