Permalink
Browse files

Added JUnitXML and TAP output for Node.js CLI

  • Loading branch information...
1 parent ff09bcf commit 41d612340ad539577b976ce50dc372cf210e76fb nzakas committed Feb 23, 2011
@@ -33,7 +33,8 @@ component.jsfiles= commonjs/Exports.js, \
core/TestRunner.js, \
nodejs/Node.js, \
nodejs/CLI.Logger.js, \
- nodejs/CLI.XUnit.js
+ nodejs/CLI.XUnit.js, \
+ nodejs/CLI.Format.js
#Override
global.build.base = ${component.jsfiles.base}/../build
@@ -20,7 +20,8 @@ var fs = require("fs"),
var options = {
verbose: false,
webcompat: false,
- help: false
+ help: false,
+ output: false
};
//-----------------------------------------------------------------------------
@@ -63,7 +64,9 @@ function outputHelp(){
"\nUsage: yuitest [options] [file|dir]*",
" ",
"Global Options",
+ " --groups groupname Run only tests cases that are part of groupname.",
" --help Displays this information.",
+ " --output format Specifies output format (junitxml, tap, xunit).",
" --verbose Display informational messages and warnings.",
" --webcompat Load tests designed for use in browsers."
].join("\n") + "\n\n");
@@ -83,7 +86,7 @@ while(arg){
options[arg.substring(2)] = true;
//get the next argument
- if (arg == "--groups"){
+ if (arg == "--groups" || arg == "--output"){
options[arg.substring(2)] = args.shift();
}
} else {
@@ -112,8 +115,25 @@ files = files.map(function(filename){
// Determine output format
//-----------------------------------------------------------------------------
-//TODO: Other types of output
-YUITest.Node.CLI.XUnit();
+switch(options.output){
+ case "junitxml":
+ if (options.verbose){
+ stderr.write("[INFO] Using JUnitXML output format.\n");
+ }
+ YUITest.Node.CLI.Format(YUITest.TestFormat.JUnitXML);
+ break;
+ case "tap":
+ if (options.verbose){
+ stderr.write("[INFO] Using TAP output format.\n");
+ }
+ YUITest.Node.CLI.Format(YUITest.TestFormat.TAP);
+ break;
+ default:
+ if (options.verbose){
+ stderr.write("[INFO] Using XUnit output format.\n");
+ }
+ YUITest.Node.CLI.XUnit();
+}
//-----------------------------------------------------------------------------
// Set up TestRunner
@@ -3643,3 +3643,29 @@ YUITest.Node.CLI.XUnit = function(){
};
+
+
+/**
+ * Console output that uses TestFormat formats.
+ * @namespace YUITest.Node.CLI
+ * @class Format
+ * @constructor
+ */
+YUITest.Node.CLI.Format = function(format){
+
+ var testRunner = YUITest.TestRunner;
+
+
+ //handles test runner events
+ function handleEvent(event){
+
+ var results = event.results,
+ sys = require('sys');
+
+ sys.print(format(results));
+ }
+
+ testRunner.subscribe(testRunner.COMPLETE_EVENT, handleEvent);
+
+};
+
@@ -3643,3 +3643,29 @@ YUITest.Node.CLI.XUnit = function(){
};
+
+
+/**
+ * Console output that uses TestFormat formats.
+ * @namespace YUITest.Node.CLI
+ * @class Format
+ * @constructor
+ */
+YUITest.Node.CLI.Format = function(format){
+
+ var testRunner = YUITest.TestRunner;
+
+
+ //handles test runner events
+ function handleEvent(event){
+
+ var results = event.results,
+ sys = require('sys');
+
+ sys.print(format(results));
+ }
+
+ testRunner.subscribe(testRunner.COMPLETE_EVENT, handleEvent);
+
+};
+

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -3643,3 +3643,29 @@ YUITest.Node.CLI.XUnit = function(){
};
+
+
+/**
+ * Console output that uses TestFormat formats.
+ * @namespace YUITest.Node.CLI
+ * @class Format
+ * @constructor
+ */
+YUITest.Node.CLI.Format = function(format){
+
+ var testRunner = YUITest.TestRunner;
+
+
+ //handles test runner events
+ function handleEvent(event){
+
+ var results = event.results,
+ sys = require('sys');
+
+ sys.print(format(results));
+ }
+
+ testRunner.subscribe(testRunner.COMPLETE_EVENT, handleEvent);
+
+};
+
@@ -20,7 +20,8 @@ var fs = require("fs"),
var options = {
verbose: false,
webcompat: false,
- help: false
+ help: false,
+ output: false
};
//-----------------------------------------------------------------------------
@@ -63,7 +64,9 @@ function outputHelp(){
"\nUsage: yuitest [options] [file|dir]*",
" ",
"Global Options",
+ " --groups groupname Run only tests cases that are part of groupname.",
" --help Displays this information.",
+ " --output format Specifies output format (junitxml, tap, xunit).",
" --verbose Display informational messages and warnings.",
" --webcompat Load tests designed for use in browsers."
].join("\n") + "\n\n");
@@ -83,7 +86,7 @@ while(arg){
options[arg.substring(2)] = true;
//get the next argument
- if (arg == "--groups"){
+ if (arg == "--groups" || arg == "--output"){
options[arg.substring(2)] = args.shift();
}
} else {
@@ -112,8 +115,25 @@ files = files.map(function(filename){
// Determine output format
//-----------------------------------------------------------------------------
-//TODO: Other types of output
-YUITest.Node.CLI.XUnit();
+switch(options.output){
+ case "junitxml":
+ if (options.verbose){
+ stderr.write("[INFO] Using JUnitXML output format.\n");
+ }
+ YUITest.Node.CLI.Format(YUITest.TestFormat.JUnitXML);
+ break;
+ case "tap":
+ if (options.verbose){
+ stderr.write("[INFO] Using TAP output format.\n");
+ }
+ YUITest.Node.CLI.Format(YUITest.TestFormat.TAP);
+ break;
+ default:
+ if (options.verbose){
+ stderr.write("[INFO] Using XUnit output format.\n");
+ }
+ YUITest.Node.CLI.XUnit();
+}
//-----------------------------------------------------------------------------
// Set up TestRunner

0 comments on commit 41d6123

Please sign in to comment.