Fix test-coverage.js script

Fix test-coverage by only replacing the last occurence of `/src/` when deriving the instrumented file path from the original file path.
This commit is contained in:
Éric Lemoine
2015-04-29 12:00:06 +02:00
parent 04dea3c6ff
commit e40a51574b

View File

@@ -139,7 +139,15 @@ var foundAllJavaScriptSourceFiles = function(err, files) {
files.forEach(function(file) {
cnt++;
var content = fs.readFileSync(file, 'utf-8');
var outfile = file.replace(/\/src\//, '/src-instrumented/');
// derive output file name from input file name, by replacing the *last*
// occurence of /src/ by /src-instrumented/
var re = new RegExp('/src/', 'g');
var m, match;
while ((m = re.exec(file)) !== null) {
match = m;
}
var outfile = file.substr(0, match.index) + '/src-instrumented/' +
file.substr(match.index + '/src/'.length);
var instrumented = instrumenter.instrumentSync(content, file);
fs.writeFileSync(outfile, instrumented);
if (cnt % 10 === 0) {