Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add a --coverage-dump option to save coverage results to files #48

Closed
wants to merge 3 commits into from

4 participants

@neyric

We use this option to store the coverage results into JSON files, so that we can generate HTML reports later.

@reid reid was assigned
@reid

Hey @neyric, are you still interested in this feature?

If you're willing to implement some feedback, I'll leave some in the diff. Otherwise, I may be cleaning up this feature myself to get it into a future release — but I'd prefer your feedback.

@neyric

Yes, definitly.

If you add your feedback I will try to implement it.

We would love to have this feature on the npm registry so that we can use it in our CI env.

lib/cli/index.js
@@ -252,6 +254,24 @@ CLI.prototype.submitBatch = function submitBatch(client, output, options, cb) {
batch: batch
};
+
+ if (!!options["coverage-dump"]) {
+ try {
+ covStats = fs.lstatSync(options["coverage-dump"]);
+ if (covStats.isDirectory()) {
+ agentResultIndex = 0;
+ batch.on("agentResult", function (agent, details) {
+ if (details.coverage) {
+ fs.writeFileSync(path.join(options["coverage-dump"], "coverage-" + agentResultIndex + ".json"), JSON.stringify(details.coverage, null, 3));
@reid
reid added a note

Can this line be split into multiple lines for better readability? Maybe use temporary variables for the filename and JSON data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/cli/index.js
@@ -252,6 +254,24 @@ CLI.prototype.submitBatch = function submitBatch(client, output, options, cb) {
batch: batch
};
+
+ if (!!options["coverage-dump"]) {
+ try {
+ covStats = fs.lstatSync(options["coverage-dump"]);
+ if (covStats.isDirectory()) {
+ agentResultIndex = 0;
+ batch.on("agentResult", function (agent, details) {
+ if (details.coverage) {
+ fs.writeFileSync(path.join(options["coverage-dump"], "coverage-" + agentResultIndex + ".json"), JSON.stringify(details.coverage, null, 3));
+ agentResultIndex += 1;
+ }
+ });
+ }
+ }
+ catch (e) {}
@reid
reid added a note

Is this try-catch just for JSON.stringify? If so, let's just keep the try-catch on the stringify call and use an empty string if the conversion fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/cli/index.js
@@ -252,6 +254,24 @@ CLI.prototype.submitBatch = function submitBatch(client, output, options, cb) {
batch: batch
};
+
+ if (!!options["coverage-dump"]) {
+ try {
+ covStats = fs.lstatSync(options["coverage-dump"]);
+ if (covStats.isDirectory()) {
+ agentResultIndex = 0;
@reid
reid added a note

Instead of writing a new file for every agentResult, can we instead buffer the coverage data and then write it all out before exiting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@reid reid commented on the diff
README.md
@@ -77,6 +77,16 @@ Yeti automatically includes a line coverage summary if your tests were instrumen
✔ Testing started on Safari (6.0) / Mac OS
► Testing... \ 13% complete (10/60) 11.85 tests/sec ETA 4 minutes, 2 seconds 44% line coverage
+
+The coverage results can be dumped using the `--coverage-dump` option :
@reid
reid added a note

Thanks for adding documentation! :thumbsup:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@paulRbr paulRbr referenced this pull request in neyric/yeti
Merged

Take into account reid s comments from yeti collab #1

@neyric neyric Merge pull request #1 from popox/coverage-dump
Take into account reid s comments from yeti collab
dfd6a69
@neyric

@reid Hi ! @popox implemented your suggestions. Could you have a look at it ? Thx

@neyric

@reid Any chance ?

@reid

@neyric Yeah. I'd like to get this in. Thanks for your changes, @popox! We don't have any tests here, so I'd like to add some before it lands on master.

@andrewnicols

Unless I'm mistaken, a similar option is now part of Yeti, and this PR can be closed.
https://github.com/yui/yeti#code-coverage describes using the --coverage-report json option to output JSON, and there's also the --coverage-dir to specify where is built to.

@reid

@andrewnicols is correct. Closing.

@reid reid closed this
@reid reid was unassigned by jlecomte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 23, 2013
  1. @neyric
Commits on Oct 24, 2013
  1. @paulRbr
  2. @neyric

    Merge pull request #1 from popox/coverage-dump

    neyric authored
    Take into account reid s comments from yeti collab
This page is out of date. Refresh to see the latest.
Showing with 40 additions and 3 deletions.
  1. +10 −0 README.md
  2. +30 −3 lib/cli/index.js
View
10 README.md
@@ -77,6 +77,16 @@ Yeti automatically includes a line coverage summary if your tests were instrumen
✔ Testing started on Safari (6.0) / Mac OS
► Testing... \ 13% complete (10/60) 11.85 tests/sec ETA 4 minutes, 2 seconds 44% line coverage
+
+The coverage results can be dumped using the `--coverage-dump` option :
@reid
reid added a note

Thanks for adding documentation! :thumbsup:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ $ mkdir coverage-results
+ $ yeti myproject/src/*/tests/unit/*.html --coverage-dump coverage-results --query 'filter=coverage'
+
+If your code is instrumented using istanbul, you can then generate the HTML coverage reports :
+
+ $ istanbul report --root coverage-results
+
#### AJAX testing
Yeti provides server-side AJAX routes with [echoecho][ee]. Your test can
View
33 lib/cli/index.js
@@ -9,6 +9,7 @@ var Configuration = require("./configuration");
var path = require("path");
var glob = require("glob");
var urlUtil = require("url");
+var fs = require("fs");
var readline = require("readline");
var util = require("util");
var url = require("url");
@@ -47,7 +48,8 @@ var parseArgv = exports.parseArgv = function (argv) {
"port": Number,
"timeout": Number,
"hub": url,
- "help" : Boolean
+ "help" : Boolean,
+ "coverage-dump" : String
}, shortHands = {
"b": ["--browser"],
"junit": ["--output", "junit"],
@@ -243,7 +245,8 @@ CLI.prototype.setupExceptionHandler = function () {
* @param {Function} cb Completion callback.
*/
CLI.prototype.submitBatch = function submitBatch(client, output, options, cb) {
- var reporter, batch, reporterOptions;
+ var reporter, batch, reporterOptions, covStats, agentResultIndex,
+ covFilename, covData, self = this;
batch = client.createBatch(options);
@@ -252,6 +255,28 @@ CLI.prototype.submitBatch = function submitBatch(client, output, options, cb) {
batch: batch
};
+
+ if (!!options["coverage-dump"]) {
+ covStats = fs.lstatSync(options["coverage-dump"]);
+ if (covStats.isDirectory()) {
+ agentResultIndex = 0;
+ batch.on("agentResult", function (agent, details) {
+ if (details.coverage) {
+ covFilename = path.join(options["coverage-dump"], "coverage-" + agentResultIndex + ".json");
+ try {
+ covData = JSON.stringify(details.coverage, null, 3);
+ } catch (e) {
+ covData = "";
+ self.error("Unable to dump coverage due to " + e.message + ".");
+ }
+ fs.writeFileSync(covFilename, covData);
+ agentResultIndex += 1;
+ }
+ });
+ }
+ }
+
+
if (output === "junit") {
reporter = new JUnitReporter(reporterOptions);
} else {
@@ -464,7 +489,8 @@ CLI.prototype.runBatch = function runBatch(options) {
basedir: options.get("basedir"),
query: query,
timeout: options.get("timeout"),
- tests: files
+ tests: files,
+ "coverage-dump": options.get("coverage-dump")
};
browsers = self.parseBrowsers(browsers);
@@ -593,6 +619,7 @@ CLI.prototype.route = function (argv) {
" [--hub=<url>] [--loglevel <level>] [--timeout <seconds>]" +
" [--query <params>] [--basedir <directory>] [--browser <name[/version]>...]" +
" [--wd-url <url>] [--self-url <url>]" +
+ " [--coverage-dump <directory>] " +
" [--help] [--] [<HTML file>...]";
config.pipeLog(this);
Something went wrong with that request. Please try again.