Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 29310aa6a253ec13b479b00841d3adeb554cf9d9 1 parent 25f14c3
@ggoodale ggoodale authored
View
1  .gitignore
@@ -1 +1,2 @@
node_modules
+reports
View
47 lib/mf-tools/test/testBuilder.js
@@ -1,5 +1,5 @@
(function() {
- var TestBuilder, exec, path, util, _harnessMod,
+ var TestBuilder, exec, fs, glob, path, util, _harnessMod,
__slice = Array.prototype.slice;
exec = require("child_process").exec;
@@ -8,6 +8,10 @@
util = require("util");
+ fs = require('fs');
+
+ glob = require('glob');
+
_harnessMod = path.join(__dirname, "harness.js");
TestBuilder = (function() {
@@ -63,13 +67,13 @@
};
TestBuilder.prototype.build = function() {
- var glob, test, _ref,
+ var test, testGlob, _ref,
_this = this;
if (!this._task) "TestBuilder requires task function to define tasks.";
_ref = this._testDefinitions;
for (test in _ref) {
- glob = _ref[test];
- this._addTestTask(test, glob);
+ testGlob = _ref[test];
+ this._addTestTask(test, testGlob);
}
this._task("test", "Run all tests", function() {
var t, _results;
@@ -91,7 +95,7 @@
return "NODE_PATH=$NODE_PATH:" + (this._includePaths.join(':')) + " mocha --globals window,document -u " + this._mochaUi + " -R " + this._mochaReporter + " --require " + (this._mochaPreRequire());
};
- TestBuilder.prototype._runTests = function(glob, msg) {
+ TestBuilder.prototype._runTests = function(testGlob, msg) {
var childEnv, k, v, _ref, _ref2,
_this = this;
childEnv = {};
@@ -103,13 +107,32 @@
if (childEnv["NODE_ENV"] == null) {
childEnv["NODE_ENV"] = (_ref2 = this._env) != null ? _ref2 : "test";
}
- return exec("" + (this._testCmd()) + " " + glob, {
- env: childEnv,
- encoding: 'utf8'
- }, function(err, stdout, stderr) {
- util.puts(stdout);
- console.log(stderr);
- if (err !== null) return _this._retVal = 1;
+ return glob(testGlob, function(err, files) {
+ var child, file, outFile, _i, _len, _results;
+ _results = [];
+ for (_i = 0, _len = files.length; _i < _len; _i++) {
+ file = files[_i];
+ child = exec("" + (_this._testCmd()) + " " + file, {
+ env: childEnv,
+ encoding: 'utf8'
+ }, function(err, stdout, stderr) {
+ util.puts(stdout);
+ return console.log(stderr);
+ });
+ if (err !== null) _this._retVal = 1;
+ if (_this._mochaReporter === 'xunit') {
+ if (!(fs.readdirSync('.').indexOf('reports') >= 0)) {
+ fs.mkdirSync('reports');
+ }
+ outFile = fs.createWriteStream("reports/" + (file.replace(/^.*[\\\/]/, '')) + ".xml", {
+ flags: 'w'
+ });
+ _results.push(child.stdout.pipe(outFile));
+ } else {
+ _results.push(void 0);
+ }
+ }
+ return _results;
});
};
View
3  package.json
@@ -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": {}
View
36 src/test/testBuilder.coffee
@@ -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.
Something went wrong with that request. Please try again.