Skip to content

Commit

Permalink
add test for now #144
Browse files Browse the repository at this point in the history
  • Loading branch information
ericz committed Oct 4, 2011
1 parent 31b835e commit 7e5c48d
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 7 deletions.
90 changes: 86 additions & 4 deletions client/public/spec/VariableSpec.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ describe("Variable Sync", function() {
it("can handle array and object sync edge cases", function() { it("can handle array and object sync edge cases", function() {


function setIfEqual(k, v) { function setIfEqual(k, v) {
console.log(v, val);
equals = SpecHelper.deepEqual(val, v) && key === k; equals = SpecHelper.deepEqual(val, v) && key === k;
} }


Expand All @@ -61,7 +60,7 @@ describe("Variable Sync", function() {
// Create new variables // Create new variables
now[key] = val; now[key] = val;



// Call server function to check if value synced // Call server function to check if value synced
var equals; var equals;
runs(function(){ runs(function(){
Expand All @@ -81,7 +80,7 @@ describe("Variable Sync", function() {
now[key] = val; now[key] = val;
equals = false; equals = false;
}); });



runs(function(){ runs(function(){
now.variableCheck(key, setIfEqual); now.variableCheck(key, setIfEqual);
Expand All @@ -90,10 +89,94 @@ describe("Variable Sync", function() {
waitsFor(function(){ waitsFor(function(){
return equals; return equals;
}, "setting of object leaf node", 5000); }, "setting of object leaf node", 5000);

runs(function(){
expect(equals).toBeTruthy();
});

runs(function(){
val = {a:1, b:2};
now[key] = val;
equals = false;
});


runs(function(){
now.variableCheck(key, setIfEqual);
});

waitsFor(function(){
return equals;
}, "setting of object with children leaf node", 5000);


runs(function(){ runs(function(){
expect(equals).toBeTruthy(); expect(equals).toBeTruthy();
}); });

runs(function(){
val.a = [];
equals = false;
setTimeout(function(){
val.b = {};
}, 500);
});

runs(function(){
now.variableCheck(key, setIfEqual);
});

waitsFor(function(){
return equals;
}, "setting of object child array leaf node", 5000);

runs(function(){
expect(equals).toBeTruthy();
});

runs(function(){
val.b = {};
equals = false;
});


runs(function(){
now.variableCheck(key, setIfEqual);
});

waitsFor(function(){
return equals;
}, "setting of object child object leaf node", 5000);

runs(function(){
expect(equals).toBeTruthy();
});


runs(function(){
val = ['1','2'];
now[key] = val;
equals = false;
});


runs(function(){
now.variableCheck(key, setIfEqual);
});

waitsFor(function(){
return equals;
}, "make sures arrays sent are still arrays", 5000);

runs(function(){
expect(equals).toBeTruthy();
});

runs(function(){
now.x = {};
now.x.y = false;
now.x.y = {a:1};
expect(now.x.y.a).toEqual(1);
});


}); });


Expand Down Expand Up @@ -128,7 +211,6 @@ describe("Variable Sync", function() {
now[key2] = {a: 1, b: []}; now[key2] = {a: 1, b: []};


now.variableCheck(key2, function(k, v) { now.variableCheck(key2, function(k, v) {
console.log(arguments);
equals = v.b.length === 0; equals = v.b.length === 0;
}); });
}); });
Expand Down
9 changes: 6 additions & 3 deletions client/testserver.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ var server = require('http').createServer(function (request, response) {
}); });
}); });




server.listen(80);

var nowjs = require('now'); var nowjs = require('now');


var everyone = nowjs.initialize(server); var everyone = nowjs.initialize(server, {socketio: {'log level': 3}});





everyone.now.variableCheck = function(key, cb) { everyone.now.variableCheck = function(key, cb) {
Expand Down Expand Up @@ -48,5 +53,3 @@ everyone.now.eval = function(code){
everyone.now.joinGroup = function(group) { everyone.now.joinGroup = function(group) {
nowjs.getGroup(group).addUser(this.user.clientId); nowjs.getGroup(group).addUser(this.user.clientId);
} }

server.listen(80)

0 comments on commit 7e5c48d

Please sign in to comment.