Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated test suite to be runnable in NodeJS.

  • Loading branch information...
commit 4179fce2d193d884adc989f18c35d11acc05260f 1 parent 8a799cf
Zaim Bakar authored
Showing with 67 additions and 1 deletion.
  1. +6 −1 README
  2. +55 −0 test/runner.js
  3. +6 −0 test/test.js
View
7 README
@@ -24,4 +24,9 @@ http://goessner.net/articles/JsonPath/
Testing
-------
-To run the test suite, simply open test/test.html in your browser.
+To run the test suite, simply open test/test.html in your browser.
+
+To run the test suite in a server-side CommonJS environment, simply run the
+'test/test.js' JavaScript file. Currently only available in NodeJS:
+
+ $ node test/test.js
View
55 test/runner.js
@@ -0,0 +1,55 @@
+// Creates a test environment that can be run on NodeJS
+// re-exports the 'assert' module plus an additional 'test' function similar
+// to jqUnit.test
+
+var assert = require('assert'),
+ sys = require('sys');
+
+function ok(str) {
+ return '\033[32m' + str + '\033[39m';
+};
+
+function ex(str) {
+ return '\033[33m' + str + '\033[39m';
+};
+
+function err(str) {
+ return '\033[31m' + str + '\033[39m';
+};
+
+function bold(str) {
+ return '\033[1m' + str + '\033[22m';
+};
+
+// simulates jqUnit.test
+// prints out the test name and error message with pretty colours:
+// green: success
+// red: assertion errors
+// yellow: any other exceptions
+// does not print out individual assert messages
+function test(title, fn) {
+ var colour = ok,
+ result = 'OK: ',
+ message = '';
+ try {
+ fn();
+ }
+ catch (e) {
+ if (e.name == 'AssertionError') {
+ colour = err;
+ }
+ else {
+ colour = ex;
+ }
+ result = 'ER: ';
+ message = e.message;
+ }
+ sys.puts(colour(bold(result) + title + ' ' + bold(message)));
+};
+
+// re-export assert functions
+for (var name in assert) {
+ exports[name] = assert[name];
+}
+exports.equals = exports.equal;
+exports.test = test;
View
6 test/test.js
@@ -1,3 +1,9 @@
+if (typeof require == 'function' && typeof exports == 'object') {
+ var JSONQuery = require('../JSONQuery').JSONQuery,
+ jqUnit = require('./runner'),
+ jQuery = function(){}; // note: jQuery isn't even used here
+}
+
var tests = function($) {
var collection = [
Please sign in to comment.
Something went wrong with that request. Please try again.