escover 1.3.0 → 1.3.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,12 @@
1
+ 2022.01.15, v1.3.1
2
+
3
+ fix:
4
+ - escover: do not write coverage when empty
5
+
6
+ feature:
7
+ - escover: add ability to get coverage of itself
8
+
9
+
1
10
  2022.01.15, v1.3.0
2
11
 
3
12
  feature:
package/lib/c4.js CHANGED
@@ -1,8 +1,8 @@
1
- const files = new Map();
1
+ export const __fileEntries = new Map();
2
2
 
3
3
  export const createFileEntry = (url) => {
4
- const lines = files.get(url) || new Map();
5
- files.set(url, lines);
4
+ const lines = __fileEntries.get(url) || new Map();
5
+ __fileEntries.set(url, lines);
6
6
 
7
7
  return {
8
8
  '🧨': (line, column) => {
@@ -14,4 +14,4 @@ export const createFileEntry = (url) => {
14
14
  };
15
15
  };
16
16
 
17
- export const getFiles = () => files;
17
+ export const getFileEntries = () => __fileEntries;
@@ -0,0 +1,47 @@
1
+ import tryCatch from 'try-catch';
2
+ import {
3
+ writeFileSync,
4
+ readFileSync,
5
+ } from 'fs';
6
+ import {getFileEntries} from './c4.js';
7
+ import {transform} from './transform.js';
8
+ import {merge} from './merge.js';
9
+ import findCacheDir from 'find-cache-dir';
10
+
11
+ const {
12
+ stringify,
13
+ parse,
14
+ } = JSON;
15
+
16
+ const NAME = 'escover';
17
+ const buildName = (a) => `${a}/${NAME}.json`;
18
+
19
+ export const write = () => {
20
+ const files = getFileEntries();
21
+
22
+ if (!files.size)
23
+ return;
24
+
25
+ const parsed = transform(files);
26
+ const merged = merge(parsed);
27
+ const name = findCacheDir({
28
+ name: NAME,
29
+ create: true,
30
+ });
31
+
32
+ writeFileSync(buildName(name), stringify(merged, null, 4));
33
+ };
34
+
35
+ export const read = () => {
36
+ const name = findCacheDir({
37
+ name: NAME,
38
+ });
39
+
40
+ const [error, data] = tryCatch(readFileSync, buildName(name), 'utf8');
41
+
42
+ if (error)
43
+ return [];
44
+
45
+ return parse(data);
46
+ };
47
+
package/lib/escover.js CHANGED
@@ -10,7 +10,13 @@ global.__createC4 = createFileEntry;
10
10
 
11
11
  process.once('exit', exit);
12
12
 
13
- const EXCLUDE = ['.spec.', 'node_modules', '/fixture/', '.madrun.', '/test/'];
13
+ const EXCLUDE = [
14
+ '.spec.',
15
+ 'node_modules',
16
+ '/fixture/',
17
+ '.madrun.',
18
+ '/test/',
19
+ ];
14
20
 
15
21
  export async function load(url, context, defaultLoad) {
16
22
  const {format, source: rawSource} = await defaultLoad(url, context, defaultLoad);
package/lib/exit.js CHANGED
@@ -2,5 +2,6 @@ import once from 'once';
2
2
  import {write} from './coverage.js';
3
3
 
4
4
  export const exit = once(() => {
5
+ console.log("xxx");
5
6
  write();
6
7
  });
@@ -3,11 +3,11 @@ import putout, {} from 'putout';
3
3
  import * as mark from './plugin-mark/index.js';
4
4
 
5
5
  export const instrument = (url, source) => {
6
- const __c4 = global.__createC4(url);
6
+ const c4 = global.__createC4(url);
7
7
  const options = {
8
8
  rules: {
9
9
  mark: ['on', {
10
- __c4,
10
+ c4,
11
11
  }],
12
12
  },
13
13
  plugins: [
@@ -23,8 +23,8 @@ const buildLineNode = template(LINE, {
23
23
  placeholderPattern: /^__[a-z]$/,
24
24
  });
25
25
 
26
- function getLineNode(__c4, {line, column}) {
27
- __c4.init(line, column);
26
+ function getLineNode(c4, {line, column}) {
27
+ c4.init(line, column);
28
28
 
29
29
  return buildLineNode({
30
30
  __l: NumericLiteral(line),
@@ -46,13 +46,13 @@ export const fix = (path, {options}) => {
46
46
  return;
47
47
 
48
48
  const {
49
- __c4 = {
49
+ c4 = {
50
50
  mark: () => {},
51
51
  init: () => {},
52
52
  },
53
53
  } = options;
54
54
 
55
- const lineNode = getLineNode(__c4, start);
55
+ const lineNode = getLineNode(c4, start);
56
56
 
57
57
  if (path.isBlockStatement()) {
58
58
  path.node.body.unshift(lineNode);
@@ -74,7 +74,7 @@ export const fix = (path, {options}) => {
74
74
  path.node.left,
75
75
  ]));
76
76
  replaceWith(path.get('right'), SequenceExpression([
77
- getLineNode(__c4, path.node.right.loc.start).expression,
77
+ getLineNode(c4, path.node.right.loc.start).expression,
78
78
  path.node.right,
79
79
  ]));
80
80
  return;
@@ -99,9 +99,8 @@ 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
- }
105
104
 
106
105
  if (path.isThrowStatement())
107
106
  return addMarkToThrow(path, lineNode);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "escover",
3
- "version": "1.3.0",
3
+ "version": "1.3.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",