curl-amd
Version:
curl.js is small, fast, extensible module loader that handles AMD, CommonJS Modules/1.1, CSS, HTML/text, and legacy scripts.
76 lines (65 loc) • 1.83 kB
HTML
<html>
<head>
<title>package-specific config test</title>
<script>
curl = {
baseUrl: '',
paths: {
curl: '../src/curl'
},
packages: {
commonjs: {
path: 'support/commonjs',
config: {
injectScript: true,
moduleLoader: 'curl/loader/cjsm11',
prop: 27
}
},
// this package should not use the moduleLoader above
hybrid: {
path: 'support/commonjs'
}
}
};
</script>
<script src="../src/curl.js" type="text/javascript"></script>
<script type="text/javascript">
curl(
[
// test modules:
// load at least one from the configured package
'commonjs/nakedDependentCjsm1.1',
'commonjs/nakedSimpleCjsm1.1',
'commonjs/return-config',
'hybrid/module',
'domReady!' // wait here since code inside test changes baseUrl, foiling fetch of domReady! in call to write()
]
).then(
function (dep, simple, cfg, module) {
var test3 = !!module,
test4 = !!dep;
write((test3 ? 'SUCCESS' : 'FAILED') + ': package without custom module loader should be loaded');
write((test4 ? 'SUCCESS' : 'FAILED') + ': package with custom module loader should be loaded');
write((cfg.config().prop == 27 ? 'SUCCESS' : 'FAILED') + ': package config should be passed through to module');
write(('baseUrl' in cfg.config() ? 'SUCCESS' : 'FAILED') + ': base config should be passed through to module');
curl({
baseUrl: 'foo'
});
write((cfg.config().baseUrl == 'foo' ? 'FAILED' : 'SUCCESS') + ': module config should not change when curl\'s config is modified: ' + cfg.config().baseUrl);
},
function (ex) {
write('FAILED: ' + ex.message);
}
);
function write (msg) {
curl('domReady!', function () {
document.body.appendChild(document.createElement('div')).innerHTML = msg;
});
}
</script>
</head>
<body>
</body>
</html>