-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Use Istanbul as a CoverageCollector #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
db8f0dc
f4d2878
0ad02a9
084d248
722fb1f
a05be6a
0437298
8468220
fa7aaf9
7624258
c7f3a5a
2014566
f5dfea7
8443f5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright (c) 2014, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
'use strict'; | ||
|
||
var istanbul = require('istanbul'); | ||
|
||
function IstanbulCollector(sourceText, filename) { | ||
var instr = new istanbul.Instrumenter(); | ||
this._coverageDataStore = {}; | ||
this._instrumentor = instr; | ||
this._origSourceText = sourceText; | ||
this._instrumentedSourceText = instr.instrumentSync(sourceText, filename); | ||
} | ||
|
||
IstanbulCollector.prototype.getCoverageDataStore = function() { | ||
return this._coverageDataStore; | ||
}; | ||
|
||
IstanbulCollector.prototype.getInstrumentedSource = function(storageVarName) { | ||
return this._instrumentedSourceText + storageVarName + '.coverState=' + | ||
this._instrumentor.currentState.trackerVar + ';'; | ||
}; | ||
|
||
IstanbulCollector.prototype.extractRuntimeCoverageInfo = function() { | ||
return this._coverageDataStore.coverState; | ||
}; | ||
|
||
module.exports = IstanbulCollector; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
var DefaultTestReporter = require('./DefaultTestReporter'); | ||
var istanbul = require('istanbul'); | ||
var collector = new istanbul.Collector(); | ||
var reporter = new istanbul.Reporter(); | ||
|
||
function IstanbulTestReporter(customProcess) { | ||
this.process = customProcess || process; | ||
} | ||
|
||
IstanbulTestReporter.prototype = new DefaultTestReporter(); | ||
|
||
IstanbulTestReporter.prototype.onTestResult = | ||
function(config, testResult, aggregatedResults) { | ||
DefaultTestReporter.prototype.onTestResult.call( | ||
this, config, testResult, aggregatedResults | ||
); | ||
|
||
if (config.collectCoverage && testResult.coverage) { | ||
collector.add(testResult.coverage); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This appears to crash if the tests failed. This can be fixed by changing the if statement to: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, updated. I also considered about the idea |
||
} | ||
}; | ||
|
||
IstanbulTestReporter.prototype.onRunComplete = | ||
function (config, aggregatedResults) { | ||
DefaultTestReporter.prototype.onRunComplete.call( | ||
this, config, aggregatedResults | ||
); | ||
|
||
if (config.collectCoverage) { | ||
reporter.addAll([ 'json', 'text', 'lcov', 'clover' ]); | ||
reporter.write(collector, true, function () { | ||
console.log('All reports generated'); | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = IstanbulTestReporter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, the error was only because requiring
undefined
. And why it worked when moving it bellow because the test didn't go intoshouldCollectCoverage
block. But I feel it makes some sense, if you don't need to collect coverage then you don't need require collector.