Skip to content
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

Ouput test duration and stack trace in TAP YAML block #1209

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion lib/reporters/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
var Base = require('./base')
, cursor = Base.cursor
, color = Base.color;
var YAML = require('yamljs');

/**
* Expose `TAP`.
Expand Down Expand Up @@ -45,12 +46,13 @@ function TAP(runner) {
runner.on('pass', function(test){
passes++;
console.log('ok %d %s', n, title(test));
writeDiagnostic(test);
});

runner.on('fail', function(test, err){
failures++;
console.log('not ok %d %s', n, title(test));
if (err.stack) console.log(err.stack.replace(/^/gm, ' '));
writeDiagnostic(test, err);
});

runner.on('end', function(){
Expand All @@ -71,3 +73,20 @@ function TAP(runner) {
function title(test) {
return test.fullTitle().replace(/#/g, '');
}

/**
* Output TAP diagnostic in YAML format
* @param {Object} test
* @param {Object} err
* @api private
*/
function writeDiagnostic(test, err){
var obj = {};
if (test.duration) obj.duration_ms = test.duration / 1000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, so the name suggest it's milliseconds (duration_ms) when in fact it is seconds (/ 1000)?!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what? ms = seconds / 1000

A millisecond (from milli- and second; abbreviation: ms) is a thousandth (10−3 or 1/1,000) of a second.[1] Its symbol is ms. One millisecond is to one second as one second is to 16.67 minutes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, a couple of things went wrong here :) I assumed that test.duration was in milliseconds, since that's the standard unit in javascript.

Also, 1000ms === 1s so to convert from seconds to milliseconds we need to multiply it with 1000, since it takes 1000ms to make up 1s. Heh, converting between time units is always a pain.

The correct code should, I think, be obj.duration_ms = test.duration * 1000.

if (err && err.stack) obj.stacktrace = err.stack;
if (Object.keys(obj).length > 0) {
console.log(' ---');
console.log(YAML.stringify(obj, 4).replace(/^/gm, ' '));
console.log(' ...');
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"diff": "1.0.7",
"debug": "*",
"mkdirp": "0.3.5",
"glob": "3.2.3"
"glob": "3.2.3",
"yamljs": "0.1.5"
},
"devDependencies": {
"should": ">= 2.0.x",
Expand Down