self-coverage-helper.js 565 B

123456789101112131415161718192021
  1. /* global ___NYC_SELF_COVERAGE___ */
  2. const path = require('path')
  3. const fs = require('fs')
  4. const mkdirp = require('mkdirp')
  5. const onExit = require('signal-exit')
  6. onExit(function () {
  7. var coverage = global.___NYC_SELF_COVERAGE___
  8. if (typeof ___NYC_SELF_COVERAGE___ === 'object') coverage = ___NYC_SELF_COVERAGE___
  9. if (!coverage) return
  10. var selfCoverageDir = path.join(__dirname, '../.self_coverage')
  11. mkdirp.sync(selfCoverageDir)
  12. fs.writeFileSync(
  13. path.join(selfCoverageDir, process.pid + '.json'),
  14. JSON.stringify(coverage),
  15. 'utf-8'
  16. )
  17. })