escover 1.6.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,9 @@
1
+ 2022.01.17, v1.7.0
2
+
3
+ feature:
4
+ - escover: add ability to read config
5
+
6
+
1
7
  2022.01.17, v1.6.0
2
8
 
3
9
  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/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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "escover",
3
- "version": "1.6.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",