escover 1.0.0 → 1.0.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 +5 -0
- package/coverage.json +9 -1
- package/lib/c4.js +12 -31
- package/lib/escover.js +37 -0
- package/lib/exit.js +9 -0
- package/lib/report.js +67 -15
- package/lib/save.js +3 -4
- package/package.json +1 -4
- package/bin/c4.js +0 -69
package/coverage.json
CHANGED
package/lib/c4.js
CHANGED
|
@@ -1,36 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import process from 'process';
|
|
3
|
-
import {instrument} from './instrument/index.js';
|
|
4
|
-
import {exclude} from './exclude.js';
|
|
5
|
-
import {save} from './save.js';
|
|
6
|
-
import {createFileEntry} from './report.js';
|
|
1
|
+
const files = new Map();
|
|
7
2
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const {format, source: rawSource} = await defaultLoad(url, context, defaultLoad);
|
|
12
|
-
|
|
13
|
-
if (/commonjs|builtin/.test(format))
|
|
14
|
-
return {
|
|
15
|
-
format,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
if (exclude(url, ['.spec.js', 'node_modules']))
|
|
19
|
-
return {
|
|
20
|
-
format,
|
|
21
|
-
source: rawSource,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const source = montag`
|
|
25
|
-
const __c4 = global.__createC4('${url}');
|
|
26
|
-
${instrument(url, rawSource)}
|
|
27
|
-
`;
|
|
3
|
+
export const createFileEntry = (url) => {
|
|
4
|
+
const lines = files.get(url) || new Map();
|
|
5
|
+
files.set(url, lines);
|
|
28
6
|
|
|
29
7
|
return {
|
|
30
|
-
|
|
31
|
-
|
|
8
|
+
mark: (line, column) => {
|
|
9
|
+
lines.set(`${line}:${column}`, true);
|
|
10
|
+
},
|
|
11
|
+
init: (line, column) => {
|
|
12
|
+
lines.set(`${line}:${column}`, false);
|
|
13
|
+
},
|
|
32
14
|
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
process.once('exit', save);
|
|
15
|
+
};
|
|
36
16
|
|
|
17
|
+
export const getFiles = () => files;
|
package/lib/escover.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import montag from 'montag';
|
|
2
|
+
import process from 'process';
|
|
3
|
+
|
|
4
|
+
import {instrument} from './instrument/index.js';
|
|
5
|
+
import {exclude} from './exclude.js';
|
|
6
|
+
import {exit} from './exit.js';
|
|
7
|
+
import {createFileEntry} from './c4.js';
|
|
8
|
+
|
|
9
|
+
global.__createC4 = createFileEntry;
|
|
10
|
+
|
|
11
|
+
export async function load(url, context, defaultLoad) {
|
|
12
|
+
const {format, source: rawSource} = await defaultLoad(url, context, defaultLoad);
|
|
13
|
+
|
|
14
|
+
if (/commonjs|builtin/.test(format))
|
|
15
|
+
return {
|
|
16
|
+
format,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
if (exclude(url, ['.spec.js', 'node_modules']))
|
|
20
|
+
return {
|
|
21
|
+
format,
|
|
22
|
+
source: rawSource,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const source = montag`
|
|
26
|
+
const __c4 = global.__createC4('${url}');
|
|
27
|
+
${instrument(url, rawSource)}
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
format,
|
|
32
|
+
source,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
process.once('exit', exit);
|
|
37
|
+
|
package/lib/exit.js
ADDED
package/lib/report.js
CHANGED
|
@@ -1,17 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import {readFileSync} from 'fs';
|
|
3
|
+
|
|
4
|
+
const {parse} = JSON;
|
|
5
|
+
|
|
6
|
+
export const report = () => {
|
|
7
|
+
const coverageFile = parse(readFileSync('./coverage.json', 'utf8'));
|
|
8
|
+
|
|
9
|
+
const files = [];
|
|
10
|
+
const coverage = {
|
|
11
|
+
files,
|
|
12
|
+
coveredCount: 0,
|
|
13
|
+
uncoveredCount: 0,
|
|
14
14
|
};
|
|
15
|
-
};
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
console.log('# TAP version 13');
|
|
17
|
+
console.log('');
|
|
18
|
+
|
|
19
|
+
for (const {name, lines} of coverageFile) {
|
|
20
|
+
const uncoveredLines = [];
|
|
21
|
+
|
|
22
|
+
for (const [line, covered] of Object.entries(lines)) {
|
|
23
|
+
if (covered)
|
|
24
|
+
continue;
|
|
25
|
+
|
|
26
|
+
uncoveredLines.push(line);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const file = {
|
|
30
|
+
name,
|
|
31
|
+
covered: !uncoveredLines.length,
|
|
32
|
+
uncoveredLines,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
if (file.covered)
|
|
36
|
+
++coverage.coveredCount;
|
|
37
|
+
|
|
38
|
+
if (!file.covered)
|
|
39
|
+
++coverage.uncoveredCount;
|
|
40
|
+
|
|
41
|
+
files.push(file);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for (const {name, covered, uncoveredLines} of files) {
|
|
45
|
+
if (!covered) {
|
|
46
|
+
console.log(`# ${name}`);
|
|
47
|
+
console.log('❌ should be covered');
|
|
48
|
+
console.log('---');
|
|
49
|
+
console.log(`lines: ${chalk.red(uncoveredLines.join(','))}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (coverage.uncoveredCount)
|
|
54
|
+
console.log('');
|
|
55
|
+
|
|
56
|
+
console.log(`1..${files.length}`);
|
|
57
|
+
console.log(`# files: ${files.length}`);
|
|
58
|
+
console.log(`# covered: ${coverage.coveredCount}`);
|
|
59
|
+
|
|
60
|
+
if (!coverage.uncoveredCount) {
|
|
61
|
+
console.log('');
|
|
62
|
+
console.log('# ☘️ ok');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (coverage.uncoveredCount) {
|
|
66
|
+
console.log(`# 🧨 fail: ${coverage.uncoveredCount}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
package/lib/save.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {writeFileSync} from 'fs';
|
|
2
|
-
import
|
|
3
|
-
import {getFiles} from './report.js';
|
|
2
|
+
import {getFiles} from './c4.js';
|
|
4
3
|
|
|
5
4
|
const {stringify} = JSON;
|
|
6
5
|
|
|
7
|
-
export const save =
|
|
6
|
+
export const save = () => {
|
|
8
7
|
const files = getFiles();
|
|
9
8
|
const report = [];
|
|
10
9
|
for (const [name, places] of files.entries()) {
|
|
@@ -23,5 +22,5 @@ export const save = once(() => {
|
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
writeFileSync('./coverage.json', stringify(report, null, 4));
|
|
26
|
-
}
|
|
25
|
+
};
|
|
27
26
|
|
package/package.json
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "escover",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.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",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"bin": {
|
|
9
|
-
"escover": "bin/escover.js"
|
|
10
|
-
},
|
|
11
8
|
"repository": {
|
|
12
9
|
"type": "git",
|
|
13
10
|
"url": "git://github.com/coderaiser/escover.git"
|
package/bin/c4.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
|
|
5
|
-
import {readFileSync} from 'fs';
|
|
6
|
-
|
|
7
|
-
const {parse} = JSON;
|
|
8
|
-
const coverageFile = parse(readFileSync('./coverage.json', 'utf8'));
|
|
9
|
-
|
|
10
|
-
const files = [];
|
|
11
|
-
const coverage = {
|
|
12
|
-
files,
|
|
13
|
-
coveredCount: 0,
|
|
14
|
-
uncoveredCount: 0,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
console.log('# TAP version 13');
|
|
18
|
-
console.log('');
|
|
19
|
-
|
|
20
|
-
for (const {name, lines} of coverageFile) {
|
|
21
|
-
const uncoveredLines = [];
|
|
22
|
-
|
|
23
|
-
for (const [line, covered] of Object.entries(lines)) {
|
|
24
|
-
if (covered)
|
|
25
|
-
continue;
|
|
26
|
-
|
|
27
|
-
uncoveredLines.push(line);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const file = {
|
|
31
|
-
name,
|
|
32
|
-
covered: !uncoveredLines.length,
|
|
33
|
-
uncoveredLines,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
if (file.covered)
|
|
37
|
-
++coverage.coveredCount;
|
|
38
|
-
|
|
39
|
-
if (!file.covered)
|
|
40
|
-
++coverage.uncoveredCount;
|
|
41
|
-
|
|
42
|
-
files.push(file);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
for (const {name, covered, uncoveredLines} of files) {
|
|
46
|
-
if (!covered) {
|
|
47
|
-
console.log(`# ${name}`);
|
|
48
|
-
console.log('❌ should be covered');
|
|
49
|
-
console.log('---');
|
|
50
|
-
console.log(`lines: ${chalk.red(uncoveredLines.join(','))}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (coverage.uncoveredCount)
|
|
55
|
-
console.log('');
|
|
56
|
-
|
|
57
|
-
console.log(`1..${files.length}`);
|
|
58
|
-
console.log(`# files: ${files.length}`);
|
|
59
|
-
console.log(`# covered: ${coverage.coveredCount}`);
|
|
60
|
-
|
|
61
|
-
if (!coverage.uncoveredCount) {
|
|
62
|
-
console.log('');
|
|
63
|
-
console.log('# ☘️ ok');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (coverage.uncoveredCount) {
|
|
67
|
-
console.log(`# 🧨 fail: ${coverage.uncoveredCount}`);
|
|
68
|
-
}
|
|
69
|
-
|