escover 1.5.1 → 1.7.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,27 @@
1
+ 2022.01.17, v1.7.1
2
+
3
+ fix:
4
+ - escover: config: rm once
5
+
6
+
7
+ 2022.01.17, v1.7.0
8
+
9
+ feature:
10
+ - escover: add ability to read config
11
+
12
+
13
+ 2022.01.17, v1.6.0
14
+
15
+ feature:
16
+ - escover: add sorting
17
+
18
+
19
+ 2022.01.17, v1.5.2
20
+
21
+ fix:
22
+ - escover: add ability to override ZENLOAD && NODE_OPTIONS
23
+
24
+
1
25
  2022.01.17, v1.5.1
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,30 @@
1
+ import {readFileSync} from 'fs';
2
+ import picomatch from 'picomatch';
3
+ import {findUpSync} from 'find-up';
4
+
5
+ const {parse} = JSON;
6
+
7
+ export const isExclude = (name, patterns) => {
8
+ const isMatch = picomatch(patterns, {
9
+ dot: true,
10
+ });
11
+
12
+ return isMatch(name);
13
+ };
14
+
15
+ const defaults = {
16
+ exclude: [],
17
+ };
18
+
19
+ export const readConfig = () => {
20
+ const name = findUpSync('.nycrc.json');
21
+
22
+ if (!name)
23
+ return defaults;
24
+
25
+ const data = readFileSync(name, 'utf8');
26
+ return {
27
+ ...defaults,
28
+ ...parse(data),
29
+ };
30
+ };
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,
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.1",
3
+ "version": "1.7.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",
@@ -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",