testem-time-reporter
Advanced tools
Comparing version 1.1.0 to 1.2.0
31
index.js
@@ -5,10 +5,12 @@ /* eslint-env node */ | ||
function TimeReporter (out) { | ||
this.out = out || process.stdout; | ||
function TimeReporter (opts) { | ||
this.out = opts.out || process.stdout; | ||
this.runDuration = 0; | ||
this.previousDot = true; | ||
this.opts = opts; | ||
write = this.out.write.bind(this.out); | ||
this.tests = {}; | ||
this.failures = []; | ||
this.longestTest = { runDuration: 0 }; | ||
this.longTests = []; | ||
} | ||
@@ -18,8 +20,2 @@ | ||
report: function (prefix, data) { | ||
// This is stupid, for some reason report was being called twice for every test. | ||
if (this.tests[data.name.trim()]) { | ||
return; | ||
} | ||
this.tests[data.name.trim()] = true; | ||
this.runDuration += data.runDuration; | ||
@@ -40,2 +36,6 @@ let dot = false; | ||
} | ||
if (this.opts.sort && !this.done && data.runDuration > 500) { | ||
this.longTests.push(data); | ||
return; | ||
} | ||
const result = `\n${data.runDuration}ms - ${data.name.trim()}`; | ||
@@ -59,10 +59,11 @@ if (data.runDuration > 2000) { | ||
finish: function () { | ||
if (this.finished) { | ||
return; | ||
this.done = true; | ||
if (this.opts.sort && this.longTests.length) { | ||
const sorted = this.longTests.sort((a, b) => a.runDuration < b.runDuration ? -1 : 1); | ||
sorted.forEach(data => this.report(null, data)); | ||
} else if (this.longestTest.name) { | ||
write(`\n Longest test - ${this.longestTest.runDuration}ms - ${this.longestTest.name.trim()}\n`); | ||
} | ||
this.finished = true; | ||
write(`\n Tests completed in ${this.runDuration / 1000} seconds \n`); | ||
if (this.longestTest.name) { | ||
write(`\n Longest test - ${this.longestTest.runDuration}ms - ${this.longestTest.name.trim()}\n`); | ||
} | ||
if (this.failures.length) { | ||
@@ -69,0 +70,0 @@ write('\n Failing tests: \n'); |
{ | ||
"name": "testem-time-reporter", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A testem reporter for highlighting tests", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
84
test.js
@@ -8,15 +8,14 @@ /* global describe, it */ | ||
describe('test failure reporter', function () { | ||
it('writes out result without passes', function () { | ||
it('writes out fast results as dots, plus a summary', function () { | ||
var stream = new PassThrough(); | ||
var reporter = new TimeReporter(stream); | ||
var reporter = new TimeReporter({ out: stream }); | ||
reporter.report('phantomjs', { | ||
name: 'it does stuff', | ||
passed: true, | ||
runDuration: 3000, | ||
runDuration: 300, | ||
logs: [] | ||
}); | ||
reporter.report('phantomjs', { | ||
name: 'it fails', | ||
passed: false, | ||
error: new Error('at host:port/path:line: it crapped out'), | ||
name: 'it does more stuff', | ||
passed: true, | ||
runDuration: 300, | ||
@@ -27,22 +26,73 @@ logs: ['I am a log', 'Useful information'] | ||
var output = stream.read().toString(); | ||
// one line per failure plus three for summary | ||
assert.equal(output.split('\n').length, 4); | ||
assert.match(output, /1\/2 failed/); | ||
// one line for all success plus 6 for summary | ||
assert.equal(output.split('\n').length, 7); | ||
assert.match(output, /\.\./); // two dots for passes | ||
}); | ||
it('writes out errors', function () { | ||
it('writes out slow results as lines with run duration, plus a summary', function () { | ||
var stream = new PassThrough(); | ||
var reporter = new TimeReporter(stream); | ||
var reporter = new TimeReporter({ out: stream }); | ||
reporter.report('phantomjs', { | ||
name: 'it fails', | ||
passed: false, | ||
error: new Error('at host:port/path:line: it crapped out'), | ||
name: 'it does stuff', | ||
passed: true, | ||
runDuration: 300, | ||
logs: [] | ||
}); | ||
reporter.report('phantomjs', { | ||
name: 'it takes a while', | ||
passed: true, | ||
runDuration: 3000, | ||
logs: ['I am a log', 'Useful information'] | ||
}); | ||
reporter.report('phantomjs', { | ||
name: 'it takes a while more', | ||
passed: true, | ||
runDuration: 5000, | ||
logs: ['I am a log', 'Useful information'] | ||
}); | ||
reporter.finish(); | ||
var output = stream.read().toString(); | ||
// one line per failure plus three for summary | ||
assert.equal(output.split('\n').length, 4); | ||
assert.match(output, /it crapped out/); | ||
// one line fast success, two for slow success, plus 6 for summary | ||
assert.equal(output.split('\n').length, 9); | ||
assert.match(output, /3000ms - it takes a while/); // log long test | ||
assert.match(output, /Longest test - 5000ms - it takes a while more/); // Log as longest test | ||
}); | ||
it('can sort out slow tests', function () { | ||
var stream = new PassThrough(); | ||
var reporter = new TimeReporter({ out: stream, sort: true }); | ||
reporter.report('phantomjs', { | ||
name: 'it does stuff', | ||
passed: true, | ||
runDuration: 300, | ||
logs: [] | ||
}); | ||
reporter.report('phantomjs', { | ||
name: 'it takes a while more', | ||
passed: true, | ||
runDuration: 5000, | ||
logs: ['I am a log', 'Useful information'] | ||
}); | ||
reporter.report('phantomjs', { | ||
name: 'it takes a long damn time', | ||
passed: true, | ||
runDuration: 9000, | ||
logs: ['I am a log', 'Useful information'] | ||
}); | ||
reporter.report('phantomjs', { | ||
name: 'it takes a while', | ||
passed: true, | ||
runDuration: 3000, | ||
logs: ['I am a log', 'Useful information'] | ||
}); | ||
reporter.finish(); | ||
var output = stream.read().toString(); | ||
// one line fast success, three for slow success, plus 5 for summary (no longest line) | ||
assert.equal(output.split('\n').length, 8); | ||
const index1 = output.indexOf('3000ms - it takes a while'); | ||
const index2 = output.indexOf('5000ms - it takes a while more'); | ||
const index3 = output.indexOf('9000ms - it takes a long damn time'); | ||
assert.equal(-1 < index1 < index2 < index3, true); // eslint-disable-line | ||
assert.equal(output.indexOf('Longest'), -1); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9607
8
175