web-apps/vendor/requirejs/tests/undef/undefEnforceShim.html
Maxim Kadushkin 741b10515d webapps added
2016-03-10 21:48:53 -03:00

78 lines
2 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>require.js: requirejs.undef() Test</title>
<script type="text/javascript" src="../../require.js"></script>
<script type="text/javascript" src="../doh/runner.js"></script>
<script type="text/javascript" src="../doh/_browserRunner.js"></script>
<script type="text/javascript">
var doneCount = 0;
var master = new doh.Deferred();
function done() {
doneCount += 1;
//alert("done");
if (doneCount == 2) {
//alert("master callback");
master.callback(true);
}
}
requirejs.onError = function (err) {
var id = err.requireModules[0],
config = {paths: {}};
if (id !== 'dep') {
throw new Error('onError was expecting "dep" but got: ' + id);
}
requirejs.undef(id);
config.paths[id] = 'real';
requirejs.config(config);
requirejs(['dep'], function (dep) {
doh.is("real", dep.name);
done();
});
return;
throw err;
};
requirejs({
waitSeconds: 2,
enforceDefine: true,
shim: {
'globalFoo': {
exports: 'globalFoo'
}
}
}, ['globalFoo', 'dep'], function (globalFoo, dep) {
doh.is("globalFoo", globalFoo.name);
doh.is("real", dep.name);
done();
});
doh.register(
"undef",
[
{
name: "undef",
timeout: 5000,
runTest: function () {
return master;
}
}
]
);
doh.run();
</script>
</head>
<body>
<h1>require.js: requirejs.undef() Test</h1>
<p>Use requirejs.undef() to reset and load a module from a different path.</p>
<p>Check console for messages</p>
</body>
</html>