Skip to content

Loading…

added ability to specify xunit output file #384

Closed
wants to merge 1 commit into from

2 participants

@vire
  • necessary to add to the testem config a key output_file : file-name.xml
  • for now only for the xunit ci reporter
  • test checks for output file presence
@vire vire added abilyt to specify xunit output file
* neceary to add to the testem config a key output_file : file-name.xml
e5ecd35
@airportyh

I don't like the fact that the output_file is only specific to xunit when there's no reason it has to be.

@airportyh airportyh closed this
@vire

@airportyh hi,

I made this patch primary for a specific CI builder setup where the output of thestem wasn't allowed to write direct via stdout testem ci > test-result.xml (and was later consumed with some test report parser).

I think in most cases, where an CI/build tool is running javascirpt tests, it can also deal with standard testem's output or there is an option to use stdout.

@airportyh

If the output_file option is generic and is applicable to all reporters, I would be more open to this feature.

@jschilli jschilli referenced this pull request in ember-cli/ember-cli
Closed

ember test ci --silent outputs warnings #3466

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 2, 2014
  1. @vire

    added abilyt to specify xunit output file

    vire committed
    * neceary to add to the testem config a key output_file : file-name.xml
Showing with 33 additions and 4 deletions.
  1. +11 −2 lib/ci/index.js
  2. +4 −1 lib/ci/test_reporters/xunit_reporter.js
  3. +18 −1 tests/ci/ci_tests.js
View
13 lib/ci/index.js
@@ -10,6 +10,8 @@ var HookRunner = require('../hook_runner')
var log = require('npmlog')
var cleanExit = require('../clean_exit')
var isa = require('../isa')
+var fs = require('fs')
+var wStream = null;
function App(config, finalizer){
this.exited = false
@@ -20,6 +22,7 @@ function App(config, finalizer){
this.hookRunners = {}
this.results = []
this.reporter = this.initReporter(this.config.get('reporter'))
+ this.outFile = this.createWStream(this.config.get('out_file'))
if (!this.reporter){
console.error('Test reporter `' + reporter + '` not found.')
this.cleanExit(1)
@@ -132,7 +135,7 @@ App.prototype = {
}
})
}
- this.reporter.finish()
+ this.reporter.finish(this.outFile)
this.emit('tests-finish')
this.stopHookRunners()
this.stopServer(this.exit.bind(this))
@@ -161,6 +164,12 @@ App.prototype = {
return 0
},
+ createWStream: function(outFileName) {
+ if(outFileName) {
+ return fs.createWriteStream(outFileName);
+ }
+ },
+
exit: function(){
if (this.exited) return
this.cleanExit(this.getExitCode())
@@ -172,4 +181,4 @@ App.prototype = {
-module.exports = App
+module.exports = App
View
5 lib/ci/test_reporters/xunit_reporter.js
@@ -22,11 +22,14 @@ XUnitReporter.prototype = {
this.total++
if (data.passed) this.pass++
},
- finish: function(){
+ finish: function(writeStream){
if (this.silent) return
this.endTime = new Date()
this.out.write(this.summaryDisplay())
this.out.write('\n')
+ if(writeStream) {
+ writeStream.write(this.summaryDisplay())
+ }
},
summaryDisplay: function(){
return '<testsuite name="Testem Tests" tests="' + this.total +
View
19 tests/ci/ci_tests.js
@@ -12,6 +12,11 @@ var Process = require('did_it_work')
describe('ci mode app', function(){
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(){
done()
})
@@ -75,6 +80,18 @@ describe('ci mode app', function(){
var app = new App(config)
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(){
var app = new App(new Config('ci'))
@@ -269,4 +286,4 @@ describe('runHook', function(){
})
})
-})
+})
Something went wrong with that request. Please try again.