index.js
801 Bytes
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
'use strict';
const { Session } = require('inspector');
const { promisify } = require('util');
class CoverageInstrumenter {
constructor() {
this.session = new Session();
this.postSession = promisify(this.session.post.bind(this.session));
}
async startInstrumenting() {
this.session.connect();
await this.postSession('Profiler.enable');
await this.postSession('Profiler.startPreciseCoverage', {
callCount: true,
detailed: true,
});
}
async stopInstrumenting() {
const {result} = await this.postSession(
'Profiler.takePreciseCoverage',
);
await this.postSession('Profiler.stopPreciseCoverage');
await this.postSession('Profiler.disable');
return result;
}
}
module.exports.CoverageInstrumenter = CoverageInstrumenter;