index.js 801 B

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. const { Session } = require('inspector');
  3. const { promisify } = require('util');
  4. class CoverageInstrumenter {
  5. constructor() {
  6. this.session = new Session();
  7. this.postSession = promisify(this.session.post.bind(this.session));
  8. }
  9. async startInstrumenting() {
  10. this.session.connect();
  11. await this.postSession('Profiler.enable');
  12. await this.postSession('Profiler.startPreciseCoverage', {
  13. callCount: true,
  14. detailed: true,
  15. });
  16. }
  17. async stopInstrumenting() {
  18. const {result} = await this.postSession(
  19. 'Profiler.takePreciseCoverage',
  20. );
  21. await this.postSession('Profiler.stopPreciseCoverage');
  22. await this.postSession('Profiler.disable');
  23. return result;
  24. }
  25. }
  26. module.exports.CoverageInstrumenter = CoverageInstrumenter;