import { test, describe, expect } from 'vitest'; import { h } from 'preact'; import { useState } from 'preact/hooks'; import { buildIslandHtml } from '@hyperspan/vite-plugin/islands'; import { renderPreactSSR, renderPreactIsland } from './index'; // --------------------------------------------------------------------------- // Simple Preact components defined inline — no .tsx compilation needed // --------------------------------------------------------------------------- function Hello({ name = 'World', count = 0 }: { name?: string; count?: number }) { return h('div', { class: 'hello' }, [ h('h1', null, `Hello ${name}!`), h('p', null, `Count: ${count}`), ]); } // --------------------------------------------------------------------------- // buildIslandHtml // --------------------------------------------------------------------------- describe('buildIslandHtml', () => { const jsId = 'abc123'; const componentName = 'Hello'; const esmName = 'hello-component'; test('wraps SSR content in a div with the island id', () => { const result = buildIslandHtml(jsId, componentName, esmName, '', '
SSR
'); expect(result).toContain(`SSR
'); }); test('includes a module script tag with the correct source id', () => { const result = buildIslandHtml(jsId, componentName, esmName, 'console.log(1)', ''); expect(result).toContain(`' }); expect(output).not.toContain('