deno.land / x / esm@v135_2 / test / solid-js / solid.test.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { assertEquals } from "https://deno.land/std@0.180.0/testing/asserts.ts";
import { transform } from "http://localhost:8080/@babel/standalone@7.21.4";import babelPresetSolid from "http://localhost:8080/babel-preset-solid@1.6.16";import { renderToString } from "http://localhost:8080/solid-js@1.6.16/web";
function transformSolid(rawCode: string): string { const { code } = transform(rawCode, { presets: [ [babelPresetSolid, { generate: "ssr", hydratable: false, }], ["typescript", { onlyRemoveTypeImports: true, isTSX: true, allExtensions: true, }], ], filename: "main.jsx", }); if (!code) { throw new Error("code is empty"); } return code .replaceAll(`"solid-js"`, `"http://localhost:8080/solid-js@1.6.16"`) .replaceAll( `"solid-js/web"`, `"http://localhost:8080/solid-js@1.6.16/web"`, );}
Deno.test("solid.js ssr", async () => { const code = `import { createSignal } from "solid-js";
function Counter() { const [count, setCount] = createSignal(0); const increment = () => setCount(count() + 1);
return ( <button type="button" onClick={increment}> {count()} </button> ); }
export default function App() { return <Counter />; } `; const { default: App } = await import( `data:application/javascript,${encodeURIComponent(transformSolid(code))}` ); const html = renderToString(App); assertEquals(html, `<button type="button">0</button>`);});
esm

Version Info

Tagged at
a year ago