Skip to content

Commit

Permalink
fix(preprocessor): Call done with error message instead of populating…
Browse files Browse the repository at this point in the history
… instrumentedCode
  • Loading branch information
cafesanu committed Jan 15, 2016
1 parent 1ba61bc commit c56e4de
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions lib/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,39 +112,40 @@ function createCoveragePreprocessor (logger, helper, basePath, reporters, covera
instrumenter.instrument(content, jsPath, function (err, instrumentedCode) {
if (err) {
log.error('%s\n at %s', err.message, file.originalPath)
}
done(err.message)
} else {
if (file.sourceMap && instrumenter.lastSourceMap()) {
log.debug('Adding source map to instrumented file for "%s".', file.originalPath)
var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(instrumenter.lastSourceMap().toString()))
generator.applySourceMap(new SourceMapConsumer(file.sourceMap))
file.sourceMap = JSON.parse(generator.toString())
instrumentedCode += '\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,'
instrumentedCode += new Buffer(JSON.stringify(file.sourceMap)).toString('base64') + '\n'
}

if (file.sourceMap && instrumenter.lastSourceMap()) {
log.debug('Adding source map to instrumented file for "%s".', file.originalPath)
var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(instrumenter.lastSourceMap().toString()))
generator.applySourceMap(new SourceMapConsumer(file.sourceMap))
file.sourceMap = JSON.parse(generator.toString())
instrumentedCode += '\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,'
instrumentedCode += new Buffer(JSON.stringify(file.sourceMap)).toString('base64') + '\n'
}
// remember the actual immediate instrumented JS for given original path
sourceCache[jsPath] = content

// remember the actual immediate instrumented JS for given original path
sourceCache[jsPath] = content
if (includeAllSources) {
// reset stateful regex
coverageObjRegex.lastIndex = 0

if (includeAllSources) {
// reset stateful regex
coverageObjRegex.lastIndex = 0
var coverageObjMatch = coverageObjRegex.exec(instrumentedCode)

var coverageObjMatch = coverageObjRegex.exec(instrumentedCode)
if (coverageObjMatch !== null) {
var coverageObj = JSON.parse(coverageObjMatch[0])

if (coverageObjMatch !== null) {
var coverageObj = JSON.parse(coverageObjMatch[0])
coverageMap.add(coverageObj)
}
}

coverageMap.add(coverageObj)
// RequireJS expects JavaScript files to end with `.js`
if (useJSExtensionForCoffeeScript && instrumenterLiteral === 'ibrik') {
file.path = file.path.replace(/\.coffee$/, '.js')
}
}

// RequireJS expects JavaScript files to end with `.js`
if (useJSExtensionForCoffeeScript && instrumenterLiteral === 'ibrik') {
file.path = file.path.replace(/\.coffee$/, '.js')
done(instrumentedCode)
}

done(instrumentedCode)
})
}
}
Expand Down

0 comments on commit c56e4de

Please sign in to comment.