escover 1.8.1 → 1.12.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,29 @@
1
+ 2022.01.19, v1.12.0
2
+
3
+ feature:
4
+ - escover: add lcov support
5
+
6
+
7
+ 2022.01.19, v1.11.0
8
+
9
+ feature:
10
+ - escover: mark: add support of continue
11
+ - escover: coverage-file: read -> readCoverage
12
+
13
+
14
+ 2022.01.19, v1.10.0
15
+
16
+ feature:
17
+ - escover: add .. when to many lines to display
18
+
19
+
20
+ 2022.01.19, v1.9.0
21
+
22
+ feature:
23
+ - escover: formatters: files: add ability to cut lines, when count more then 10
24
+ - escover: formatters returning a string
25
+
26
+
1
27
  2022.01.19, v1.8.1
2
28
 
3
29
  fix:
package/bin/escover.js CHANGED
@@ -1,11 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import {cli} from '../lib/cli/cli.js';
4
- import {read} from '../lib/coverage-file.js';
4
+ import {readCoverage} from '../lib/coverage-file/coverage-file.js';
5
+ import {readConfig} from '../lib/config.js';
5
6
 
6
7
  cli({
7
8
  argv: process.argv,
8
9
  exit: process.exit,
9
- read,
10
+ readCoverage,
11
+ readConfig,
10
12
  });
11
13
 
package/lib/cli/cli.js CHANGED
@@ -8,7 +8,7 @@ import reportFiles from '../formatters/files.js';
8
8
 
9
9
  const {ESCOVER_FORMAT, NODE_OPTIONS = ''} = process.env;
10
10
 
11
- export const cli = ({argv, exit, read}) => {
11
+ export const cli = ({argv, exit, readCoverage}) => {
12
12
  const args = yargsParser(argv.slice(2), {
13
13
  string: [
14
14
  'format',
@@ -36,12 +36,16 @@ export const cli = ({argv, exit, read}) => {
36
36
  execute('"' + cmd.join(`" "`) + '"', exit);
37
37
  }
38
38
 
39
- const coverage = read();
39
+ const coverage = readCoverage();
40
+
41
+ let output = '';
40
42
 
41
43
  if (args.format === 'lines')
42
- return reportLines(coverage);
44
+ output = reportLines(coverage);
45
+ else
46
+ output = reportFiles(coverage);
43
47
 
44
- reportFiles(coverage);
48
+ process.stdout.write(output);
45
49
  };
46
50
 
47
51
  function execute(cmd, exit) {
@@ -1,12 +1,14 @@
1
- import tryCatch from 'try-catch';
2
1
  import {
3
2
  writeFileSync,
4
3
  readFileSync,
5
4
  } 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';
5
+ import tryCatch from 'try-catch';
6
+ import {join} from 'path';
7
+ import {getFileEntries} from '../c4.js';
8
+ import {transform} from '../transform.js';
9
+ import {merge} from '../merge.js';
10
+ import {findCacheDir} from './find-cache-dir.js';
11
+ import {createLcov} from './lcov.js';
10
12
 
11
13
  const {
12
14
  stringify,
@@ -16,24 +18,26 @@ const {
16
18
  const NAME = 'escover';
17
19
  const buildName = (a) => `${a}/${NAME}.json`;
18
20
 
19
- export const write = () => {
21
+ export const writeCoverage = () => {
20
22
  const files = getFileEntries();
21
23
 
22
24
  if (!files.size)
23
25
  return;
24
26
 
25
27
  const parsed = transform(files);
26
-
27
28
  const merged = merge(parsed);
28
- const name = findCacheDir({
29
+ const lcov = createLcov(merged);
30
+
31
+ const dir = findCacheDir({
29
32
  name: NAME,
30
33
  create: true,
31
34
  });
32
35
 
33
- writeFileSync(buildName(name), stringify(merged, null, 4));
36
+ writeFileSync(join(dir, 'lcov.info'), lcov);
37
+ writeFileSync(buildName(dir), stringify(merged, null, 4));
34
38
  };
35
39
 
36
- export const read = () => {
40
+ export const readCoverage = () => {
37
41
  const name = findCacheDir({
38
42
  name: NAME,
39
43
  });
@@ -0,0 +1,14 @@
1
+ import {join} from 'path';
2
+ import {cwd} from 'process';
3
+ import {mkdirSync} from 'fs';
4
+
5
+ export function findCacheDir() {
6
+ const name = join(cwd(), 'coverage');
7
+
8
+ mkdirSync(name, {
9
+ recursive: true,
10
+ });
11
+
12
+ return name;
13
+ }
14
+
@@ -0,0 +1,17 @@
1
+ const {entries} = Object;
2
+
3
+ export const createLcov = (files) => {
4
+ const result = [];
5
+
6
+ for (const {name, lines} of files) {
7
+ result.push(`SF:${name}`);
8
+ for (const [line, covered] of entries(lines)) {
9
+ const count = covered ? 1 : 0;
10
+ result.push(`DA:${line},${count}`);
11
+ }
12
+ }
13
+
14
+ result.push('end_of_record');
15
+
16
+ return result.join('\n');
17
+ };
package/lib/exit.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import once from 'once';
2
- import {write} from './coverage-file.js';
2
+ import {writeCoverage} from './coverage-file/coverage-file.js';
3
3
 
4
4
  export const exit = once(() => {
5
- write();
5
+ writeCoverage();
6
6
  });
@@ -19,7 +19,7 @@ export default (coverageFile) => {
19
19
  ];
20
20
 
21
21
  for (const {filename, covered, lines, percentLines} of files) {
22
- const uncoveredLines = lines.join(', ');
22
+ const uncoveredLines = formatLines(lines);
23
23
 
24
24
  if (covered) {
25
25
  tableData.push([chalk.green(filename), chalk.green(percentLines), '']);
@@ -29,7 +29,7 @@ export default (coverageFile) => {
29
29
  tableData.push([chalk.red(filename), chalk.red(percentLines), chalk.red(uncoveredLines)]);
30
30
  }
31
31
 
32
- process.stdout.write(table(tableData, {
32
+ return table(tableData, {
33
33
  drawHorizontalLine: (raw) => {
34
34
  return !raw || raw === 1 || raw === files.length + 1;
35
35
  },
@@ -46,9 +46,19 @@ export default (coverageFile) => {
46
46
  joinJoin: '|',
47
47
  bodyJoin: '|',
48
48
  },
49
- }));
49
+ });
50
50
  };
51
51
 
52
+ export function formatLines(array) {
53
+ const lines = array.slice(0, 10).join(', ');
54
+
55
+ if (array.length <= 10)
56
+ return lines;
57
+
58
+ const latest = array[array.length - 1];
59
+ return `${lines}..${latest}`;
60
+ }
61
+
52
62
  function parseUncoveredLines(lines) {
53
63
  const uncoveredLines = [];
54
64
 
@@ -69,11 +79,12 @@ function parseCoverageFile(coverageFile) {
69
79
  const uncoveredLines = parseUncoveredLines(lines);
70
80
 
71
81
  const linesCount = keys(lines).length;
72
- const percentLines = getPercentLines(linesCount, uncoveredLines);
82
+ const uncoveredLinesCount = uncoveredLines.length;
83
+ const percentLines = getLinesPercent(linesCount, uncoveredLinesCount);
73
84
 
74
85
  files.push({
75
86
  filename,
76
- covered: !uncoveredLines.length,
87
+ covered: !uncoveredLinesCount,
77
88
  lines: uncoveredLines,
78
89
  percentLines,
79
90
  });
@@ -82,9 +93,9 @@ function parseCoverageFile(coverageFile) {
82
93
  return files;
83
94
  }
84
95
 
85
- function getPercentLines(linesCount, uncoveredLines) {
96
+ export function getLinesPercent(linesCount, uncoveredLinesCount) {
86
97
  if (!linesCount)
87
98
  return 100;
88
99
 
89
- return 100 - Math.round(100 / linesCount * uncoveredLines.length);
100
+ return 100 - Math.round(100 / linesCount * uncoveredLinesCount);
90
101
  }
@@ -1,7 +1,10 @@
1
1
  import chalk from 'chalk';
2
2
  const {entries} = Object;
3
3
 
4
+ const createOut = (output) => (a) => output.push(a);
4
5
  export default (coverageFile) => {
6
+ const output = [];
7
+ const out = createOut(output);
5
8
  const files = [];
6
9
  const coverage = {
7
10
  files,
@@ -9,8 +12,8 @@ export default (coverageFile) => {
9
12
  uncoveredCount: 0,
10
13
  };
11
14
 
12
- console.log('# CAP version 13');
13
- console.log('');
15
+ out('# CAP version 13');
16
+ out('');
14
17
 
15
18
  for (const {name, lines} of coverageFile) {
16
19
  const uncoveredLines = [];
@@ -39,31 +42,33 @@ export default (coverageFile) => {
39
42
 
40
43
  for (const {name, covered, uncoveredLines} of files) {
41
44
  if (!covered) {
42
- console.log(`# ${name}`);
43
- console.log('🧨 should be covered');
44
- console.log('---');
45
- console.log(`lines:`);
45
+ out(`# ${name}`);
46
+ out('🧨 should be covered');
47
+ out('---');
48
+ out(`lines:`);
46
49
  for (const line of uncoveredLines) {
47
- console.log(`️- ${chalk.red(line)} at file://${name}:${line}`);
50
+ out(`️- ${chalk.red(line)} at file://${name}:${line}`);
48
51
  }
49
- console.log('');
52
+ out('');
50
53
  }
51
54
  }
52
55
 
53
- console.log(`1..${files.length}`);
54
- console.log(`# files: ${files.length}`);
55
- console.log(`# covered: ${coverage.coveredCount}`);
56
+ out(`1..${files.length}`);
57
+ out(`# files: ${files.length}`);
58
+ out(`# covered: ${coverage.coveredCount}`);
56
59
 
57
- console.log('');
60
+ out('');
58
61
 
59
62
  if (!coverage.uncoveredCount) {
60
- console.log('#️ 🌴 ok');
63
+ out('#️ 🌴 ok');
61
64
  }
62
65
 
63
66
  if (coverage.uncoveredCount) {
64
- console.log(`# 🧨 fail: ${coverage.uncoveredCount}`);
67
+ out(`# 🧨 fail: ${coverage.uncoveredCount}`);
65
68
  }
66
69
 
67
- console.log('');
70
+ out('');
71
+
72
+ return output.join('\n');
68
73
  };
69
74
 
@@ -0,0 +1,10 @@
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
+
@@ -3,9 +3,11 @@ import {
3
3
  types,
4
4
  operator,
5
5
  } from 'putout';
6
+
6
7
  import {addMarkToReturn} from './return.js';
7
8
  import {addMarkToArrowFunction} from './arrow.js';
8
9
  import {addMarkToThrow} from './throw.js';
10
+ import {addMarkToContinue} from './continue.js';
9
11
 
10
12
  const {
11
13
  NumericLiteral,
@@ -16,6 +18,7 @@ const {
16
18
  const {
17
19
  replaceWith,
18
20
  compareAny,
21
+ compare,
19
22
  } = operator;
20
23
 
21
24
  const LINE = `__c4['🧨'](__l, __c)`;
@@ -93,13 +96,15 @@ export const fix = (path, {options}) => {
93
96
  if (path.isReturnStatement())
94
97
  return addMarkToReturn(path, lineNode);
95
98
 
96
- if (path.isArrowFunctionExpression()) {
99
+ if (path.isArrowFunctionExpression())
97
100
  return addMarkToArrowFunction(path, lineNode);
98
- }
99
101
 
100
102
  if (path.isThrowStatement())
101
103
  return addMarkToThrow(path, lineNode);
102
104
 
105
+ if (path.isContinueStatement())
106
+ return addMarkToContinue(path, lineNode);
107
+
103
108
  replaceWith(path, BlockStatement([
104
109
  node,
105
110
  ]));
@@ -135,6 +140,17 @@ export const traverse = ({push}) => ({
135
140
 
136
141
  push(path);
137
142
  },
143
+ ContinueStatement(path) {
144
+ if (!path.parentPath.isBlockStatement())
145
+ return;
146
+
147
+ const {body} = path.parentPath.node;
148
+
149
+ if (compare(body[0], LINE))
150
+ return;
151
+
152
+ push(path);
153
+ },
138
154
  LogicalExpression(path) {
139
155
  if (compareAny(path.get('left'), EXCLUDE))
140
156
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "escover",
3
- "version": "1.8.1",
3
+ "version": "1.12.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",
@@ -19,11 +19,8 @@
19
19
  "loader"
20
20
  ],
21
21
  "scripts": {
22
- "loader": "madrun loader",
23
22
  "test": "madrun test",
24
- "test:only": "madrun test:only",
25
23
  "coverage": "madrun coverage",
26
- "c4": "madrun c4",
27
24
  "lint": "madrun lint",
28
25
  "fresh:lint": "madrun fresh:lint",
29
26
  "lint:fresh": "madrun lint:fresh",
@@ -33,7 +30,7 @@
33
30
  "watch:test": "madrun watch:test",
34
31
  "watch:lint": "madrun watch:lint",
35
32
  "watch:tape": "madrun watch:tape",
36
- "watch:coverage": "madrun watch:coverage"
33
+ "prewisdom": "madrun prewisdom"
37
34
  },
38
35
  "dependencies": {
39
36
  "chalk": "^5.0.0",
@@ -44,6 +41,7 @@
44
41
  "once": "^1.4.0",
45
42
  "picomatch": "^2.3.1",
46
43
  "putout": "^24.0.2",
44
+ "strip-ansi": "^7.0.1",
47
45
  "table": "^6.8.0",
48
46
  "try-catch": "^3.0.0",
49
47
  "yargs-parser": "^21.0.0",