Permalink
Browse files

Added individual file output to cake when using the xunit reporter.

  • Loading branch information...
1 parent 25f14c3 commit 29310aa6a253ec13b479b00841d3adeb554cf9d9 @ggoodale ggoodale committed Jun 4, 2012
Showing with 61 additions and 26 deletions.
  1. +1 −0 .gitignore
  2. +35 −12 lib/mf-tools/test/testBuilder.js
  3. +2 −1 package.json
  4. +23 −13 src/test/testBuilder.coffee
View
@@ -1 +1,2 @@
node_modules
+reports

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -3,7 +3,7 @@
"author": "Mason Browne <mason@massivelyfun.com> (http://massivelyfun.com/people/maseb)",
"name": "mf-tools",
"description": "Build and test tools.",
- "version": "0.0.2",
+ "version": "0.0.3",
"homepage": "http://massivelyfun.com/projects/mf-tools",
"repository": {
"type": "git",
@@ -21,6 +21,7 @@
"mocha": "= 0.10.1",
"chai": "= 0.3.3",
"jsdom": "= 0.2.10",
+ "glob": "= 3.1.5",
"phantom": "= 0.3.3"
},
"optionalDependencies": {}
@@ -1,6 +1,9 @@
{exec} = require "child_process"
path = require "path"
util = require "util"
+fs = require 'fs'
+glob = require 'glob'
+
_harnessMod = path.join(__dirname, "harness.js")
class TestBuilder
constructor: ->
@@ -39,8 +42,8 @@ class TestBuilder
unless @_task
"TestBuilder requires task function to define tasks."
- for test, glob of @_testDefinitions
- @_addTestTask test, glob
+ for test, testGlob of @_testDefinitions
+ @_addTestTask test, testGlob
@_task "test", "Run all tests", =>
@@ -53,20 +56,27 @@ class TestBuilder
_testCmd: ->
"NODE_PATH=$NODE_PATH:#{@_includePaths.join ':'} mocha --globals window,document -u #{@_mochaUi} -R #{@_mochaReporter} --require #{@_mochaPreRequire()}"
- _runTests: (glob, msg) ->
+ # Run our test. If we're running in xunit output mode, we want to write each test file's
+ # output to a separate file, so that xunit doesn't freak out.
+ _runTests: (testGlob, msg) ->
childEnv = {}
childEnv[k] = v for k,v of process.env
childEnv["NODE_ENV"] ?= (@_env ? "test")
- exec "#{@_testCmd()} #{glob}",
- env: childEnv
- encoding: 'utf8'
- , (err, stdout, stderr) =>
- # console.log "\n#{msg}\n==========================="
- util.puts stdout # verbiage
- console.log stderr # test summary
-
- @_retVal = 1 if err != null
-
+ glob testGlob, (err, files) =>
+ for file in files
+ child = exec "#{@_testCmd()} #{file}",
+ env: childEnv
+ encoding: 'utf8'
+ , (err, stdout, stderr) =>
+ # console.log "\n#{msg}\n==========================="
+ util.puts stdout # verbiage
+ console.log stderr # test summary
+ @_retVal = 1 if err != null
+ if @_mochaReporter == 'xunit'
+ fs.mkdirSync('reports') unless fs.readdirSync('.').indexOf('reports') >= 0
+ outFile = fs.createWriteStream "reports/#{file.replace(/^.*[\\\/]/, '')}.xml", { flags : 'w' }
+ child.stdout.pipe(outFile)
+
_addTestTask: (name, dir) ->
taskName = "test:#{name}"

0 comments on commit 29310aa

Please sign in to comment.