escover 1.0.5 → 1.1.3

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,27 @@
1
+ 2022.01.11, v1.1.3
2
+
3
+ fix:
4
+ - escover: rm unused
5
+
6
+
7
+ 2022.01.11, v1.1.2
8
+
9
+ fix:
10
+ - escover: get back running support
11
+
12
+
13
+ 2022.01.11, v1.1.1
14
+
15
+ feature:
16
+ - escover: bin only shows report
17
+
18
+
19
+ 2022.01.11, v1.1.0
20
+
21
+ feature:
22
+ - (escover) add bin
23
+
24
+
1
25
  2022.01.08, v1.0.5
2
26
 
3
27
  feature:
package/README.md CHANGED
@@ -9,18 +9,40 @@
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
- Explosive coverage tool
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 -g
39
+ npm i escover -D
18
40
  ```
19
41
 
20
- Then run using:
42
+ Run to collect and show coverage:
21
43
 
22
44
  ```sh
23
- NODE_OPTIONS="'--loader escover'" escover npm test
45
+ escover npm test
24
46
  ```
25
47
 
26
48
  ## How it looks like?
@@ -33,6 +55,26 @@ When some lines missing coverage:
33
55
 
34
56
  ![image](https://user-images.githubusercontent.com/1573141/147944130-9b901646-05ff-4a76-86c9-30631b0a0dd4.png)
35
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
+
36
78
  ## License
37
79
 
38
80
  MIT
package/bin/escover.js ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {cli} from '../lib/cli/cli.js';
4
+ import {read} from '../lib/config.js';
5
+
6
+ cli({
7
+ argv: process.argv,
8
+ exit: process.exit,
9
+ read,
10
+ });
11
+
package/lib/cli/cli.js ADDED
@@ -0,0 +1,49 @@
1
+ import {execSync} from 'child_process';
2
+ import tryCatch from 'try-catch';
3
+ import yargsParser from 'yargs-parser';
4
+
5
+ import {version} from './version.js';
6
+ import {report} from '../report.js';
7
+
8
+ export const cli = ({argv, exit, read}) => {
9
+ const args = yargsParser(argv.slice(2), {
10
+ boolean: [
11
+ 'version',
12
+ ],
13
+ alias: {
14
+ v: 'version',
15
+ },
16
+ configuration: {},
17
+ });
18
+
19
+ if (args.version) {
20
+ console.log(`v${version()}`);
21
+ return exit();
22
+ }
23
+
24
+ const cmd = argv.slice(2);
25
+
26
+ if (cmd.length) {
27
+ execute('"' + cmd.join(`" "`) + '"', exit);
28
+ }
29
+
30
+ const coverage = read();
31
+
32
+ report(coverage);
33
+ };
34
+
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
+ });
44
+
45
+ if (error) {
46
+ console.error(error.message);
47
+ return exit(1);
48
+ }
49
+ }
@@ -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/exit.js CHANGED
@@ -1,9 +1,6 @@
1
1
  import once from 'once';
2
-
3
- import {save} from './save.js';
4
- import {report} from './report.js';
2
+ import {write} from './config.js';
5
3
 
6
4
  export const exit = once(() => {
7
- save();
8
- report();
5
+ write();
9
6
  });
@@ -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,
@@ -62,7 +57,7 @@ export const report = () => {
62
57
  console.log('');
63
58
 
64
59
  if (!coverage.uncoveredCount) {
65
- console.log('# ☘️ ok');
60
+ console.log('#️ 🌴 ok');
66
61
  }
67
62
 
68
63
  if (coverage.uncoveredCount) {
@@ -1,4 +1,4 @@
1
- export const parse = (files) => {
1
+ export const transform = (files) => {
2
2
  const result = [];
3
3
 
4
4
  for (const [rawName, places] of files.entries()) {
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "escover",
3
- "version": "1.0.5",
3
+ "version": "1.1.3",
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"
@@ -19,6 +23,7 @@
19
23
  "test": "madrun test",
20
24
  "test:only": "madrun test:only",
21
25
  "coverage": "madrun coverage",
26
+ "c4": "madrun c4",
22
27
  "lint": "madrun lint",
23
28
  "fresh:lint": "madrun fresh:lint",
24
29
  "lint:fresh": "madrun lint:fresh",
@@ -32,9 +37,13 @@
32
37
  },
33
38
  "dependencies": {
34
39
  "chalk": "^5.0.0",
40
+ "find-cache-dir": "^3.3.2",
41
+ "find-up": "^6.2.0",
35
42
  "montag": "^1.2.1",
36
43
  "once": "^1.4.0",
37
- "putout": "^23.5.0"
44
+ "putout": "^23.5.0",
45
+ "try-catch": "^3.0.0",
46
+ "yargs-parser": "^21.0.0"
38
47
  },
39
48
  "engines": {
40
49
  "node": ">=14"
@@ -43,6 +52,7 @@
43
52
  "devDependencies": {
44
53
  "@putout/test": "^4.1.0",
45
54
  "c8": "^7.8.0",
55
+ "escover": ".",
46
56
  "eslint": "^8.3.0",
47
57
  "eslint-plugin-node": "^11.1.0",
48
58
  "eslint-plugin-putout": "^12.2.0",
package/c4.json DELETED
@@ -1,15 +0,0 @@
1
- [{
2
- "name": "changelog.js",
3
- "lines": {
4
- "1": false,
5
- "7": false,
6
- "9": false
7
- }
8
- }, {
9
- "name": "simple.js",
10
- "lines": {
11
- "1": true,
12
- "7": true,
13
- "9": true
14
- }
15
- }]
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
- };