-
-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b64d921
commit 0d7fcb7
Showing
14 changed files
with
195 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,6 @@ coverage | |
node_modules | ||
test/build/ | ||
.self_coverage | ||
*.covered.js | ||
self-coverage/ | ||
*.swp | ||
needs-transpile.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,43 @@ | ||
var istanbul = require('istanbul-lib-instrument') | ||
var fs = require('fs') | ||
var path = require('path') | ||
|
||
;[ | ||
'index.js', | ||
'lib/process.js' | ||
].forEach(function (name) { | ||
var indexPath = path.join(__dirname, name) | ||
var source = fs.readFileSync(indexPath, 'utf8') | ||
|
||
var instrumentor = istanbul.createInstrumenter({ | ||
coverageVariable: '___NYC_SELF_COVERAGE___', | ||
esModules: true | ||
}) | ||
const path = require('path') | ||
const fs = require('fs') | ||
const istanbul = require('istanbul-lib-instrument') | ||
const makeDir = require('make-dir') | ||
const glob = require('glob') | ||
|
||
const instrumenter = istanbul.createInstrumenter({ | ||
coverageVariable: '___NYC_SELF_COVERAGE___', | ||
esModules: true | ||
}) | ||
|
||
function instrumentFile (name) { | ||
const indexPath = path.join(__dirname, name) | ||
const outputPath = path.join(__dirname, 'self-coverage', name) | ||
|
||
var instrumentedSource = instrumentor.instrumentSync(source, indexPath) | ||
const source = fs.readFileSync(indexPath, 'utf8') | ||
const instrumentedSource = name === 'package.json' ? source : instrumenter.instrumentSync(source, indexPath) | ||
|
||
var outputPath = path.join(__dirname, name.replace(/\.js$/, '.covered.js')) | ||
makeDir.sync(path.dirname(outputPath)) | ||
fs.writeFileSync(outputPath, instrumentedSource) | ||
}) | ||
} | ||
|
||
function instrumentGlob (pattern) { | ||
const result = glob.sync(pattern, { | ||
cwd: __dirname, | ||
nodir: true | ||
}) | ||
|
||
result.forEach(file => { | ||
instrumentFile(file) | ||
}) | ||
} | ||
|
||
function instrumentAll () { | ||
/* package.json is just being copied so the instrumented copy of lib/hash.js can find it. */ | ||
const globPatterns = ['package.json', 'index.js', 'bin/*.js', 'lib/**/*.js'] | ||
|
||
globPatterns.forEach(pattern => { | ||
instrumentGlob(pattern) | ||
}) | ||
} | ||
|
||
instrumentAll() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.