-
Notifications
You must be signed in to change notification settings - Fork 6
/
test-node-api.js
66 lines (47 loc) · 1.47 KB
/
test-node-api.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
const fs = require('fs');
const v8 = require('v8');
const EC = require('eight-colors');
const MCR = require('../');
const checkSnapshot = require('./check-snapshot.js');
const dir = process.env.NODE_V8_COVERAGE;
const coverageOptions = {
// logging: 'debug',
// watermarks: [60, 90],
reports: ['v8'],
name: 'My V8 Node api Coverage Report',
assetsPath: '../assets',
// lcov: true,
dataDir: dir,
entryFilter: {
'**/test/mock/node/**': true
},
outputDir: './docs/node-api',
onEnd: function(coverageResults) {
checkSnapshot(coverageResults);
}
};
const generate = async () => {
const coverageReport = MCR(coverageOptions);
// clean cache before add coverage data
coverageReport.cleanCache();
const coverageResults = await coverageReport.generate();
console.log('test-node-api coverage reportPath', EC.magenta(coverageResults.reportPath));
};
const main = async () => {
// remove previous coverage files
if (fs.existsSync(dir)) {
fs.rmSync(dir, {
recursive: true,
force: true
});
console.log(`removed previous: ${dir}`);
}
// =====================================================
require('./specs/node.test.js');
// =====================================================
v8.takeCoverage();
// stop will cased ''result' from coverage profile response is not an object'
// v8.stopCoverage();
await generate();
};
main();