escover 1.5.0 → 1.7.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,27 @@
1
+ 2022.01.17, v1.7.0
2
+
3
+ feature:
4
+ - escover: add ability to read config
5
+
6
+
7
+ 2022.01.17, v1.6.0
8
+
9
+ feature:
10
+ - escover: add sorting
11
+
12
+
13
+ 2022.01.17, v1.5.2
14
+
15
+ fix:
16
+ - escover: add ability to override ZENLOAD && NODE_OPTIONS
17
+
18
+
19
+ 2022.01.17, v1.5.1
20
+
21
+ feature:
22
+ - escover: add lines %
23
+
24
+
1
25
  2022.01.17, v1.5.0
2
26
 
3
27
  feature:
package/README.md CHANGED
@@ -45,6 +45,10 @@ Run to collect and show coverage:
45
45
  escover npm test
46
46
  ```
47
47
 
48
+ ## Config
49
+
50
+ `exclude` section of configuration file `.nyrc.json` supported.
51
+
48
52
  ## How it looks like?
49
53
 
50
54
  When everything is covered:
package/lib/cli/cli.js CHANGED
@@ -6,6 +6,8 @@ import {version} from './version.js';
6
6
  import reportLines from '../formatters/lines.js';
7
7
  import reportFiles from '../formatters/files.js';
8
8
 
9
+ const {ESCOVER_FORMAT, NODE_OPTIONS = ''} = process.env;
10
+
9
11
  export const cli = ({argv, exit, read}) => {
10
12
  const args = yargsParser(argv.slice(2), {
11
13
  string: [
@@ -19,7 +21,7 @@ export const cli = ({argv, exit, read}) => {
19
21
  f: 'format',
20
22
  },
21
23
  default: {
22
- format: 'files',
24
+ format: ESCOVER_FORMAT || 'files',
23
25
  },
24
26
  });
25
27
 
@@ -46,9 +48,9 @@ function execute(cmd, exit) {
46
48
  const [error] = tryCatch(execSync, cmd, {
47
49
  stdio: [0, 1, 2],
48
50
  env: {
49
- ...process.env,
50
- NODE_OPTIONS: '--no-warnings --loader zenload',
51
51
  ZENLOAD: 'escover,mock-import',
52
+ ...process.env,
53
+ NODE_OPTIONS: `--no-warnings --loader zenload ${NODE_OPTIONS} `,
52
54
  },
53
55
  });
54
56
 
package/lib/config.js ADDED
@@ -0,0 +1,31 @@
1
+ import {readFileSync} from 'fs';
2
+ import once from 'once';
3
+ import picomatch from 'picomatch';
4
+ import {findUpSync} from 'find-up';
5
+
6
+ const {parse} = JSON;
7
+
8
+ export const isExclude = (name, patterns) => {
9
+ const isMatch = picomatch(patterns, {
10
+ dot: true,
11
+ });
12
+
13
+ return isMatch(name);
14
+ };
15
+
16
+ const defaults = {
17
+ exclude: [],
18
+ };
19
+
20
+ export const readConfig = once(() => {
21
+ const name = findUpSync('.nycrc.json');
22
+
23
+ if (!name)
24
+ return defaults;
25
+
26
+ const data = readFileSync(name, 'utf8');
27
+ return {
28
+ ...defaults,
29
+ ...parse(data),
30
+ };
31
+ });
package/lib/escover.js CHANGED
@@ -2,21 +2,27 @@ import montag from 'montag';
2
2
  import process from 'process';
3
3
 
4
4
  import {instrument} from './instrument/index.js';
5
- import {exclude} from './exclude.js';
6
5
  import {exit} from './exit.js';
7
6
  import {createFileEntry} from './c4.js';
7
+ import {
8
+ readConfig,
9
+ isExclude,
10
+ } from './config.js';
8
11
 
9
12
  global.__createC4 = createFileEntry;
10
13
 
11
14
  process.once('exit', exit);
12
15
  const CWD = process.cwd();
13
16
 
17
+ const {exclude} = readConfig();
18
+
14
19
  const EXCLUDE = [
15
- '.spec.',
16
- 'node_modules',
17
- '/fixture/',
18
- '.madrun.',
19
- '/test/',
20
+ '**/*.spec.*',
21
+ '**/node_modules/**',
22
+ '**/fixture/**',
23
+ '**/.madrun.*',
24
+ '**/test/**',
25
+ ...exclude,
20
26
  ];
21
27
 
22
28
  export async function load(url, context, defaultLoad) {
@@ -33,7 +39,7 @@ export async function load(url, context, defaultLoad) {
33
39
  source: rawSource,
34
40
  };
35
41
 
36
- if (exclude(url, EXCLUDE))
42
+ if (isExclude(url, EXCLUDE))
37
43
  return {
38
44
  format,
39
45
  source: rawSource,
@@ -6,26 +6,30 @@ import {
6
6
  import chalk from 'chalk';
7
7
 
8
8
  const CWD = process.cwd();
9
- const {entries} = Object;
9
+ const {
10
+ entries,
11
+ keys,
12
+ } = Object;
10
13
 
11
14
  export default (coverageFile) => {
12
15
  const files = parseCoverageFile(coverageFile);
16
+
13
17
  const tableData = [
14
- ['File', 'Uncovered Lines'],
18
+ ['File', '% Lines', 'Uncovered Lines #s'],
15
19
  ];
16
20
 
17
- for (const {filename, covered, lines} of files) {
21
+ for (const {filename, covered, lines, percentLines} of files) {
18
22
  const uncoveredLines = lines.join(', ');
19
23
 
20
24
  if (covered) {
21
- tableData.push([chalk.green(filename), '']);
25
+ tableData.push([chalk.green(filename), chalk.green(percentLines), '']);
22
26
  continue;
23
27
  }
24
28
 
25
- tableData.push([chalk.red(filename), chalk.red(uncoveredLines)]);
29
+ tableData.push([chalk.red(filename), chalk.red(percentLines), chalk.red(uncoveredLines)]);
26
30
  }
27
31
 
28
- console.log(table(tableData, {
32
+ process.stdout.write(table(tableData, {
29
33
  drawHorizontalLine: (raw) => {
30
34
  return !raw || raw === 1 || raw === files.length + 1;
31
35
  },
@@ -64,13 +68,23 @@ function parseCoverageFile(coverageFile) {
64
68
  const filename = name.replace(CWD + '/', '');
65
69
  const uncoveredLines = parseUncoveredLines(lines);
66
70
 
71
+ const linesCount = keys(lines).length;
72
+ const percentLines = getPercentLines(linesCount, uncoveredLines);
73
+
67
74
  files.push({
68
75
  filename,
69
76
  covered: !uncoveredLines.length,
70
- lines: parseUncoveredLines(lines),
77
+ lines: uncoveredLines,
78
+ percentLines,
71
79
  });
72
80
  }
73
81
 
74
82
  return files;
75
83
  }
76
84
 
85
+ function getPercentLines(linesCount, uncoveredLines) {
86
+ if (!linesCount)
87
+ return 100;
88
+
89
+ return 100 - Math.round(100 / linesCount * uncoveredLines.length);
90
+ }
package/lib/transform.js CHANGED
@@ -1,7 +1,10 @@
1
+ const sort = (a) => new Map(Array.from(a.entries()).sort());
2
+
1
3
  export const transform = (files) => {
2
4
  const result = [];
5
+ const sorted = sort(files);
3
6
 
4
- for (const [rawName, places] of files.entries()) {
7
+ for (const [rawName, places] of sorted.entries()) {
5
8
  const rawLines = {};
6
9
 
7
10
  for (const [place, covered] of places.entries()) {
@@ -18,3 +21,4 @@ export const transform = (files) => {
18
21
 
19
22
  return result;
20
23
  };
24
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "escover",
3
- "version": "1.5.0",
3
+ "version": "1.7.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",
@@ -42,6 +42,7 @@
42
42
  "mock-import": "^2.11.1",
43
43
  "montag": "^1.2.1",
44
44
  "once": "^1.4.0",
45
+ "picomatch": "^2.3.1",
45
46
  "putout": "^24.0.2",
46
47
  "table": "^6.8.0",
47
48
  "try-catch": "^3.0.0",