curl-amd
Version:
curl.js is small, fast, extensible module loader that handles AMD, CommonJS Modules/1.1, CSS, HTML/text, and legacy scripts.
80 lines (62 loc) • 1.98 kB
HTML
<html>
<head>
<title>local require tests</title>
<script>
curl = {
baseUrl: '',
paths: {
curl: '../src/curl',
modules: 'stuff'
},
packages: [
{ name: 'pkg', location: 'support/commonjs' }
]
};
</script>
<script src="../src/curl.js" type="text/javascript"></script>
<script type="text/javascript">
curl(['curl/_privileged', 'tdd/Spy', 'tdd/configureAsserts', 'domReady!'], function (priv, Spy, configureAsserts) {
// test local require
var module1 = 'modules/three';
function runTest (moduleId, howMany, assert) {
curl([moduleId, 'require']).then(
function (one, require) {
// basics
assert.equal('function', typeof require, '`require` should be a function');
assert.equal('function', typeof require.toUrl, '`require.toUrl` should be a function');
// resolution
assert(!!require('modules/one'), 'r-value require should return a known-cached module');
assert.equal('stuff/one', require.toUrl('modules/one'), '`require.toUrl` should map ids to urls (paths)');
assert.equal('support/commonjs/main', require.toUrl('pkg'), '`require.toUrl` should map ids to urls (packages)');
// async callbacks
require(['modules/two'],
function () { assert(true, 'async require called callback'); },
function () { assert(false, 'async require called callback'); }
);
require(['modules/two-fubar'],
function () { assert(false, 'async require called errback'); },
function () { assert(true, 'async require called errback'); }
);
},
function (ex) {
failure('on ' + moduleId + ' exception:' + ex);
}
);
}
runTest(module1, 1, configureAsserts(success, failure));
});
function success (msg) {
write('SUCCESS: ' + msg);
}
function failure (msg) {
write('FAILED: ' + msg);
}
function write (msg) {
document.body.appendChild(document.createElement('div')).innerHTML = msg;
}
</script>
</head>
<body>
</body>
</html>