escover 1.12.0 โ†’ 1.13.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,11 @@
1
+ 2022.01.20, v1.13.0
2
+
3
+ feature:
4
+ - escover: add ability to read lcov
5
+ - coverage-file: add ability to parse lcov
6
+ - escover: mark: add support of break
7
+
8
+
1
9
  2022.01.19, v1.12.0
2
10
 
3
11
  feature:
package/README.md CHANGED
@@ -31,7 +31,11 @@ which are needed to load module again, and apply mocks.
31
31
 
32
32
  ### ๐Ÿคทโ€ How to get coverage when mocks are used?
33
33
 
34
- โ˜๏ธ Use ๐ŸŽฉ `ESCover`! It supports loaders, `ESM` and collects coverage as a loader!
34
+ โ˜๏ธ Use ๐ŸŽฉ`ESCover`! It supports loaders, `ESM` and collects coverage as a loader!
35
+
36
+ ### ๐Ÿคทโ€ What with [`coveralls`](https://coveralls.io/)? Does [`lcov`](https://github.com/StevenLooman/mocha-lcov-reporter) supported?
37
+
38
+ โ˜๏ธ Sure! `coverage/lcov.info` is main coverage file for ๐ŸŽฉ`ESCover`.
35
39
 
36
40
  ## Install
37
41
 
@@ -55,6 +59,15 @@ When everything is covered:
55
59
 
56
60
  ![image](https://user-images.githubusercontent.com/1573141/149822261-ff9bc3b4-6ee4-452c-9ada-3cc922b630ec.png)
57
61
 
62
+ ## What formatters exists?
63
+
64
+ There is two types of formatters:
65
+
66
+ - `lines` adds links to each line;
67
+ - `files` shows information in table;
68
+
69
+ You can choose formatter with `ESCOVER_FORMAT` env variable.
70
+
58
71
  ## What if I want to use ๐ŸŽฉ`ESCover` with `mock-import`?
59
72
 
60
73
  Experimental `loaders` supports only one, for now. So [zenload](https://github.com/coderaiser/zenload) should be used.
@@ -8,15 +8,13 @@ import {getFileEntries} from '../c4.js';
8
8
  import {transform} from '../transform.js';
9
9
  import {merge} from '../merge.js';
10
10
  import {findCacheDir} from './find-cache-dir.js';
11
- import {createLcov} from './lcov.js';
12
-
13
- const {
14
- stringify,
15
- parse,
16
- } = JSON;
11
+ import {
12
+ generateLcov,
13
+ parseLcov,
14
+ } from './lcov.js';
17
15
 
18
16
  const NAME = 'escover';
19
- const buildName = (a) => `${a}/${NAME}.json`;
17
+ const LCOV = 'lcov.info';
20
18
 
21
19
  export const writeCoverage = () => {
22
20
  const files = getFileEntries();
@@ -26,27 +24,26 @@ export const writeCoverage = () => {
26
24
 
27
25
  const parsed = transform(files);
28
26
  const merged = merge(parsed);
29
- const lcov = createLcov(merged);
27
+ const lcov = generateLcov(merged);
30
28
 
31
29
  const dir = findCacheDir({
32
30
  name: NAME,
33
31
  create: true,
34
32
  });
35
33
 
36
- writeFileSync(join(dir, 'lcov.info'), lcov);
37
- writeFileSync(buildName(dir), stringify(merged, null, 4));
34
+ writeFileSync(join(dir, LCOV), lcov);
38
35
  };
39
36
 
40
37
  export const readCoverage = () => {
41
- const name = findCacheDir({
38
+ const dir = findCacheDir({
42
39
  name: NAME,
43
40
  });
44
41
 
45
- const [error, data] = tryCatch(readFileSync, buildName(name), 'utf8');
42
+ const [error, data] = tryCatch(readFileSync, join(dir, LCOV), 'utf8');
46
43
 
47
44
  if (error)
48
45
  return [];
49
46
 
50
- return parse(data);
47
+ return parseLcov(data);
51
48
  };
52
49
 
@@ -1,6 +1,6 @@
1
1
  const {entries} = Object;
2
2
 
3
- export const createLcov = (files) => {
3
+ export const generateLcov = (files) => {
4
4
  const result = [];
5
5
 
6
6
  for (const {name, lines} of files) {
@@ -9,9 +9,44 @@ export const createLcov = (files) => {
9
9
  const count = covered ? 1 : 0;
10
10
  result.push(`DA:${line},${count}`);
11
11
  }
12
+
13
+ result.push('end_of_record');
12
14
  }
13
15
 
14
- result.push('end_of_record');
15
-
16
16
  return result.join('\n');
17
17
  };
18
+
19
+ const isEnd = (a) => a === 'end_of_record';
20
+
21
+ export const parseLcov = (lcov) => {
22
+ const files = [];
23
+ let name = '';
24
+ let lines = {};
25
+
26
+ for (const current of lcov.split('\n')) {
27
+ const [cmd, arg] = current.split(':');
28
+
29
+ if (cmd === 'SF') {
30
+ name = arg;
31
+ lines = {};
32
+ continue;
33
+ }
34
+
35
+ if (cmd === 'DA') {
36
+ const [line, covered] = arg.split(',');
37
+ lines[line] = Boolean(Number(covered));
38
+ continue;
39
+ }
40
+
41
+ if (isEnd(cmd)) {
42
+ files.push({
43
+ name,
44
+ lines,
45
+ });
46
+ continue;
47
+ }
48
+ }
49
+
50
+ return files;
51
+ };
52
+
@@ -7,7 +7,6 @@ import {
7
7
  import {addMarkToReturn} from './return.js';
8
8
  import {addMarkToArrowFunction} from './arrow.js';
9
9
  import {addMarkToThrow} from './throw.js';
10
- import {addMarkToContinue} from './continue.js';
11
10
 
12
11
  const {
13
12
  NumericLiteral,
@@ -19,6 +18,7 @@ const {
19
18
  replaceWith,
20
19
  compareAny,
21
20
  compare,
21
+ replaceWithMultiple,
22
22
  } = operator;
23
23
 
24
24
  const LINE = `__c4['๐Ÿงจ'](__l, __c)`;
@@ -102,8 +102,11 @@ export const fix = (path, {options}) => {
102
102
  if (path.isThrowStatement())
103
103
  return addMarkToThrow(path, lineNode);
104
104
 
105
- if (path.isContinueStatement())
106
- return addMarkToContinue(path, lineNode);
105
+ if (path.isContinueStatement() || path.isBreakStatement())
106
+ return replaceWithMultiple(path, [
107
+ lineNode,
108
+ path.node,
109
+ ]);
107
110
 
108
111
  replaceWith(path, BlockStatement([
109
112
  node,
@@ -140,7 +143,7 @@ export const traverse = ({push}) => ({
140
143
 
141
144
  push(path);
142
145
  },
143
- ContinueStatement(path) {
146
+ 'ContinueStatement|BreakStatement'(path) {
144
147
  if (!path.parentPath.isBlockStatement())
145
148
  return;
146
149
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "escover",
3
- "version": "1.12.0",
3
+ "version": "1.13.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,10 +0,0 @@
1
- import {operator} from 'putout';
2
- const {replaceWithMultiple} = operator;
3
-
4
- export const addMarkToContinue = (path, lineNode) => {
5
- return replaceWithMultiple(path, [
6
- lineNode,
7
- path.node,
8
- ]);
9
- };
10
-