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

added ability to specify xunit output file #384

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
13 changes: 11 additions & 2 deletions lib/ci/index.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var HookRunner = require('../hook_runner')
var log = require('npmlog') var log = require('npmlog')
var cleanExit = require('../clean_exit') var cleanExit = require('../clean_exit')
var isa = require('../isa') var isa = require('../isa')
var fs = require('fs')
var wStream = null;


function App(config, finalizer){ function App(config, finalizer){
this.exited = false this.exited = false
Expand All @@ -20,6 +22,7 @@ function App(config, finalizer){
this.hookRunners = {} this.hookRunners = {}
this.results = [] this.results = []
this.reporter = this.initReporter(this.config.get('reporter')) this.reporter = this.initReporter(this.config.get('reporter'))
this.outFile = this.createWStream(this.config.get('out_file'))
if (!this.reporter){ if (!this.reporter){
console.error('Test reporter `' + reporter + '` not found.') console.error('Test reporter `' + reporter + '` not found.')
this.cleanExit(1) this.cleanExit(1)
Expand Down Expand Up @@ -132,7 +135,7 @@ App.prototype = {
} }
}) })
} }
this.reporter.finish() this.reporter.finish(this.outFile)
this.emit('tests-finish') this.emit('tests-finish')
this.stopHookRunners() this.stopHookRunners()
this.stopServer(this.exit.bind(this)) this.stopServer(this.exit.bind(this))
Expand Down Expand Up @@ -161,6 +164,12 @@ App.prototype = {
return 0 return 0
}, },


createWStream: function(outFileName) {
if(outFileName) {
return fs.createWriteStream(outFileName);
}
},

exit: function(){ exit: function(){
if (this.exited) return if (this.exited) return
this.cleanExit(this.getExitCode()) this.cleanExit(this.getExitCode())
Expand All @@ -172,4 +181,4 @@ App.prototype = {






module.exports = App module.exports = App
5 changes: 4 additions & 1 deletion lib/ci/test_reporters/xunit_reporter.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ XUnitReporter.prototype = {
this.total++ this.total++
if (data.passed) this.pass++ if (data.passed) this.pass++
}, },
finish: function(){ finish: function(writeStream){
if (this.silent) return if (this.silent) return
this.endTime = new Date() this.endTime = new Date()
this.out.write(this.summaryDisplay()) this.out.write(this.summaryDisplay())
this.out.write('\n') this.out.write('\n')
if(writeStream) {
writeStream.write(this.summaryDisplay())
}
}, },
summaryDisplay: function(){ summaryDisplay: function(){
return '<testsuite name="Testem Tests" tests="' + this.total + return '<testsuite name="Testem Tests" tests="' + this.total +
Expand Down
19 changes: 18 additions & 1 deletion tests/ci/ci_tests.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ var Process = require('did_it_work')
describe('ci mode app', function(){ describe('ci mode app', function(){


beforeEach(function(done){ beforeEach(function(done){
fs.exists('test-output.xml', function(exists) {
if(exists) {
fs.unlinkSync('test-output.xml');
}
});
fs.unlink('tests/fixtures/tape/public/bundle.js', function(){ fs.unlink('tests/fixtures/tape/public/bundle.js', function(){
done() done()
}) })
Expand Down Expand Up @@ -75,6 +80,18 @@ describe('ci mode app', function(){
var app = new App(config) var app = new App(config)
assert.strictEqual(app.reporter, fakeReporter) assert.strictEqual(app.reporter, fakeReporter)
}) })

it('allow passing in out_file from config', function() {
var outFile = 'test-output.xml';
assert.equal(fs.existsSync(outFile),false)
var config = new Config('ci', {
'out_file': outFile
});
var app = new App(config);
console.log('app in test:', app)
assert.strictEqual(app.outFile.path, outFile);
assert.equal(fs.existsSync(outFile),true);
})


it('wrapUp reports error to reporter', function(){ it('wrapUp reports error to reporter', function(){
var app = new App(new Config('ci')) var app = new App(new Config('ci'))
Expand Down Expand Up @@ -269,4 +286,4 @@ describe('runHook', function(){
}) })
}) })


}) })