Skip to content

Commit

Permalink
Change SummaryReporter behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
5long committed Nov 6, 2010
1 parent aef7773 commit 804d874
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
7 changes: 1 addition & 6 deletions src/bin/cli.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ var runner = require("../runner")
, util = require("../util") , util = require("../util")
, async = util.async , async = util.async
, path = require("path") , path = require("path")
, reporterMod = require("../reporter")
, reporters = [ new reporterMod.Failure()
, new reporterMod.Summary()
, new reporterMod.Error()
]


function main() { function main() {
var files = util.makeArray(process.argv, 2) var files = util.makeArray(process.argv, 2)
Expand All @@ -17,7 +12,7 @@ function main() {
loadAndRun(path.join(cwd, file), this) loadAndRun(path.join(cwd, file), this)
}, function(err) { }, function(err) {
if (err) throw err if (err) throw err
runner.run({reporters:reporters}, function(err) { runner.run({}, function(err) {
if (err) throw err if (err) throw err
}) })
}) })
Expand Down
2 changes: 1 addition & 1 deletion src/reporter/summary.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function SummaryReporter(writable) {
var self = this var self = this
this._output = writable || process.stdout this._output = writable || process.stdout
this._result = {all: [], passed: [], failed: []} this._result = {all: [], passed: [], failed: []}
process.on("exit", function() { process.on("_reutTestEnd", function() {
self._report() self._report()
}) })
} }
Expand Down
13 changes: 11 additions & 2 deletions src/runner.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ var TestSuite = require("./test_suite")
, Test = require("./test") , Test = require("./test")
, async = require("./util").async , async = require("./util").async
, suites = [] , suites = []
, reporterMod = require("./reporter")
, defaultReporters = [
new reporterMod.Failure()
, new reporterMod.Summary()
, new reporterMod.Error()
]


// TODO Extract the test runner interface. // TODO Extract the test runner interface.
var runner = module.exports = { var runner = module.exports = {
Expand All @@ -17,13 +23,16 @@ var runner = module.exports = {
} }
, run: function(opt, cb) { , run: function(opt, cb) {
if (arguments.length < 2) cb = opt if (arguments.length < 2) cb = opt
var reporters = opt.reporters || [] var reporters = opt.reporters || defaultReporters
async.paraMap(suites, function(suite) { async.paraMap(suites, function(suite) {
reporters.forEach(function(r) { reporters.forEach(function(r) {
suite.reportTo(r) suite.reportTo(r)
}) })
suite.run(this) suite.run(this)
}, cb) }, function(err, result) {
process.emit("_reutTestEnd")
cb.apply(this, arguments)
})
} }
, _suites: suites , _suites: suites
} }
1 change: 1 addition & 0 deletions test/reporter_summary.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dummySuite.run(function(err) {
}) })


process.on("exit", function() { process.on("exit", function() {
process.emit("_reutTestEnd")
var output = spyWritable.input[0] var output = spyWritable.input[0]
, num = sampleTest.num , num = sampleTest.num
assert.notEqual(output.indexOf(num.all), -1) assert.notEqual(output.indexOf(num.all), -1)
Expand Down

0 comments on commit 804d874

Please sign in to comment.