escover 1.5.2 → 1.7.2

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.18, v1.7.2
2
+
3
+ feature:
4
+ - escover: config: isExclude: add ability to drop stars
5
+
6
+
7
+ 2022.01.17, v1.7.1
8
+
9
+ fix:
10
+ - escover: config: rm once
11
+
12
+
13
+ 2022.01.17, v1.7.0
14
+
15
+ feature:
16
+ - escover: add ability to read config
17
+
18
+
19
+ 2022.01.17, v1.6.0
20
+
21
+ feature:
22
+ - escover: add sorting
23
+
24
+
1
25
  2022.01.17, v1.5.2
2
26
 
3
27
  fix:
package/README.md CHANGED
@@ -45,15 +45,15 @@ Run to collect and show coverage:
45
45
  escover npm test
46
46
  ```
47
47
 
48
- ## How it looks like?
48
+ ## Config
49
49
 
50
- When everything is covered:
50
+ `exclude` section of configuration file `.nyrc.json` supported.
51
51
 
52
- ![image](https://user-images.githubusercontent.com/1573141/147943954-ef708577-2856-4de0-9397-dead487b8c08.png)
52
+ ## How it looks like?
53
53
 
54
- When some lines missing coverage:
54
+ When everything is covered:
55
55
 
56
- ![image](https://user-images.githubusercontent.com/1573141/147944130-9b901646-05ff-4a76-86c9-30631b0a0dd4.png)
56
+ ![image](https://user-images.githubusercontent.com/1573141/149822261-ff9bc3b4-6ee4-452c-9ada-3cc922b630ec.png)
57
57
 
58
58
  ## What if I want to use 🎩`ESCover` with `mock-import`?
59
59
 
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
- NODE_OPTIONS: '--no-warnings --loader zenload',
50
51
  ZENLOAD: 'escover,mock-import',
51
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,42 @@
1
+ import {readFileSync} from 'fs';
2
+ import picomatch from 'picomatch';
3
+ import {findUpSync} from 'find-up';
4
+
5
+ const {parse} = JSON;
6
+
7
+ const addStars = (patterns) => {
8
+ const result = [];
9
+ for (const pattern of patterns) {
10
+ result.push(...[
11
+ `**/${pattern}/**`,
12
+ pattern,
13
+ ]);
14
+ }
15
+
16
+ return result;
17
+ };
18
+
19
+ export const isExclude = (name, patterns) => {
20
+ const isMatch = picomatch(addStars(patterns), {
21
+ dot: true,
22
+ });
23
+
24
+ return isMatch(name);
25
+ };
26
+
27
+ const defaults = {
28
+ exclude: [],
29
+ };
30
+
31
+ export const readConfig = () => {
32
+ const name = findUpSync('.nycrc.json');
33
+
34
+ if (!name)
35
+ return defaults;
36
+
37
+ const data = readFileSync(name, 'utf8');
38
+ return {
39
+ ...defaults,
40
+ ...parse(data),
41
+ };
42
+ };
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.2",
3
+ "version": "1.7.2",
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",