-
-
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
resolves #2149, #1257: Make TAP reporter conform to TAP13 #3452
Changes from all commits
d3c2df9
c067a6e
9c78b61
78ab6c5
b59af19
ddc5b17
f030a4b
43c94c8
8d369b7
9677744
3047441
253d76a
e00b99c
1e559b3
419fc33
3551db3
68d8b9c
3b5f88f
3cac7f1
b5b88a1
ce24d96
d5b519d
3242408
61e8c79
8dc5b65
4b11a31
38b8ce3
7951bf0
ff80cf4
0496ef3
42035e7
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
*/ | ||
|
||
var Base = require('./base'); | ||
var inherits = require('../utils').inherits; | ||
|
||
/** | ||
* Expose `TAP`. | ||
|
@@ -24,46 +25,47 @@ exports = module.exports = TAP; | |
* @api public | ||
* @param {Runner} runner | ||
*/ | ||
function TAP(runner) { | ||
function TAP(runner, options) { | ||
Base.call(this, runner); | ||
|
||
var self = this; | ||
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. Add this line: |
||
var n = 1; | ||
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.
|
||
var passes = 0; | ||
var failures = 0; | ||
|
||
var tapSpec = '12'; | ||
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. Should this be numeric instead? |
||
if (options && options.reporterOptions) { | ||
if (options.reporterOptions.spec) { | ||
tapSpec = options.reporterOptions.spec; | ||
} | ||
} | ||
|
||
if (tapSpec === '13') { | ||
this.producer = new TAP13Producer(); | ||
} else { | ||
this.producer = new TAP12Producer(); | ||
} | ||
|
||
runner.on('start', function() { | ||
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. runner.on('start', function() {
var ntests = runner.grepTotal(runner.suite);
self.producer.writeStart(ntests);
}); |
||
var total = runner.grepTotal(runner.suite); | ||
console.log('%d..%d', 1, total); | ||
self.producer.writeStart(runner); | ||
}); | ||
|
||
runner.on('test end', function() { | ||
++n; | ||
}); | ||
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. Remove |
||
|
||
runner.on('pending', function(test) { | ||
console.log('ok %d %s # SKIP -', n, title(test)); | ||
self.producer.writePending(n, test); | ||
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. var n = stats.tests;
self.producer.writePending(n, test); |
||
}); | ||
|
||
runner.on('pass', function(test) { | ||
passes++; | ||
console.log('ok %d %s', n, title(test)); | ||
self.producer.writePass(n, test); | ||
}); | ||
|
||
runner.on('fail', function(test, err) { | ||
failures++; | ||
console.log('not ok %d %s', n, title(test)); | ||
if (err.message) { | ||
console.log(err.message.replace(/^/gm, ' ')); | ||
} | ||
if (err.stack) { | ||
console.log(err.stack.replace(/^/gm, ' ')); | ||
} | ||
self.producer.writeFail(n, test, err); | ||
}); | ||
|
||
runner.once('end', function() { | ||
console.log('# tests ' + (passes + failures)); | ||
console.log('# pass ' + passes); | ||
console.log('# fail ' + failures); | ||
self.producer.writeEnd(runner); | ||
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.
|
||
}); | ||
} | ||
|
||
|
@@ -77,3 +79,95 @@ function TAP(runner) { | |
function title(test) { | ||
return test.fullTitle().replace(/#/g, ''); | ||
} | ||
|
||
/** | ||
* Inherit from `Base.prototype`. | ||
*/ | ||
inherits(TAP, Base); | ||
|
||
/** | ||
* Initialize a new `TAPProducer`. Should only be used as a base class. | ||
* | ||
* @private | ||
* @class | ||
* @api private | ||
*/ | ||
function TAPProducer() {} | ||
|
||
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
TAPProducer.prototype.writePending = function(n, test) { | ||
console.log('ok %d %s # SKIP -', n, title(test)); | ||
}; | ||
|
||
TAPProducer.prototype.writePass = function(n, test) { | ||
console.log('ok %d %s', n, title(test)); | ||
}; | ||
|
||
TAPProducer.prototype.writeEnd = function(runner) { | ||
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.
|
||
console.log('# tests ' + (runner.stats.passes + runner.stats.failures)); | ||
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. Just noticed this, but think this is possibly an unreported existing bug. |
||
console.log('# pass ' + runner.stats.passes); | ||
console.log('# fail ' + runner.stats.failures); | ||
}; | ||
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. Should this include a summary line for pending tests? |
||
|
||
/** | ||
* Initialize a new `TAP12Producer` which will produce output conforming to the TAP12 spec. | ||
* | ||
* @private | ||
* @class | ||
* @api private | ||
*/ | ||
function TAP12Producer() {} | ||
|
||
TAP12Producer.prototype.writeStart = function(runner) { | ||
var total = runner.grepTotal(runner.suite); | ||
console.log('%d..%d', 1, total); | ||
}; | ||
|
||
TAP12Producer.prototype.writeFail = function(n, test, err) { | ||
console.log('not ok %d %s', n, title(test)); | ||
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (err.message) { | ||
console.log(err.message.replace(/^/gm, ' ')); | ||
} | ||
if (err.stack) { | ||
console.log(err.stack.replace(/^/gm, ' ')); | ||
} | ||
}; | ||
|
||
inherits(TAP12Producer, TAPProducer); | ||
|
||
/** | ||
* Initialize a new `TAP13Producer` which will produce output conforming to the TAP13 spec. | ||
* | ||
* @private | ||
* @class | ||
* @api private | ||
*/ | ||
function TAP13Producer() {} | ||
|
||
TAP13Producer.prototype.yamlIndent = function(level) { | ||
return Array(level + 1).join(' '); | ||
}; | ||
|
||
TAP13Producer.prototype.writeStart = function(runner) { | ||
console.log('TAP version 13'); | ||
var total = runner.grepTotal(runner.suite); | ||
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
console.log('%d..%d', 1, total); | ||
}; | ||
|
||
TAP13Producer.prototype.writeFail = function(n, test, err) { | ||
console.log('not ok %d %s', n, title(test)); | ||
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var emitYamlBlock = err.message != null || err.stack != null; | ||
if (emitYamlBlock) { | ||
console.log(this.yamlIndent(1) + '---'); | ||
if (err.message) { | ||
console.log(this.yamlIndent(2) + 'message: |-'); | ||
console.log(err.message.replace(/^/gm, this.yamlIndent(3))); | ||
} | ||
if (err.stack) { | ||
console.log(this.yamlIndent(2) + 'stack: |-'); | ||
console.log(err.stack.replace(/^/gm, this.yamlIndent(3))); | ||
} | ||
console.log(this.yamlIndent(1) + '...'); | ||
} | ||
}; | ||
|
||
inherits(TAP13Producer, TAPProducer); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict'; | ||
|
||
/** | ||
* This file generates a wide range of output to test reporter functionality. | ||
*/ | ||
|
||
describe('Animals', function() { | ||
|
||
it('should consume organic material', function(done) { done(); }); | ||
it('should breathe oxygen', function(done) { | ||
// we're a jellyfish | ||
var actualBreathe = 'nothing'; | ||
var expectedBreathe = 'oxygen'; | ||
expect(actualBreathe, 'to equal', expectedBreathe); | ||
done(); | ||
}); | ||
it('should be able to move', function(done) { done(); }); | ||
it('should reproduce sexually', function(done) { done(); }); | ||
it('should grow from a hollow sphere of cells', function(done) { done(); }); | ||
|
||
describe('Vertebrates', function() { | ||
describe('Mammals', function() { | ||
it('should give birth to live young', function(done) { | ||
var expectedMammal = { | ||
consumesMaterial: 'organic', | ||
breathe: 'oxygen', | ||
reproduction: { | ||
type: 'sexually', | ||
spawnType: 'live', | ||
} | ||
}; | ||
var platypus = JSON.parse(JSON.stringify(expectedMammal)); | ||
platypus['reproduction']['spawnType'] = 'hard-shelled egg'; | ||
|
||
expect(platypus, 'to equal', expectedMammal); | ||
done(); | ||
}); | ||
|
||
describe('Blue Whale', function() { | ||
it('should be the largest of all mammals', function(done) { done(); }); | ||
it('should have a body in some shade of blue', function(done) { | ||
var bodyColor = 'blueish_grey'; | ||
var shadesOfBlue = ['cyan', 'light_blue', 'blue', 'indigo']; | ||
expect(bodyColor, 'to be one of', shadesOfBlue); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('Birds', function() { | ||
it('should have feathers', function(done) { done(); }); | ||
it('should lay hard-shelled eggs', function(done) { done(); }); | ||
}); | ||
}); | ||
|
||
describe('Tardigrades', function() { | ||
mollstam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
it('should answer to "water bear"', function(done) { done(); }); | ||
it('should be able to survive global mass extinction events', function(done) { | ||
throw new Error("How do we even test for this without causing one?") | ||
done(); | ||
}); | ||
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. Can we add a pending test somewhere in this fixture?
|
||
}); | ||
}); |
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.
Disagree with this change. IMO, all reporters should extend
Base
. See below for at least one reason.