test-dependencies-async.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>reveal.js - Test Async Dependencies</title>
  6. <link rel="stylesheet" href="../css/reveal.css">
  7. <link rel="stylesheet" href="qunit-2.5.0.css">
  8. </head>
  9. <body style="overflow: auto;">
  10. <div id="qunit"></div>
  11. <div id="qunit-fixture"></div>
  12. <div class="reveal" style="display: none;">
  13. <div class="slides">
  14. <section>Slide content</section>
  15. </div>
  16. </div>
  17. <script src="../js/reveal.js"></script>
  18. <script src="qunit-2.5.0.js"></script>
  19. <script>
  20. var externalScriptSequence = '';
  21. var scriptCount = 0;
  22. QUnit.config.autostart = false;
  23. QUnit.module( 'Async Dependencies' );
  24. QUnit.test( 'Async scripts are loaded', function( assert ) {
  25. assert.expect( 5 );
  26. var done = assert.async( 5 );
  27. function callback( event ) {
  28. if( externalScriptSequence.length === 1 ) {
  29. assert.ok( externalScriptSequence === 'A', 'first callback was sync script' );
  30. done();
  31. }
  32. else {
  33. assert.ok( true, 'async script loaded' );
  34. done();
  35. }
  36. if( externalScriptSequence.length === 4 ) {
  37. assert.ok( externalScriptSequence.indexOf( 'A' ) !== -1 &&
  38. externalScriptSequence.indexOf( 'B' ) !== -1 &&
  39. externalScriptSequence.indexOf( 'C' ) !== -1 &&
  40. externalScriptSequence.indexOf( 'D' ) !== -1, 'four unique scripts were loaded' );
  41. done();
  42. }
  43. scriptCount ++;
  44. }
  45. Reveal.initialize({
  46. dependencies: [
  47. { src: 'assets/external-script-a.js', async: false, callback: callback },
  48. { src: 'assets/external-script-b.js', async: true, callback: callback },
  49. { src: 'assets/external-script-c.js', async: true, callback: callback },
  50. { src: 'assets/external-script-d.js', async: true, callback: callback }
  51. ]
  52. });
  53. });
  54. QUnit.start();
  55. </script>
  56. </body>
  57. </html>