UNPKG

curl-amd

Version:

curl.js is small, fast, extensible module loader that handles AMD, CommonJS Modules/1.1, CSS, HTML/text, and legacy scripts.

112 lines (99 loc) 2.08 kB
<!DOCTYPE HTML> <html> <head> <title>test then()</title> <script> curl = { paths: { curl: '../src/curl/' }, plugins: { js: { timeout: 500 } } }; </script> <script src="../src/curl.js" type="text/javascript"></script> <script type="text/javascript"> // test modules curl( ['stuff/three', 'stuff/one'] ).then( function (three, one) { write('SUCCESS: then() called'); if (three == 3 && one == 1) { write('SUCCESS: modules passed to then()'); } else { write('FAILED: modules not passed to then()'); } }, function (ex) { write('FAILED: ' + ex.message); } ).then( function (three, one) { write('SUCCESS: 2nd then() called'); if (three == 3 && one == 1) { write('SUCCESS: modules passed to 2nd then()'); } else { write('FAILED: modules not passed to 2nd then()'); } } ); // test 404 curl( ['stuff/does-not-exist'] ).then( function (WAT) { write('FAILED: then() called when module doesn\' exist'); }, function (ex) { write('SUCCESS: fail brach called when module doesn\'t exist. Message: ' + ex.message); } ); // test x-domain 404 curl( ['http://cujojs.com/this-doesnt-exist'] ).then( function (WAT) { write('FAILED: then() called when xdomain module doesn\' exist'); }, function (ex) { write('SUCCESS: fail branch called when xdomain module doesn\'t exist. Message: ' + ex.message); } ); // test js! plugin curl( ['js!stuff/plain_old.js!exports=testDomain.foo'] ).then( function (foo) { write('SUCCESS: js! plugin.'); }, function (ex) { write('FAILED: js! plugin. ' + ex.message); } ); // test js! plugin curl( ['js!stuff/plain_old-bad-url.js!exports=testDomain.thiscantexist'] ).then( function (foo) { write('FAILED: js! plugin didn\'t detect 404.'); }, function (ex) { write('SUCCESS: js! plugin detected 404. '); } ); function write (msg) { curl('domReady!', function () { document.body.appendChild(document.createElement('div')).innerHTML = msg; }); } </script> </head> <body> </body> </html>