escover 1.13.0 → 1.14.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,10 @@
1
+ 2022.01.21, v1.14.0
2
+
3
+ feature:
4
+ - escover: instrument: integrate with putout with crawling enabled
5
+ - escover: format: files: add align center
6
+
7
+
1
8
  2022.01.20, v1.13.0
2
9
 
3
10
  feature:
@@ -35,6 +35,8 @@ export default (coverageFile) => {
35
35
  },
36
36
  columns: [{
37
37
  paddingLeft: 0,
38
+ }, {
39
+ alignment: 'center',
38
40
  }],
39
41
  border: {
40
42
  ...getBorderCharacters('void'),
@@ -56,19 +56,15 @@ export default (coverageFile) => {
56
56
  out(`1..${files.length}`);
57
57
  out(`# files: ${files.length}`);
58
58
  out(`# covered: ${coverage.coveredCount}`);
59
-
60
59
  out('');
61
60
 
62
- if (!coverage.uncoveredCount) {
61
+ if (!coverage.uncoveredCount)
63
62
  out('#️ 🌴 ok');
64
- }
65
63
 
66
- if (coverage.uncoveredCount) {
64
+ if (coverage.uncoveredCount)
67
65
  out(`# 🧨 fail: ${coverage.uncoveredCount}`);
68
- }
69
66
 
70
67
  out('');
71
68
 
72
69
  return output.join('\n');
73
70
  };
74
-
@@ -1,5 +1,4 @@
1
1
  import putout from 'putout';
2
-
3
2
  import * as mark from './plugin-mark/index.js';
4
3
 
5
4
  export const instrument = (url, source) => {
@@ -1,7 +1,7 @@
1
1
  import {types} from 'putout';
2
2
  const {SequenceExpression} = types;
3
3
 
4
- export const addMarkToReturn = (path, lineNode) => {
4
+ export const addMarkToArgument = (path, lineNode) => {
5
5
  const {node} = path;
6
6
  const {expression} = lineNode;
7
7
 
@@ -4,9 +4,8 @@ import {
4
4
  operator,
5
5
  } from 'putout';
6
6
 
7
- import {addMarkToReturn} from './return.js';
7
+ import {addMarkToArgument} from './argument.js';
8
8
  import {addMarkToArrowFunction} from './arrow.js';
9
- import {addMarkToThrow} from './throw.js';
10
9
 
11
10
  const {
12
11
  NumericLiteral,
@@ -39,12 +38,10 @@ export const report = () => 'Mark line';
39
38
 
40
39
  export const fix = (path, {options}) => {
41
40
  const {node} = path;
42
-
43
41
  const {start} = path.node.loc;
44
42
 
45
43
  const {
46
44
  c4 = {
47
- mark: () => {},
48
45
  init: () => {},
49
46
  },
50
47
  } = options;
@@ -56,8 +53,9 @@ export const fix = (path, {options}) => {
56
53
  return;
57
54
  }
58
55
 
59
- if (path.isCallExpression()) {
56
+ if (path.isCallExpression() || path.isNewExpression()) {
60
57
  const {node} = path;
58
+
61
59
  replaceWith(path, SequenceExpression([
62
60
  lineNode.expression,
63
61
  node,
@@ -85,28 +83,18 @@ export const fix = (path, {options}) => {
85
83
  return;
86
84
  }
87
85
 
88
- if (path.isNewExpression()) {
89
- replaceWith(path, SequenceExpression([
90
- lineNode.expression,
91
- node,
92
- ]));
93
- return;
94
- }
95
-
96
- if (path.isReturnStatement())
97
- return addMarkToReturn(path, lineNode);
98
-
99
86
  if (path.isArrowFunctionExpression())
100
87
  return addMarkToArrowFunction(path, lineNode);
101
88
 
102
- if (path.isThrowStatement())
103
- return addMarkToThrow(path, lineNode);
89
+ if (path.isReturnStatement() || path.isThrowStatement())
90
+ return addMarkToArgument(path, lineNode);
104
91
 
105
- if (path.isContinueStatement() || path.isBreakStatement())
92
+ if (path.isContinueStatement() || path.isBreakStatement()) {
106
93
  return replaceWithMultiple(path, [
107
94
  lineNode,
108
95
  path.node,
109
96
  ]);
97
+ }
110
98
 
111
99
  replaceWith(path, BlockStatement([
112
100
  node,
@@ -115,24 +103,39 @@ export const fix = (path, {options}) => {
115
103
 
116
104
  const EXCLUDE = [
117
105
  LINE,
118
- `(${LINE}, __z)`,
119
106
  `return (${LINE}, __z)`,
120
107
  `return ${LINE}`,
121
108
  `throw (${LINE}, __z)`,
122
109
  ];
123
110
 
124
- export const exclude = () => EXCLUDE;
111
+ const SEQUENCE = `(${LINE}, __z)`;
112
+ const isExclude = (node) => {
113
+ return compareAny(node, [
114
+ ...EXCLUDE,
115
+ SEQUENCE,
116
+ ]);
117
+ };
125
118
 
126
- export const include = () => [
127
- 'CallExpression',
128
- 'NewExpression',
129
- 'ReturnStatement',
130
- 'ThrowStatement',
131
- ];
119
+ export const exclude = () => EXCLUDE;
132
120
 
133
121
  export const traverse = ({push}) => ({
122
+ 'ThrowStatement|ReturnStatement'(path) {
123
+ push(path);
124
+ },
125
+ CallExpression(path) {
126
+ if (compare(path.parentPath.node, SEQUENCE))
127
+ return;
128
+
129
+ push(path);
130
+ },
131
+ 'CallExpression|NewExpression'(path) {
132
+ if (compare(path.parentPath.node, SEQUENCE))
133
+ return;
134
+
135
+ push(path);
136
+ },
134
137
  'AssignmentPattern|AssignmentExpression'(path) {
135
- if (compareAny(path.get('right'), EXCLUDE))
138
+ if (isExclude(path.get('right')))
136
139
  return;
137
140
 
138
141
  push(path);
@@ -144,18 +147,13 @@ export const traverse = ({push}) => ({
144
147
  push(path);
145
148
  },
146
149
  'ContinueStatement|BreakStatement'(path) {
147
- if (!path.parentPath.isBlockStatement())
148
- return;
149
-
150
- const {body} = path.parentPath.node;
151
-
152
- if (compare(body[0], LINE))
150
+ if (compare(path.getPrevSibling(), LINE))
153
151
  return;
154
152
 
155
153
  push(path);
156
154
  },
157
155
  LogicalExpression(path) {
158
- if (compareAny(path.get('left'), EXCLUDE))
156
+ if (isExclude(path.get('left')))
159
157
  return;
160
158
 
161
159
  push(path);
@@ -167,6 +165,9 @@ export const traverse = ({push}) => ({
167
165
  push(path);
168
166
  },
169
167
  SequenceExpression(path) {
168
+ if (compare(path, `(${LINE}, __z)`))
169
+ return;
170
+
170
171
  const expressions = path.get('expressions');
171
172
 
172
173
  for (const expPath of expressions) {
@@ -180,7 +181,7 @@ export const traverse = ({push}) => ({
180
181
  const consequentPath = path.get('consequent');
181
182
  const alternatePath = path.get('alternate');
182
183
 
183
- if (!consequentPath.isBlockStatement() && !compareAny(consequentPath, EXCLUDE))
184
+ if (!consequentPath.isBlockStatement() && !isExclude(consequentPath))
184
185
  push(consequentPath);
185
186
 
186
187
  if (!alternatePath.node)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "escover",
3
- "version": "1.13.0",
3
+ "version": "1.14.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",
@@ -1,17 +0,0 @@
1
- import {
2
- types,
3
- operator,
4
- } from 'putout';
5
- const {SequenceExpression} = types;
6
-
7
- const {replaceWith} = operator;
8
-
9
- export const addMarkToThrow = (path, lineNode) => {
10
- const argumentPath = path.get('argument');
11
-
12
- return replaceWith(argumentPath, SequenceExpression([
13
- lineNode.expression,
14
- argumentPath.node,
15
- ]));
16
- };
17
-