escover 1.3.4 → 1.5.1

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,27 @@
1
+ 2022.01.17, v1.5.1
2
+
3
+ feature:
4
+ - escover: add lines %
5
+
6
+
7
+ 2022.01.17, v1.5.0
8
+
9
+ feature:
10
+ - escover: add formatter table
11
+
12
+
13
+ 2022.01.15, v1.4.1
14
+
15
+ feature:
16
+ - escover: coverage -> coverage-file
17
+
18
+
19
+ 2022.01.15, v1.4.0
20
+
21
+ feature:
22
+ - escover: add ability to preserve fileEntries
23
+
24
+
1
25
  2022.01.15, v1.3.4
2
26
 
3
27
  fix:
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.js';
4
+ import {read} from '../lib/coverage-file.js';
5
5
 
6
6
  cli({
7
7
  argv: process.argv,
package/lib/c4.js CHANGED
@@ -1,17 +1,36 @@
1
- export const __fileEntries = new Map();
1
+ const noop = () => {};
2
2
 
3
+ global.__fileEntries = global.__fileEntries || new Map();
4
+
5
+ export const {__fileEntries} = global;
3
6
  export const createFileEntry = (url) => {
4
- const lines = __fileEntries.get(url) || new Map();
7
+ url = url.replace(/\?.*$/, '');
8
+ let lines = __fileEntries.get(url);
9
+
10
+ if (lines) {
11
+ return {
12
+ '🧨': set(lines),
13
+ 'init': noop,
14
+ };
15
+ }
16
+
17
+ lines = new Map();
18
+
5
19
  __fileEntries.set(url, lines);
6
20
 
7
21
  return {
8
- '🧨': (line, column) => {
9
- lines.set(`${line}:${column}`, true);
10
- },
11
- 'init': (line, column) => {
12
- lines.set(`${line}:${column}`, false);
13
- },
22
+ '🧨': set(lines),
23
+ 'init': init(lines),
14
24
  };
15
25
  };
16
26
 
27
+ const set = (lines) => (line, column) => {
28
+ lines.set(`${line}:${column}`, true);
29
+ };
30
+
31
+ const init = (lines) => (line, column) => {
32
+ lines.set(`${line}:${column}`, false);
33
+ };
34
+
17
35
  export const getFileEntries = () => __fileEntries;
36
+
package/lib/cli/cli.js CHANGED
@@ -3,17 +3,24 @@ import tryCatch from 'try-catch';
3
3
  import yargsParser from 'yargs-parser';
4
4
 
5
5
  import {version} from './version.js';
6
- import {report} from '../report.js';
6
+ import reportLines from '../formatters/lines.js';
7
+ import reportFiles from '../formatters/files.js';
7
8
 
8
9
  export const cli = ({argv, exit, read}) => {
9
10
  const args = yargsParser(argv.slice(2), {
11
+ string: [
12
+ 'format',
13
+ ],
10
14
  boolean: [
11
15
  'version',
12
16
  ],
13
17
  alias: {
14
18
  v: 'version',
19
+ f: 'format',
20
+ },
21
+ default: {
22
+ format: 'files',
15
23
  },
16
- configuration: {},
17
24
  });
18
25
 
19
26
  if (args.version) {
@@ -29,7 +36,10 @@ export const cli = ({argv, exit, read}) => {
29
36
 
30
37
  const coverage = read();
31
38
 
32
- report(coverage);
39
+ if (args.format === 'lines')
40
+ return reportLines(coverage);
41
+
42
+ reportFiles(coverage);
33
43
  };
34
44
 
35
45
  function execute(cmd, exit) {
@@ -23,6 +23,7 @@ export const write = () => {
23
23
  return;
24
24
 
25
25
  const parsed = transform(files);
26
+
26
27
  const merged = merge(parsed);
27
28
  const name = findCacheDir({
28
29
  name: NAME,
package/lib/exit.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import once from 'once';
2
- import {write} from './coverage.js';
2
+ import {write} from './coverage-file.js';
3
3
 
4
4
  export const exit = once(() => {
5
5
  write();
@@ -0,0 +1,90 @@
1
+ import {
2
+ table,
3
+ getBorderCharacters,
4
+ } from 'table';
5
+
6
+ import chalk from 'chalk';
7
+
8
+ const CWD = process.cwd();
9
+ const {
10
+ entries,
11
+ keys,
12
+ } = Object;
13
+
14
+ export default (coverageFile) => {
15
+ const files = parseCoverageFile(coverageFile);
16
+
17
+ const tableData = [
18
+ ['File', '% Lines', 'Uncovered Lines #s'],
19
+ ];
20
+
21
+ for (const {filename, covered, lines, percentLines} of files) {
22
+ const uncoveredLines = lines.join(', ');
23
+
24
+ if (covered) {
25
+ tableData.push([chalk.green(filename), chalk.green(percentLines), '']);
26
+ continue;
27
+ }
28
+
29
+ tableData.push([chalk.red(filename), chalk.red(percentLines), chalk.red(uncoveredLines)]);
30
+ }
31
+
32
+ process.stdout.write(table(tableData, {
33
+ drawHorizontalLine: (raw) => {
34
+ return !raw || raw === 1 || raw === files.length + 1;
35
+ },
36
+ columns: [{
37
+ paddingLeft: 0,
38
+ }],
39
+ border: {
40
+ ...getBorderCharacters('void'),
41
+ topBody: '-',
42
+ bottomBody: '-',
43
+ joinBody: '-',
44
+ topJoin: '|',
45
+ bottomJoin: '|',
46
+ joinJoin: '|',
47
+ bodyJoin: '|',
48
+ },
49
+ }));
50
+ };
51
+
52
+ function parseUncoveredLines(lines) {
53
+ const uncoveredLines = [];
54
+
55
+ for (const [line, covered] of entries(lines)) {
56
+ if (covered)
57
+ continue;
58
+
59
+ uncoveredLines.push(line);
60
+ }
61
+
62
+ return uncoveredLines;
63
+ }
64
+
65
+ function parseCoverageFile(coverageFile) {
66
+ const files = [];
67
+ for (const {name, lines} of coverageFile) {
68
+ const filename = name.replace(CWD + '/', '');
69
+ const uncoveredLines = parseUncoveredLines(lines);
70
+
71
+ const linesCount = keys(lines).length;
72
+ const percentLines = getPercentLines(linesCount, uncoveredLines);
73
+
74
+ files.push({
75
+ filename,
76
+ covered: !uncoveredLines.length,
77
+ lines: uncoveredLines,
78
+ percentLines,
79
+ });
80
+ }
81
+
82
+ return files;
83
+ }
84
+
85
+ function getPercentLines(linesCount, uncoveredLines) {
86
+ if (!linesCount)
87
+ return 100;
88
+
89
+ return 100 - Math.round(100 / linesCount * uncoveredLines.length);
90
+ }
@@ -1,7 +1,7 @@
1
1
  import chalk from 'chalk';
2
2
  const {entries} = Object;
3
3
 
4
- export const report = (coverageFile) => {
4
+ export default (coverageFile) => {
5
5
  const files = [];
6
6
  const coverage = {
7
7
  files,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "escover",
3
- "version": "1.3.4",
3
+ "version": "1.5.1",
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",
@@ -43,6 +43,7 @@
43
43
  "montag": "^1.2.1",
44
44
  "once": "^1.4.0",
45
45
  "putout": "^24.0.2",
46
+ "table": "^6.8.0",
46
47
  "try-catch": "^3.0.0",
47
48
  "yargs-parser": "^21.0.0",
48
49
  "zenload": "^1.4.0"