escover 1.17.1 → 1.20.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.02.11, v1.20.0
2
+
3
+ feature:
4
+ - escover: export instrument, plugin
5
+
6
+
7
+ 2022.02.10, v1.19.0
8
+
9
+ feature:
10
+ - escover: mark: add ability of IfCondition alternate as IfCondition
11
+
12
+
13
+ 2022.01.30, v1.18.0
14
+
15
+ feature:
16
+ - escover: improve generation of SequenceExpressions
17
+
18
+
19
+ 2022.01.27, v1.17.2
20
+
21
+ fix:
22
+ - mark: StringLiteral
23
+
24
+
1
25
  2022.01.27, v1.17.1
2
26
 
3
27
  fix:
package/README.md CHANGED
@@ -84,9 +84,48 @@ Then run:
84
84
  NODE_OPTIONS="'--loader zenlend'" ZENLOAD='escover,mock-import' escover npm test
85
85
  ```
86
86
 
87
- This configuration will add coverage collectors and then apply mocks with help of `mock-import`.
88
- Of course the most comfortable way of doing this things will be [madrun](https://github.com/coderaiser/madrun).
89
- Run you `package-scripts` in `JavaScript` :)!
87
+ ## What you should know about `lcov`
88
+
89
+ Format used by 🎩`ESCover` located in `coverage/lcov.info`.
90
+
91
+ - ☝️ *[`lcov`](https://github.com/linux-test-project/lcov) was created in `2002`, almost twenty years ago.*
92
+ - ☝️ *Linux kernel developers created it to know what is going on with the coverage.*
93
+ - ☝️ *It's written in `PERL` and has text based format.*
94
+ - ☝️ *This is most popular coverage format of all times supported by a lot of tools (like [coveralls](https://coveralls.io)).*
95
+
96
+ When you run your `ESM` application with:
97
+
98
+ ```sh
99
+ escover npm test
100
+ ```
101
+
102
+ You will receive something similar to:
103
+
104
+ ```sh
105
+ SF:/Users/coderaiser/escover/lib/transform.js
106
+ DA:1,1
107
+ DA:3,1
108
+ DA:7,1
109
+ DA:9,1
110
+ DA:10,1
111
+ DA:12,1
112
+ DA:24,1
113
+ DA:25,1
114
+ DA:27,1
115
+ DA:28,1
116
+ DA:29,1
117
+ DA:32,1
118
+ end_of_record
119
+ ```
120
+
121
+ Where:
122
+ - `SF` - is path to source;
123
+ - `DA` - is line number, and count of running;
124
+ - `end_of_record` latest recored for current file entry;
125
+
126
+ The only thing that is differ from `lcov`: counters it `0` or `1`, if you have a reason to use "real" counters [create an issue](https://github.com/coderaiser/escover/issues/new).
127
+
128
+ It can be added in one line of code, but I see no reason why it can be useful 🤷‍♂️.
90
129
 
91
130
  ## License
92
131
 
package/lib/escover.js CHANGED
@@ -56,3 +56,4 @@ export async function load(url, context, defaultLoad) {
56
56
  };
57
57
  }
58
58
 
59
+ export default instrument;
@@ -1,4 +1,8 @@
1
- import putout from 'putout';
1
+ import {
2
+ parse,
3
+ generate,
4
+ transform,
5
+ } from 'putout';
2
6
  import * as mark from './plugin-mark/index.js';
3
7
 
4
8
  export const instrument = (url, source) => {
@@ -14,7 +18,10 @@ export const instrument = (url, source) => {
14
18
  ],
15
19
  };
16
20
 
17
- const {code} = putout(source, options);
21
+ const ast = parse(source);
22
+ transform(ast, source, options);
23
+ const {code} = generate(ast);
24
+
18
25
  return code;
19
26
  };
20
27
 
@@ -53,16 +53,6 @@ export const fix = (path, {options}) => {
53
53
  return;
54
54
  }
55
55
 
56
- if (path.isIdentifier()) {
57
- const {node} = path;
58
-
59
- replaceWith(path, SequenceExpression([
60
- lineNode.expression,
61
- node,
62
- ]));
63
- return;
64
- }
65
-
66
56
  if (path.isCallExpression() || path.isNewExpression()) {
67
57
  const {node} = path;
68
58
 
@@ -100,6 +90,16 @@ export const fix = (path, {options}) => {
100
90
  ]);
101
91
  }
102
92
 
93
+ if (path.isExpression()) {
94
+ const {node} = path;
95
+
96
+ replaceWith(path, SequenceExpression([
97
+ lineNode.expression,
98
+ node,
99
+ ]));
100
+ return;
101
+ }
102
+
103
103
  replaceWith(path, BlockStatement([
104
104
  node,
105
105
  ]));
@@ -199,8 +199,12 @@ export const traverse = ({push}) => ({
199
199
  if (!alternatePath.node)
200
200
  return;
201
201
 
202
- if (!alternatePath.isBlockStatement() && !isExclude(alternatePath))
202
+ if (alternatePath.isIfStatement())
203
+ return;
204
+
205
+ if (!alternatePath.isBlockStatement() && !isExclude(alternatePath)) {
203
206
  push(alternatePath);
207
+ }
204
208
  },
205
209
  });
206
210
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "escover",
3
- "version": "1.17.1",
3
+ "version": "1.20.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",
@@ -13,6 +13,13 @@
13
13
  "type": "git",
14
14
  "url": "git://github.com/coderaiser/escover.git"
15
15
  },
16
+ "exports": {
17
+ ".": {
18
+ "import": "./lib/escover.js"
19
+ },
20
+ "./plugin": "./lib/instrument/plugin-mark/index.js",
21
+ "./instrument": "./lib/instrument/index.js"
22
+ },
16
23
  "keywords": [
17
24
  "coverage",
18
25
  "putout",