Permalink
Browse files

Latest changes for Node.js

  • Loading branch information...
1 parent 68f0817 commit 5e249139d89b5596eacbb275fa0f3c65640bf8ef nzakas committed Feb 15, 2011
View
34 javascript/build/yuitest/npm/cli.js
@@ -13,7 +13,9 @@ var fs = require("fs"),
//options collected from command line
var options = {
- verbose: false
+ verbose: false,
+ webcompat: false,
+ help: false
};
//-----------------------------------------------------------------------------
@@ -51,6 +53,16 @@ function getFiles(dir){
return files;
}
+function outputHelp(){
+ stdout.write([
+ "\nUsage: yuitest [options] [file|dir]*",
+ " ",
+ "Global Options",
+ " --help Displays this information.",
+ " --verbose Display informational messages and warnings.",
+ " --webcompat Load tests designed for use in browsers."
+ ].join("\n") + "\n\n");
+}
//-----------------------------------------------------------------------------
// Process command line
@@ -76,6 +88,11 @@ while(arg){
arg = args.shift();
}
+if (options.help){
+ outputHelp();
+ process.exit(0);
+}
+
//get the full path names
files = files.map(function(filename){
return path.join(process.cwd(), filename);
@@ -104,7 +121,7 @@ TestRunner.subscribe("complete", function(event){
// Include test files
//-----------------------------------------------------------------------------
-var i, len;
+var i, len, output;
if (files.length){
for (i=0, len=files.length; i < len; i++){
@@ -113,8 +130,17 @@ if (files.length){
stderr.write("[INFO] Loading " + files[i] + "\n");
}
- var output = fs.readFileSync(files[i]);
- vm.runInThisContext("(function(YUITest){\n" + output + "\n})", files[i])(YUITest);
+ if (options.webcompat){
+ output = fs.readFileSync(files[i]);
+ vm.runInThisContext("(function(YUITest){\n" + output + "\n})", files[i])(YUITest);
+ } else {
+ try {
+ require(files[i]);
+ } catch (ex) {
+ stderr.write("[ERROR] No tests loaded from " + files[i] + ". If you're not using CommonJS module format, try running with --webcompat option.\n");
+ process.exit(1);
+ }
+ }
}
} else {
stderr.write("[ERROR] No tests to run, exiting.\n");
View
2 javascript/build/yuitest/npm/package.json
@@ -1,6 +1,6 @@
{
"name": "yuitest",
- "version": "0.6.0",
+ "version": "0.6.2",
"description": "YUI Test Library on NodeJS",
"author": "Nicholas C. Zakas <nzakas@yahoo-inc.com>",
"bugs": { "web" : "http://yuilibrary.com/projects/yuitest/issues" },
View
2 javascript/npm/package.json
@@ -1,6 +1,6 @@
{
"name": "yuitest",
- "version": "0.6.0",
+ "version": "0.6.2",
"description": "YUI Test Library on NodeJS",
"author": "Nicholas C. Zakas <nzakas@yahoo-inc.com>",
"bugs": { "web" : "http://yuilibrary.com/projects/yuitest/issues" },
View
34 javascript/src/nodejs/cli.js
@@ -13,7 +13,9 @@ var fs = require("fs"),
//options collected from command line
var options = {
- verbose: false
+ verbose: false,
+ webcompat: false,
+ help: false
};
//-----------------------------------------------------------------------------
@@ -51,6 +53,16 @@ function getFiles(dir){
return files;
}
+function outputHelp(){
+ stdout.write([
+ "\nUsage: yuitest [options] [file|dir]*",
+ " ",
+ "Global Options",
+ " --help Displays this information.",
+ " --verbose Display informational messages and warnings.",
+ " --webcompat Load tests designed for use in browsers."
+ ].join("\n") + "\n\n");
+}
//-----------------------------------------------------------------------------
// Process command line
@@ -76,6 +88,11 @@ while(arg){
arg = args.shift();
}
+if (options.help){
+ outputHelp();
+ process.exit(0);
+}
+
//get the full path names
files = files.map(function(filename){
return path.join(process.cwd(), filename);
@@ -104,7 +121,7 @@ TestRunner.subscribe("complete", function(event){
// Include test files
//-----------------------------------------------------------------------------
-var i, len;
+var i, len, output;
if (files.length){
for (i=0, len=files.length; i < len; i++){
@@ -113,8 +130,17 @@ if (files.length){
stderr.write("[INFO] Loading " + files[i] + "\n");
}
- var output = fs.readFileSync(files[i]);
- vm.runInThisContext("(function(YUITest){\n" + output + "\n})", files[i])(YUITest);
+ if (options.webcompat){
+ output = fs.readFileSync(files[i]);
+ vm.runInThisContext("(function(YUITest){\n" + output + "\n})", files[i])(YUITest);
+ } else {
+ try {
+ require(files[i]);
+ } catch (ex) {
+ stderr.write("[ERROR] No tests loaded from " + files[i] + ". If you're not using CommonJS module format, try running with --webcompat option.\n");
+ process.exit(1);
+ }
+ }
}
} else {
stderr.write("[ERROR] No tests to run, exiting.\n");
View
1 javascript/src/nodejs/init.js
@@ -1 +0,0 @@
-//initialization for Node.js

0 comments on commit 5e24913

Please sign in to comment.