Permalink
Browse files

Make it work in the browser

  • Loading branch information...
1 parent ce7b001 commit 4436d7d36bf23234f6e0c665d48eb4cf1d61e235 @kriszyp committed Jan 13, 2012
Showing with 34 additions and 8 deletions.
  1. +25 −1 assert.js
  2. +9 −7 runner.js
View
@@ -1,7 +1,31 @@
// Based on http://wiki.commonjs.org/wiki/Unit_Testing/1.0#Assert with
// modifications to handle promises
(function(define){
-define(["promised-io/promise", "assert"],function(promise, assert){
+define(["promised-io/promise"],function(promise){
+var assert;
+try{
+ assert = require("assert");
+}catch(e){
+ assert = {
+ equal: function(a, b, message){
+ console.assert(a == b, message);
+ },
+ deepEqual: function(a, b, message){
+ if(a && typeof a == "object" && b && typeof b == "object"){
+ for(var i in a){
+ assert.deepEqual(a[i], b[i], message);
+ }
+ for(var i in b){
+ if(!(i in a)){
+ assert.equal(a[i], b[i], message);
+ }
+ }
+ }else{
+ console.assert(a == b, message);
+ }
+ },
+ }
+}
var exports = {};
var when = promise.when;
exports.assert = {};
View
@@ -6,14 +6,16 @@ var when = promise.when,
onError;
function run(tests, args){
if(!args){
- var params = require("promised-io/process").args;
- args = {};
- for(var i = 0; i < params.length; i++){
- if(params[i].charAt(0) == "-"){
- args[params[i].substring(1)] = params[i+1];
- params++;
+ try{
+ var params = require("promised-io/process").args;
+ args = {};
+ for(var i = 0; i < params.length; i++){
+ if(params[i].charAt(0) == "-"){
+ args[params[i].substring(1)] = params[i+1];
+ params++;
+ }
}
- }
+ }catch(e){}
}
print("Running tests ");
doTests(compileTests(tests, args));

0 comments on commit 4436d7d

Please sign in to comment.