build-self-coverage.js 594 B

12345678910111213141516171819202122
  1. var istanbul = require('istanbul-lib-instrument')
  2. var fs = require('fs')
  3. var path = require('path')
  4. ;[
  5. 'index.js',
  6. 'lib/process.js'
  7. ].forEach(function (name) {
  8. var indexPath = path.join(__dirname, name)
  9. var source = fs.readFileSync(indexPath, 'utf8')
  10. var instrumentor = istanbul.createInstrumenter({
  11. coverageVariable: '___NYC_SELF_COVERAGE___',
  12. esModules: true
  13. })
  14. var instrumentedSource = instrumentor.instrumentSync(source, indexPath)
  15. var outputPath = path.join(__dirname, name.replace(/\.js$/, '.covered.js'))
  16. fs.writeFileSync(outputPath, instrumentedSource)
  17. })