spec-csp.html 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <html>
  2. <meta http-equiv="Content-Security-Policy" content="script-src 'nonce-iifbjI67iq4HZJUQ54eC' 'self' data:; default-src 'self';">
  3. <!-- Using a <blockquote> because it's an obscure tag -->
  4. <!-- which allows us to use document.querySelector() -->
  5. <!-- with generic tags freely inside Cypress tests. -->
  6. <blockquote id="root">
  7. <!-- This is where our test subjects will be injected. -->
  8. </blockquote>
  9. <script nonce="iifbjI67iq4HZJUQ54eC">
  10. let root = document.querySelector('#root')
  11. // We aren't loading Alpine directly because we are expecting
  12. // Cypress to inject HTML into "#root", THEN we'll call
  13. // this function from Cypress to boot everything up.
  14. root.evalScripts = (extraJavaScript) => {
  15. // Load bespoke JavaScript.
  16. if (extraJavaScript) {
  17. let script = document.createElement('script')
  18. script.src = `data:text/javascript;base64,${btoa(`
  19. document.addEventListener('alpine:init', () => {
  20. ${extraJavaScript}
  21. })
  22. `)}`
  23. root.after(script)
  24. }
  25. document.addEventListener('alpine:initialized', () => {
  26. let readyEl = document.createElement('blockquote')
  27. readyEl.setAttribute('alpine-is-ready', true)
  28. readyEl.style.width = '1px'
  29. readyEl.style.height = '1px'
  30. document.querySelector('blockquote').after(readyEl)
  31. })
  32. // Load Alpine.
  33. let script = document.createElement('script')
  34. script.src = '/../../packages/csp/dist/cdn.js'
  35. root.after(script)
  36. }
  37. </script>
  38. </html>