escover 1.0.5 → 1.1.0

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.0
2
+
3
+ feature:
4
+ - (escover) add bin
5
+
6
+
1
7
  2022.01.08, v1.0.5
2
8
 
3
9
  feature:
package/README.md CHANGED
@@ -9,7 +9,7 @@
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).
13
13
 
14
14
  ## Install
15
15
 
@@ -19,6 +19,12 @@ npm i escover -g
19
19
 
20
20
  Then run using:
21
21
 
22
+ ```sh
23
+ escover npm test
24
+ ```
25
+
26
+ Or as [loader](https://nodejs.org/dist/latest-v16.x/docs/api/esm.html#loaders):
27
+
22
28
  ```sh
23
29
  NODE_OPTIONS="'--loader escover'" escover npm test
24
30
  ```
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,54 @@
1
+ import {promisify} from 'util';
2
+ import yargsParser from 'yargs-parser';
3
+ import _foreground from 'foreground-child';
4
+
5
+ import {version} from './version.js';
6
+ import {report} from '../report.js';
7
+
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}) => {
17
+ const args = yargsParser(argv.slice(2), {
18
+ boolean: [
19
+ 'version',
20
+ ],
21
+ alias: {
22
+ v: 'version',
23
+ },
24
+ configuration: {},
25
+ });
26
+
27
+ if (args.version) {
28
+ console.log(`v${version()}`);
29
+ return exit();
30
+ }
31
+
32
+ const cmd = hideInstrumenterArgs(args);
33
+
34
+ if (!cmd.length)
35
+ return;
36
+
37
+ await foreground(cmd);
38
+ const coverage = read();
39
+
40
+ report(coverage);
41
+ };
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
+
@@ -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,40 @@
1
+ import {
2
+ writeFileSync,
3
+ readFileSync,
4
+ } from 'fs';
5
+ import {getFiles} from './c4.js';
6
+ import {transform} from './transform.js';
7
+ import {merge} from './merge.js';
8
+ import findCacheDir from 'find-cache-dir';
9
+
10
+ const {
11
+ stringify,
12
+ parse,
13
+ } = JSON;
14
+
15
+ const NAME = 'escover';
16
+ const buildName = (a) => `${a}/${NAME}.json`;
17
+
18
+ export const write = () => {
19
+ const files = getFiles();
20
+ const parsed = transform(files);
21
+ const merged = merge(parsed);
22
+ const name = findCacheDir({
23
+ name: NAME,
24
+ create: true,
25
+ });
26
+
27
+ writeFileSync(buildName(name), stringify(merged, null, 4));
28
+ };
29
+
30
+ export const read = () => {
31
+ const name = findCacheDir({
32
+ name: NAME,
33
+ });
34
+
35
+ if (!name)
36
+ return null;
37
+
38
+ const data = readFileSync(buildName(name), 'utf8');
39
+ return parse(data);
40
+ };
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,13 @@
1
1
  {
2
2
  "name": "escover",
3
- "version": "1.0.5",
3
+ "version": "1.1.0",
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
+ "bin": {
9
+ "escover": "bin/escover.js"
10
+ },
8
11
  "repository": {
9
12
  "type": "git",
10
13
  "url": "git://github.com/coderaiser/escover.git"
@@ -19,6 +22,7 @@
19
22
  "test": "madrun test",
20
23
  "test:only": "madrun test:only",
21
24
  "coverage": "madrun coverage",
25
+ "c4": "madrun c4",
22
26
  "lint": "madrun lint",
23
27
  "fresh:lint": "madrun fresh:lint",
24
28
  "lint:fresh": "madrun lint:fresh",
@@ -32,9 +36,14 @@
32
36
  },
33
37
  "dependencies": {
34
38
  "chalk": "^5.0.0",
39
+ "find-cache-dir": "^3.3.2",
40
+ "find-up": "^6.2.0",
41
+ "foreground-child": "^2.0.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
- };