spec.html 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <html>
  2. <!-- Using a <blockquote> because it's an obscure tag -->
  3. <!-- which allows us to use document.querySelector() -->
  4. <!-- with generic tags freely inside Cypress tests. -->
  5. <blockquote id="root">
  6. <!-- This is where our test subjects will be injected. -->
  7. </blockquote>
  8. <script src="/../../packages/morph/dist/cdn.js"></script>
  9. <script src="/../../packages/persist/dist/cdn.js"></script>
  10. <script src="/../../packages/focus/dist/cdn.js"></script>
  11. <script src="/../../packages/intersect/dist/cdn.js"></script>
  12. <script src="/../../packages/collapse/dist/cdn.js"></script>
  13. <script src="/../../packages/anchor/dist/cdn.js"></script>
  14. <script src="/../../packages/mask/dist/cdn.js"></script>
  15. <script src="/../../packages/ui/dist/cdn.js"></script>
  16. <script>
  17. let root = document.querySelector('#root')
  18. // We aren't loading Alpine directly because we are expecting
  19. // Cypress to inject HTML into "#root", THEN we'll call
  20. // this function from Cypress to boot everything up.
  21. root.evalScripts = (extraJavaScript) => {
  22. // Load bespoke JavaScript.
  23. if (extraJavaScript) {
  24. let script = document.createElement('script')
  25. script.src = `data:text/javascript;base64,${btoa(`
  26. document.addEventListener('alpine:init', () => {
  27. ${extraJavaScript}
  28. })
  29. `)}`
  30. root.after(script)
  31. }
  32. // Load all injected script tags.
  33. root.querySelectorAll('script').forEach(el => {
  34. eval(el.innerHTML)
  35. })
  36. // Load Alpine.
  37. let script = document.createElement('script')
  38. script.src = '/../../packages/alpinejs/dist/cdn.js'
  39. root.after(script)
  40. document.addEventListener('alpine:initialized', () => {
  41. let readyEl = document.createElement('blockquote')
  42. readyEl.setAttribute('alpine-is-ready', true)
  43. readyEl.style.width = '1px'
  44. readyEl.style.height = '1px'
  45. document.querySelector('blockquote').after(readyEl)
  46. })
  47. }
  48. </script>
  49. </html>