escover 1.7.2 → 1.10.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,31 @@
1
+ 2022.01.19, v1.10.0
2
+
3
+ feature:
4
+ - escover: add .. when to many lines to display
5
+
6
+
7
+ 2022.01.19, v1.9.0
8
+
9
+ feature:
10
+ - escover: formatters: files: add ability to cut lines, when count more then 10
11
+ - escover: formatters returning a string
12
+
13
+
14
+ 2022.01.19, v1.8.1
15
+
16
+ fix:
17
+ - npmignore: add example
18
+
19
+
20
+ 2022.01.19, v1.8.0
21
+
22
+ fix:
23
+ - chore: instrument: rm useless fixture
24
+
25
+ feature:
26
+ - escover: when one of expressions lin line not covered - line not covered
27
+
28
+
1
29
  2022.01.18, v1.7.2
2
30
 
3
31
  feature:
package/README.md CHANGED
@@ -47,7 +47,7 @@ escover npm test
47
47
 
48
48
  ## Config
49
49
 
50
- `exclude` section of configuration file `.nyrc.json` supported.
50
+ `exclude` section of configuration file `.nyrc.json` supported.
51
51
 
52
52
  ## How it looks like?
53
53
 
package/bin/escover.js CHANGED
@@ -1,7 +1,7 @@
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 {read} from '../lib/coverage-file/coverage-file.js';
5
5
 
6
6
  cli({
7
7
  argv: process.argv,
package/lib/cli/cli.js CHANGED
@@ -38,10 +38,14 @@ export const cli = ({argv, exit, read}) => {
38
38
 
39
39
  const coverage = read();
40
40
 
41
+ let output = '';
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,12 @@
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 {getFileEntries} from '../c4.js';
7
+ import {transform} from '../transform.js';
8
+ import {merge} from '../merge.js';
9
+ import {findCacheDir} from './find-cache-dir.js';
10
10
 
11
11
  const {
12
12
  stringify,
@@ -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
+
package/lib/exit.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import once from 'once';
2
- import {write} from './coverage-file.js';
2
+ import {write} from './coverage-file/coverage-file.js';
3
3
 
4
4
  export const exit = once(() => {
5
5
  write();
@@ -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
 
package/lib/transform.js CHANGED
@@ -1,17 +1,13 @@
1
1
  const sort = (a) => new Map(Array.from(a.entries()).sort());
2
2
 
3
+ const isBool = (a) => typeof a === 'boolean';
4
+
3
5
  export const transform = (files) => {
4
6
  const result = [];
5
7
  const sorted = sort(files);
6
8
 
7
9
  for (const [rawName, places] of sorted.entries()) {
8
- const rawLines = {};
9
-
10
- for (const [place, covered] of places.entries()) {
11
- const [line] = place.split(':');
12
-
13
- rawLines[line] = covered;
14
- }
10
+ const rawLines = mergeLines(places);
15
11
 
16
12
  result.push({
17
13
  rawName,
@@ -22,3 +18,20 @@ export const transform = (files) => {
22
18
  return result;
23
19
  };
24
20
 
21
+ function mergeLines(places) {
22
+ const result = {};
23
+
24
+ for (const [place, covered] of places.entries()) {
25
+ const [line] = place.split(':');
26
+
27
+ if (isBool(result[line])) {
28
+ result[line] &= covered;
29
+ continue;
30
+ }
31
+
32
+ result[line] = covered;
33
+ }
34
+
35
+ return result;
36
+ }
37
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "escover",
3
- "version": "1.7.2",
3
+ "version": "1.10.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,21 +19,17 @@
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",
30
27
  "fix:lint": "madrun fix:lint",
31
28
  "report": "madrun report",
32
29
  "watcher": "madrun watcher",
33
- "watch:test": "madrun watch:test",
34
30
  "watch:lint": "madrun watch:lint",
35
31
  "watch:tape": "madrun watch:tape",
36
- "watch:coverage": "madrun watch:coverage"
32
+ "prewisdom": "madrun prewisdom"
37
33
  },
38
34
  "dependencies": {
39
35
  "chalk": "^5.0.0",
@@ -1,4 +0,0 @@
1
- export const sum = (a, b) => a + b;
2
-
3
- // export const mul = (a, b) => a * b;
4
-