in-memory-report.js 714 B

1234567891011121314151617181920212223242526272829
  1. const { ReportBase } = require('istanbul-lib-report')
  2. class InMemoryReport extends ReportBase {
  3. constructor (opt) {
  4. super(opt)
  5. this.opt = opt
  6. }
  7. onStart () {
  8. this.data = {}
  9. }
  10. onDetail (node) {
  11. const fc = node.getFileCoverage()
  12. const key = fc.path
  13. this.data[key] = fc.toJSON()
  14. }
  15. onEnd () {
  16. if (!this.opt || !this.opt.emitter || !this.opt.emitter.emit) {
  17. console.error('Could not raise "coverage_complete" event, missing emitter because it was not supplied during initialization of the reporter')
  18. return
  19. }
  20. this.opt.emitter.emit('coverage_complete', this.opt.browser, this.data)
  21. }
  22. }
  23. InMemoryReport.TYPE = 'in-memory'
  24. module.exports = InMemoryReport