Skip to content
Browse files

YUI Test Coverage support. Display line coverage.

If tested code was instrumented with YUI Test Coverage,
coverage data will be passed along with test results
in the agentResults event.

The `./go yui` script uses the recently-added `--query`
command-line option to run YUI's tests with `filter=coverage`
in the query string, which triggers YUI Loader to load
instrumented files.

A basic line coverage percentage is displayed during testing
on the command line when coverage data is available.
  • Loading branch information...
1 parent f4375f9 commit fe4a563a20b33fd2c9bd7da05deca8711d3c641b @reid reid committed Aug 23, 2012
Showing with 44 additions and 3 deletions.
  1. +5 −0 doc/api/index.mustache
  2. +32 −2 lib/cli.js
  3. +1 −0 lib/client.js
  4. +5 −0 lib/hub/view/public/inject.js
  5. +1 −1 scripts/yui.sh
View
5 doc/api/index.mustache
@@ -193,6 +193,11 @@ Emitted when an agent has completed testing a web page.
`details` is an YUI Test formatted object detailing test results.
</p>
+<p>
+If the code tested was instrumented with <a href="http://yuilibrary.com/yuitest/">YUI Test Coverage</a>,
+the `details.coverage` object will contain coverage data for this result.
+</p>
+
<h4>Event: 'agentError'</h4>
```
View
34 lib/cli.js
@@ -96,6 +96,9 @@ function submitBatch(client, options, cb) {
passed: 0,
failed: 0,
currentIndex: 0,
+ coverage: [],
+ calledLines: 0,
+ coveredLines: 0,
total: options.tests.length
};
@@ -152,22 +155,44 @@ function submitBatch(client, options, cb) {
error("");
}
+ function coverageProgress() {
+ var report = "",
+ percent;
+
+ batchDetails.coverage.forEach(function (result) {
+ Object.keys(result).forEach(function (file) {
+ var data = result[file];
+ batchDetails.calledLines += data.calledLines;
+ batchDetails.coveredLines += data.coveredLines;
+ });
+ });
+
+ if (batchDetails.calledLines > 0) {
+ percent = batchDetails.calledLines / batchDetails.coveredLines * 100;
+ report = percent.toFixed(0) + "% line coverage ";
+ }
+
+ return report;
+ }
+
function updateProgress() {
var s = process.stderr,
current = batchDetails.currentIndex,
total = batchDetails.total,
percent = current / total * 100,
tps = (beats * 1000) / ((new Date()).getTime() - timeStart),
spin = ["/", "|", "\\", "-"],
- spins = spin.length - 1;
+ spins = spin.length - 1,
+ coverage = coverageProgress();
s.write("\r\u001B[2K");
s.write("Testing... " +
spin[spinIndex] +
" " + percent.toFixed(0) +
"% complete (" + current + "/" +
total + ") " +
- tps.toFixed(2) + " tests/sec "
+ tps.toFixed(2) + " tests/sec " +
+ coverage
);
spinIndex += 1;
@@ -187,6 +212,11 @@ function submitBatch(client, options, cb) {
batchDetails.passed += passed;
batchDetails.failed += failed;
+ if (details.coverage) {
+ batchDetails.coverage.push(details.coverage);
+ updateProgress();
+ }
+
if (failed) {
error(iconColor(icon), color.bold(details.name), "on", agent);
displayVerboseResult(details);
View
1 lib/client.js
@@ -80,6 +80,7 @@ util.inherits(ClientBatch, EventEmitter2);
* @event agentResult
* @param {String} agent Agent name.
* @param {Object} details Test result details, in YUI Test JSON format.
+ * @param {Object} [details.coverage] Test coverage details, if YUI Test Coverage instrumented code was present.
*/
/**
View
5 lib/hub/view/public/inject.js
@@ -307,6 +307,11 @@
function complete(data) {
$yetify.results = data.results;
+
+ if ("function" === typeof Runner.getCoverage) {
+ $yetify.results.coverage = Runner.getCoverage();
+ }
+
sendResults();
}
View
2 scripts/yui.sh
@@ -60,4 +60,4 @@ fi
echo "Starting Yeti for YUI tests:\n${TESTS[@]}"
-node $YETI "${TESTS[@]}"
+node $YETI --query "filter=coverage" "${TESTS[@]}"

0 comments on commit fe4a563

Please sign in to comment.
Something went wrong with that request. Please try again.