1
0

apply-injections.spec.ts 844 B

1234567891011121314151617181920212223
  1. // @vitest-environment jsdom
  2. import { afterEach, expect, it, vi } from 'vitest'
  3. import { applyIndexInjections } from '../../src/client/apply-injections.ts'
  4. afterEach(() => {
  5. document.head.innerHTML = ''
  6. document.body.innerHTML = ''
  7. })
  8. it('ignores script preload hints and executes script sources through the worker loader', async () => {
  9. const loadScript = vi.fn(async () => {})
  10. const preload = '/plugins/??app-a/client.js,app-b/client.js&rev=app'
  11. const bootstrap = '/plugins/??modules/client.js&rev=boot'
  12. await applyIndexInjections([
  13. { kind: 'script-preload', src: preload },
  14. { kind: 'script-src', placement: 'head', src: bootstrap },
  15. ], loadScript)
  16. expect(loadScript).toHaveBeenCalledOnce()
  17. expect(loadScript).toHaveBeenCalledWith(bootstrap)
  18. expect(document.querySelector('link[rel="preload"]')).toBeNull()
  19. })