forked from cenfun/monocart-coverage-reports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-node-cdp.js
77 lines (55 loc) · 2.1 KB
/
test-node-cdp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const EC = require('eight-colors');
const MCR = require('../');
const CDPClient = MCR.CDPClient;
const checkSnapshot = require('./check-snapshot.js');
const coverageOptions = {
// logging: 'debug',
// watermarks: [60, 90],
reports: ['v8', 'v8-json'],
name: 'My V8 Node cdp Coverage Report',
assetsPath: '../assets',
// lcov: true,
outputDir: './docs/node-cdp',
onEnd: function(coverageResults) {
checkSnapshot(coverageResults);
}
};
const addV8Coverage = async (coverageReport, coverageList) => {
if (!coverageList) {
console.log('failed to take coverage data');
return;
}
// filter node internal files
coverageList = coverageList.filter((entry) => entry.url && entry.url.startsWith('file:'));
// console.log(coverageList);
coverageList = coverageList.filter((entry) => entry.url.includes('test/mock/node'));
if (!coverageList.length) {
return;
}
console.log('add node.js cdp coverage ...');
await coverageReport.add(coverageList);
};
const generate = async () => {
// clean cache first
const coverageReport = MCR(coverageOptions);
coverageReport.cleanCache();
// =====================================================
// after webServer is debugging on ws://127.0.0.1:9229
// connect to the server with Chrome Devtools Protocol
const client = await CDPClient({
port: 9229
});
await client.startJSCoverage();
// =====================================================
require('./specs/node.test.js');
// =====================================================
const coverageData = await client.stopJSCoverage();
// console.log('check source', coverageList.filter((it) => !it.source).map((it) => [it.scriptId, it.url]));
// console.log(coverageList.map((it) => it.url));
await addV8Coverage(coverageReport, coverageData);
// await client.Profiler.disable();
await client.close();
const coverageResults = await coverageReport.generate();
console.log('test-node-cdp coverage reportPath', EC.magenta(coverageResults.reportPath));
};
generate();