Add run script to generate instrumented code coverage .asar
This commit is contained in:
parent
5b5d51ecf4
commit
e17e195479
2 changed files with 32 additions and 0 deletions
|
@ -24,6 +24,7 @@
|
|||
"scripts": {
|
||||
"bootstrap": "python ./script/bootstrap.py",
|
||||
"build": "python ./script/build.py -c D",
|
||||
"instrument-code-coverage": "node ./spec/coverage/instrument.js",
|
||||
"lint": "npm run lint-js && npm run lint-cpp && npm run lint-docs",
|
||||
"lint-js": "standard && cd spec && standard",
|
||||
"lint-cpp": "python ./script/cpplint.py",
|
||||
|
|
31
spec/coverage/instrument.js
Normal file
31
spec/coverage/instrument.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Generate an instrumented .asar file for all the files in lib/ and save it
|
||||
// to out/coverage/electron-instrumented.asar
|
||||
|
||||
var asar = require('asar')
|
||||
var fs = require('fs')
|
||||
var glob = require('glob')
|
||||
var Instrumenter = require('istanbul').Instrumenter
|
||||
var mkdirp = require('mkdirp')
|
||||
var path = require('path')
|
||||
|
||||
var instrumenter = new Instrumenter()
|
||||
var outputPath = path.join(__dirname, '..', '..', 'out', 'coverage')
|
||||
var libPath = path.join(__dirname, '..', '..', 'lib')
|
||||
|
||||
glob.sync('**/*.js', {cwd: libPath}).forEach(function (relativePath) {
|
||||
var rawPath = path.join(libPath, relativePath)
|
||||
var raw = fs.readFileSync(rawPath, 'utf8')
|
||||
|
||||
var generatedPath = path.join(outputPath, 'lib', relativePath)
|
||||
var generated = instrumenter.instrumentSync(raw, rawPath)
|
||||
mkdirp.sync(path.dirname(generatedPath))
|
||||
fs.writeFileSync(generatedPath, generated)
|
||||
})
|
||||
|
||||
var asarPath = path.join(outputPath, 'electron-instrumented.asar')
|
||||
asar.createPackageWithOptions(path.join(outputPath, 'lib'), asarPath, {}, function (error) {
|
||||
if (error) {
|
||||
console.error(error.stack || error)
|
||||
process.exit(1)
|
||||
}
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue