-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Implement support for multiple reporters #1772
Changes from all commits
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
*/ | ||
|
||
var tty = require('tty') | ||
, fs = require('fs') | ||
, diff = require('diff') | ||
, ms = require('../ms') | ||
, utils = require('../utils') | ||
|
@@ -225,11 +226,21 @@ exports.list = function(failures){ | |
* @api public | ||
*/ | ||
|
||
function Base(runner) { | ||
function Base(runner, options, path) { | ||
var self = this | ||
, stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 } | ||
, failures = this.failures = []; | ||
|
||
this.options = options; | ||
this.path = path; | ||
|
||
if (path) { | ||
if (!fs.createWriteStream) { | ||
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. I was thinking about this while working on my branch for plugin support. It seems what'd be even more useful is a generic writable stream. at the risk of ballooning the inheritance tree, I went with keeping the base reporter completely generic. then, browser-based reporters would use it, and node-based ones would use a subclass you don't have to do this, since my code will conflict with just about everything anyway, but something to think about. 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. that gives me an idea for a server-side reporter which launches the HTML reporter and uses websockets to stream the results. 😄 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. Yeah, the idea of a generic writable stream hit me too ... but I'm hesitant to do much refactoring though, given how long this pull request has been floating around (almost a year). If there's a way to get it out as-is, and follow-up with improvements, I'm more keen to that. 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. understood |
||
throw new Error('file output not supported in browser'); | ||
} | ||
this.fileStream = fs.createWriteStream(path); | ||
} | ||
|
||
if (!runner) return; | ||
this.runner = runner; | ||
|
||
|
@@ -323,6 +334,32 @@ Base.prototype.epilogue = function(){ | |
console.log(); | ||
}; | ||
|
||
|
||
/** | ||
* Write to reporter output stream | ||
*/ | ||
Base.prototype.write = function(str){ | ||
if (this.fileStream) { | ||
this.fileStream.write(str); | ||
} else { | ||
process.stdout.write(str); | ||
} | ||
}; | ||
|
||
Base.prototype.writeLine = function(line) { | ||
this.write(line + '\n'); | ||
}; | ||
|
||
Base.prototype.done = function(failures, fn) { | ||
if (this.fileStream) { | ||
this.fileStream.end(function() { | ||
fn(failures); | ||
}); | ||
} else { | ||
fn(failures); | ||
} | ||
}; | ||
|
||
/** | ||
* Pad the given `str` to `len`. | ||
* | ||
|
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.
fyi: with the linting work that's being done, we're not going to be using leading commas. also, the below conditional will need curlies
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.
Roger.