spec.html 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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/history/dist/cdn.js"></script>
  9. <script src="/../../packages/morph/dist/cdn.js"></script>
  10. <script src="/../../packages/persist/dist/cdn.js"></script>
  11. <script src="/../../packages/focus/dist/cdn.js"></script>
  12. <script src="/../../packages/intersect/dist/cdn.js"></script>
  13. <script src="/../../packages/collapse/dist/cdn.js"></script>
  14. <script src="/../../packages/mask/dist/cdn.js"></script>
  15. <script>
  16. let root = document.querySelector('#root')
  17. // We aren't loading Alpine directly because we are expecting
  18. // Cypress to inject HTML into "#root", THEN we'll call
  19. // this function from Cypress to boot everything up.
  20. root.evalScripts = (extraJavaScript) => {
  21. // Load bespoke JavaScript.
  22. if (extraJavaScript) {
  23. let script = document.createElement('script')
  24. script.src = `data:text/javascript;base64,${btoa(`
  25. document.addEventListener('alpine:init', () => {
  26. ${extraJavaScript}
  27. })
  28. `)}`
  29. root.after(script)
  30. }
  31. // Load all injected script tags.
  32. root.querySelectorAll('script').forEach(el => {
  33. eval(el.innerHTML)
  34. })
  35. // Load Alpine.
  36. let script = document.createElement('script')
  37. script.src = '/../../packages/alpinejs/dist/cdn.js'
  38. root.after(script)
  39. document.addEventListener('alpine:initialized', () => {
  40. let readyEl = document.createElement('blockquote')
  41. readyEl.setAttribute('alpine-is-ready', true)
  42. readyEl.style.width = '1px'
  43. readyEl.style.height = '1px'
  44. document.querySelector('blockquote').after(readyEl)
  45. })
  46. }
  47. </script>
  48. </html>