Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
no longer tests for modules in the cache by checking for truthiness (…
…leftover from earlier assumption that all modules would have exports objects). with tests
- Loading branch information
John Hann
committed
Feb 28, 2012
1 parent
a11826c
commit efd3726
Showing
3 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<title>undefined module loads once</title> | ||
|
||
<script> | ||
curl = { | ||
baseUrl: '', | ||
paths: { | ||
curl: '../src/curl' | ||
} | ||
}; | ||
|
||
</script> | ||
<script src="../src/curl.js" type="text/javascript"></script> | ||
|
||
<script type="text/javascript"> | ||
|
||
curl(['curl/_privileged', 'domReady!'], function (priv) { | ||
|
||
// override curl's insertScript function with an injected spy | ||
|
||
function MethodSpy (method, context) { | ||
var count, orig, spy; | ||
|
||
count = 0; | ||
orig = context[method]; | ||
|
||
context[method] = function () { | ||
count++; | ||
return orig.apply(context, arguments); | ||
}; | ||
|
||
return { | ||
calledNever: function () { return count == 0; }, | ||
calledOnce: function () { return count == 1; }, | ||
calledTwice: function () { return count == 2; }, | ||
calledMany: function (howMany) { return count == howMany; } | ||
}; | ||
} | ||
|
||
var core = priv.core, | ||
origLoadScript = core.loadScript, | ||
Promise = priv.Promise, | ||
module1 = 'stuff/undefined-module'; | ||
|
||
function runTest (moduleId, howMany) { | ||
|
||
var spy = new MethodSpy('loadScript', core), | ||
promise = new Promise(), | ||
count = 2; | ||
|
||
function countdown () { | ||
if (--count == 0) { | ||
promise.resolve(); | ||
} | ||
} | ||
|
||
curl([moduleId], function (whatevs) {}).then( | ||
countdown, | ||
function (ex) { | ||
write('FAILED: on ' + moduleId + ' exception:' + ex); | ||
} | ||
); | ||
|
||
curl([moduleId], function (whatevs) {}).then( | ||
countdown, | ||
function (ex) { | ||
write('FAILED: on ' + moduleId + ' exception:' + ex); | ||
} | ||
); | ||
|
||
if (spy.calledMany(howMany || 0)) { | ||
write('SUCCESS: loaded ' + moduleId + ' exactly once'); | ||
} | ||
else { | ||
write('FAILED: loaded ' + moduleId + ' more than once'); | ||
} | ||
|
||
priv.core.loadScript = origLoadScript; | ||
|
||
return promise; | ||
|
||
} | ||
window.runTest = runTest; | ||
window.module1 = module1; | ||
|
||
runTest(module1, 1); | ||
|
||
}); | ||
|
||
function write (msg) { | ||
document.body.appendChild(document.createElement('div')).innerHTML = msg; | ||
} | ||
|
||
</script> | ||
|
||
</head> | ||
<body> | ||
|
||
<button onclick="runTest(window.module1);">press this button to load the local module again</button> | ||
<button onclick="curl('curl/_privileged',console.log);">dump cache to console</button> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
define(function () { | ||
// returns nothing | ||
}); |