|
| 1 | +import { describe, it, expect, vi } from 'vitest'; |
| 2 | +import { ssrCreateContainer } from './ssr-container'; |
| 3 | +import { QStyle } from './qwik-copy'; |
| 4 | + |
| 5 | +vi.hoisted(() => { |
| 6 | + vi.stubGlobal('QWIK_LOADER_DEFAULT_MINIFIED', 'min'); |
| 7 | + vi.stubGlobal('QWIK_LOADER_DEFAULT_DEBUG', 'debug'); |
| 8 | +}); |
| 9 | + |
| 10 | +describe('SSR Container', () => { |
| 11 | + it('should not emit Qwik loader before style elements', async () => { |
| 12 | + const writer = { |
| 13 | + chunks: [] as string[], |
| 14 | + write(text: string) { |
| 15 | + this.chunks.push(text); |
| 16 | + }, |
| 17 | + toString() { |
| 18 | + return this.chunks.join(''); |
| 19 | + }, |
| 20 | + }; |
| 21 | + |
| 22 | + const container = ssrCreateContainer({ |
| 23 | + tagName: 'div', |
| 24 | + writer, |
| 25 | + renderOptions: { |
| 26 | + qwikLoader: 'inline', // Force inline loader |
| 27 | + }, |
| 28 | + }); |
| 29 | + |
| 30 | + // Open container |
| 31 | + container.openContainer(); |
| 32 | + // Add a large content to exceed 30KB while opening the next element |
| 33 | + const largeContent = 'x'.repeat(30 * 1024); |
| 34 | + container.openElement('div', null); |
| 35 | + container.textNode(largeContent); |
| 36 | + await container.closeElement(); |
| 37 | + // Add a style element with QStyle attribute |
| 38 | + container.openElement('style', [QStyle, 'my-style-id']); |
| 39 | + container.write('.my-class { color: red; }'); |
| 40 | + await container.closeElement(); |
| 41 | + // Add another regular elementm |
| 42 | + container.openElement('div', null); |
| 43 | + await container.closeElement(); |
| 44 | + await container.closeContainer(); |
| 45 | + |
| 46 | + const html = writer.toString(); |
| 47 | + expect(html.indexOf('id="qwikloader"')).toBeGreaterThan(html.indexOf('my-style-id')); |
| 48 | + }); |
| 49 | +}); |
0 commit comments