escover 1.0.2 → 1.0.3

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.08, v1.0.3
2
+
3
+ feature:
4
+ - escover: plugin-mark: add support ot ThrowStatement
5
+ - escover: add merger
6
+
7
+
1
8
  2022.01.08, v1.0.2
2
9
 
3
10
  fix:
package/coverage.json CHANGED
@@ -1,6 +1,6 @@
1
1
  [
2
2
  {
3
- "name": "file:///Users/coderaiser/escover/example/example.js",
3
+ "name": "/Users/coderaiser/escover/example/example.js",
4
4
  "lines": {
5
5
  "1": true
6
6
  }
package/lib/escover.js CHANGED
@@ -27,6 +27,8 @@ export async function load(url, context, defaultLoad) {
27
27
  ${instrument(url, rawSource)}
28
28
  `;
29
29
 
30
+ console.log(source);
31
+
30
32
  return {
31
33
  format,
32
34
  source,
@@ -0,0 +1,3 @@
1
+ if (error) {
2
+ throw (__c4.mark(2, 4), `error reading package.json: ${error.message}`);
3
+ }
@@ -0,0 +1,3 @@
1
+ if (error) {
2
+ throw `error reading package.json: ${error.message}`;
3
+ }
@@ -10,7 +10,6 @@ const {
10
10
  NumericLiteral,
11
11
  SequenceExpression,
12
12
  BlockStatement,
13
- ExpressionStatement,
14
13
  } = types;
15
14
 
16
15
  const {
@@ -103,6 +102,13 @@ export const fix = (path, {options}) => {
103
102
  if (path.isArrowFunctionExpression())
104
103
  return addMarkToArrowFunction(path, lineNode);
105
104
 
105
+ if (path.isThrowStatement()) {
106
+ return replaceWith(path.get('argument'), SequenceExpression([
107
+ lineNode.expression,
108
+ node.argument,
109
+ ]));
110
+ }
111
+
106
112
  replaceWith(path, BlockStatement([
107
113
  node,
108
114
  ]));
@@ -113,6 +119,7 @@ const EXCLUDE = [
113
119
  `(${LINE}, __z)`,
114
120
  `return (${LINE}, __z)`,
115
121
  `return ${LINE}`,
122
+ `throw (${LINE}, __z)`,
116
123
  ];
117
124
 
118
125
  export const exclude = () => EXCLUDE;
@@ -121,6 +128,7 @@ export const include = () => [
121
128
  'CallExpression',
122
129
  'NewExpression',
123
130
  'ReturnStatement',
131
+ 'ThrowStatement',
124
132
  ];
125
133
 
126
134
  export const traverse = ({push}) => ({
@@ -0,0 +1,17 @@
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
+
package/lib/merge.js ADDED
@@ -0,0 +1,44 @@
1
+ const {entries} = Object;
2
+
3
+ export const merge = (files) => {
4
+ const deduplicator = {};
5
+
6
+ for (const {rawName, rawLines} of files) {
7
+ const name = cutQuery(rawName);
8
+ const lines = applyCoverage({
9
+ name,
10
+ rawLines,
11
+ deduplicator,
12
+ });
13
+
14
+ deduplicator[name] = lines;
15
+ }
16
+
17
+ const list = [];
18
+ for (const [name, lines] of entries(deduplicator)) {
19
+ list.push({
20
+ name,
21
+ lines,
22
+ });
23
+ }
24
+
25
+ return list;
26
+ };
27
+
28
+ function applyCoverage({rawLines, name, deduplicator}) {
29
+ if (!deduplicator[name])
30
+ return rawLines;
31
+
32
+ const newLines = {};
33
+
34
+ for (const [line, value] of entries(rawLines))
35
+ newLines[line] = deduplicator[name][line] || value;
36
+
37
+ return newLines;
38
+ }
39
+
40
+ function cutQuery(name) {
41
+ return name
42
+ .replace('file://', '')
43
+ .replace(/\?.*/, '');
44
+ }
package/lib/parse.js ADDED
@@ -0,0 +1,20 @@
1
+ export const parse = (files) => {
2
+ const result = [];
3
+
4
+ for (const [rawName, places] of files.entries()) {
5
+ const rawLines = {};
6
+
7
+ for (const [place, covered] of places.entries()) {
8
+ const [line] = place.split(':');
9
+
10
+ rawLines[line] = covered;
11
+ }
12
+
13
+ result.push({
14
+ rawName,
15
+ rawLines,
16
+ });
17
+ }
18
+
19
+ return result;
20
+ };
package/lib/report.js CHANGED
@@ -2,24 +2,25 @@ import chalk from 'chalk';
2
2
  import {readFileSync} from 'fs';
3
3
 
4
4
  const {parse} = JSON;
5
+ const {entries} = Object;
5
6
 
6
7
  export const report = () => {
7
8
  const coverageFile = parse(readFileSync('./coverage.json', 'utf8'));
8
-
9
+
9
10
  const files = [];
10
11
  const coverage = {
11
12
  files,
12
13
  coveredCount: 0,
13
14
  uncoveredCount: 0,
14
15
  };
15
-
16
+
16
17
  console.log('# TAP version 13');
17
18
  console.log('');
18
-
19
+
19
20
  for (const {name, lines} of coverageFile) {
20
21
  const uncoveredLines = [];
21
22
 
22
- for (const [line, covered] of Object.entries(lines)) {
23
+ for (const [line, covered] of entries(lines)) {
23
24
  if (covered)
24
25
  continue;
25
26
 
@@ -40,7 +41,7 @@ export const report = () => {
40
41
 
41
42
  files.push(file);
42
43
  }
43
-
44
+
44
45
  for (const {name, covered, uncoveredLines} of files) {
45
46
  if (!covered) {
46
47
  console.log(`# ${name}`);
@@ -49,21 +50,21 @@ export const report = () => {
49
50
  console.log(`lines: ${chalk.red(uncoveredLines.join(','))}`);
50
51
  }
51
52
  }
52
-
53
+
53
54
  if (coverage.uncoveredCount)
54
55
  console.log('');
55
-
56
+
56
57
  console.log(`1..${files.length}`);
57
58
  console.log(`# files: ${files.length}`);
58
59
  console.log(`# covered: ${coverage.coveredCount}`);
59
-
60
+
60
61
  if (!coverage.uncoveredCount) {
61
62
  console.log('');
62
63
  console.log('# ☘️ ok');
63
64
  }
64
-
65
+
65
66
  if (coverage.uncoveredCount) {
66
67
  console.log(`# 🧨 fail: ${coverage.uncoveredCount}`);
67
68
  }
68
- }
69
+ };
69
70
 
package/lib/save.js CHANGED
@@ -1,26 +1,14 @@
1
1
  import {writeFileSync} from 'fs';
2
2
  import {getFiles} from './c4.js';
3
+ import {parse} from './parse.js';
4
+ import {merge} from './merge.js';
3
5
 
4
6
  const {stringify} = JSON;
5
7
 
6
8
  export const save = () => {
7
9
  const files = getFiles();
8
- const report = [];
9
- for (const [name, places] of files.entries()) {
10
- const lines = {};
11
- const current = {
12
- name,
13
- lines,
14
- };
15
- for (const [place, covered] of places.entries()) {
16
- const [line] = place.split(':');
17
-
18
- lines[line] = covered;
19
- }
20
-
21
- report.push(current);
22
- }
10
+ const parsed = parse(files);
11
+ const merged = merge(parsed);
23
12
 
24
- writeFileSync('./coverage.json', stringify(report, null, 4));
13
+ writeFileSync('./coverage.json', stringify(merged, null, 4));
25
14
  };
26
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "escover",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
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",