Permalink
Browse files

Fix failing tests

  • Loading branch information...
1 parent d6b92ce commit 3913152bc954c53b4b75d96003d556b9a1319a6f @kpdecker kpdecker committed Oct 17, 2013
Showing with 19 additions and 16 deletions.
  1. +1 −1 lumbar-loader-backbone.js
  2. +2 −4 lumbar-loader-localstorage.js
  3. +1 −1 lumbar-loader.js
  4. +1 −1 test/js/base.js
  5. +14 −9 test/js/local-storage.js
@@ -13,7 +13,7 @@ module.exports.initBackboneLoader = function(loaderModule, failure) {
return function() {
if (lumbarLoader.isLoaded(moduleName)) {
// The module didn't implement the proper route
- failure && failure('missing-route', moduleName);
+ failure && failure({type: 'missing-route', moduleName: moduleName}, moduleName);
return;
} else if (pendingModules[moduleName]) {
// Do not exec the backbone callback multiple times
@@ -9,12 +9,10 @@ lumbarLoader.loadJS = function(moduleName, callback) {
callback();
return true;
} catch (exception) {
- /* NOP */
- callback({moduleName: moduleName, type: 'javascript', exception: exception});
+ return callback({moduleName: moduleName + '.js', type: 'javascript', exception: exception});
}
- } else {
- callback({moduleName: moduleName + '.js', type: 'connection', httpStatus: status});
}
+ callback({moduleName: moduleName + '.js', type: err ? 'connection' : 'javascript', httpStatus: status});
});
return 1;
}).length;
View
@@ -98,7 +98,7 @@ function loadResources(moduleName, field, callback, create) {
var href = checkLoadResource(object, attr);
if (href && !lumbarLoadedResources[href]) {
var el = create(href, function(err) {
- if (err === 'connection') {
+ if (err && err.type === 'connection') {
lumbarLoadedResources[href] = false;
}
callback(err);
View
@@ -5,7 +5,7 @@ window.failedModules = [];
exports.init = function(loaderModule) {
loaderModule.loader.initEvents();
exports.initBackboneLoader(loaderModule, function (type, module) {
- failedModules.push({type: type, module: module});
+ failedModules.push({type: type && type.type, module: module});
});
Backbone.history.start();
};
@@ -40,7 +40,7 @@ setTimeout(function(){
test('empty zero responses are connection errors', function() {
QUnit.expect(3);
Loader.loader.loadModule('moduleNoRoute', function(err) {
- QUnit.equal(err, 'connection');
+ QUnit.deepEqual(err, {moduleName: 'moduleNoRoute.js', type: 'connection', httpStatus: 0});
});
QUnit.equal(this.requests.length, 1);
this.requests[0].respond(0, {}, '');
@@ -68,18 +68,20 @@ setTimeout(function(){
QUnit.equal(LocalCache.store.callCount, 2);
});
test('empty responses with status are javascript errors', function() {
- QUnit.expect(3);
+ QUnit.expect(4);
Loader.loader.loadModule('moduleNoRoute', function(err) {
- QUnit.equal(err, 'javascript');
+ QUnit.equal(err.moduleName, 'moduleNoRoute.js');
+ QUnit.equal(err.type, 'javascript');
});
QUnit.equal(this.requests.length, 1);
this.requests[0].respond(200, {}, '');
QUnit.equal(LocalCache.store.callCount, 0);
});
test('exec errors are javascript errors', function() {
- QUnit.expect(3);
+ QUnit.expect(4);
Loader.loader.loadModule('moduleNoRoute', function(err) {
- QUnit.equal(err, 'javascript');
+ QUnit.equal(err.moduleName, 'moduleNoRoute.js');
+ QUnit.equal(err.type, 'javascript');
});
QUnit.equal(this.requests.length, 1);
this.requests[0].respond(200, {}, '<foo');
@@ -91,7 +93,7 @@ setTimeout(function(){
var self = this;
Loader.loader.loadModule('moduleNoRoute', function(err) {
- QUnit.equal(err, 'connection');
+ QUnit.deepEqual(err, {moduleName: 'moduleNoRoute.js', type: 'connection', httpStatus: 404});
Loader.loader.loadModule('moduleNoRoute', function(err) {
QUnit.equal(err, undefined);
@@ -104,7 +106,7 @@ setTimeout(function(){
});
QUnit.equal(this.requests.length, 1);
- this.requests[0].respond(0, {}, '');
+ this.requests[0].respond(404, {}, '');
});
test('subsequent requests are ignored after success', function() {
@@ -151,10 +153,10 @@ setTimeout(function(){
var self = this;
Loader.loader.loadModule('moduleNoRoute', function(err) {
- QUnit.equal(err, 'javascript');
+ QUnit.equal(err.type, 'javascript');
});
Loader.loader.loadModule('moduleNoRoute', function(err) {
- QUnit.equal(err, 'javascript');
+ QUnit.equal(err.type, 'javascript');
});
QUnit.equal(this.requests.length, 1);
@@ -163,6 +165,7 @@ setTimeout(function(){
});
test('backbone routes are reattempted after connection failure', function() {
+ debugger;
QUnit.expect(5);
this.spy(Backbone.history, 'loadUrl');
@@ -171,6 +174,8 @@ setTimeout(function(){
QUnit.equal(this.requests.length, 1);
this.requests[0].respond(0, {}, '');
+ console.log('respond!');
+
Backbone.history.navigate('');
Backbone.history.navigate('module2', true);
QUnit.equal(this.requests.length, 2);

0 comments on commit 3913152

Please sign in to comment.