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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
import assert from "assert";
import { ESBUILD, itBundled, testForFile } from "./expectBundled";
var { describe, test, expect } = testForFile(import.meta.path);
describe("bundler", () => {
itBundled("compile/HelloWorld", {
compile: true,
files: {
"/entry.ts": /* js */ `
console.log("Hello, world!");
`,
},
run: { stdout: "Hello, world!" },
});
itBundled("compile/VariousBunAPIs", {
compile: true,
files: {
"/entry.ts": `
// testing random features of bun
import { Database } from "bun:sqlite";
import { serve } from 'bun';
import { getRandomSeed } from 'bun:jsc';
const db = new Database("test.db");
const query = db.query(\`select "Hello world" as message\`);
if (query.get().message !== "Hello world") throw "fail from sqlite";
const icon = await fetch("https://bun.sh/favicon.ico").then(x=>x.arrayBuffer())
if(icon.byteLength < 100) throw "fail from icon";
if (typeof getRandomSeed() !== 'number') throw "fail from bun:jsc";
const server = serve({
fetch() {
return new Response("Hello world");
},
port: 0,
});
const res = await fetch(\`http://\${server.hostname}:\${server.port}\`);
if (res.status !== 200) throw "fail from server";
if (await res.text() !== "Hello world") throw "fail from server";
server.stop();
console.log("ok");
`,
},
run: { stdout: "ok" },
});
itBundled("compile/ReactSSR", {
install: ["react@next", "react-dom@next"],
files: {
"/entry.tsx": /* tsx */ `
import React from "react";
import { renderToReadableStream } from "react-dom/server";
const headers = {
headers: {
"Content-Type": "text/html",
},
};
const App = () => (
<html>
<body>
<h1>Hello World</h1>
<p>This is an example.</p>
</body>
</html>
);
const port = 42001;
const server = Bun.serve({
port,
async fetch(req) {
return new Response(await renderToReadableStream(<App />), headers);
},
});
const res = await fetch("http://localhost:" + port);
if (res.status !== 200) throw "status error";
console.log(await res.text());
server.stop();
`,
},
run: {
stdout: "<!DOCTYPE html><html><head></head><body><h1>Hello World</h1><p>This is an example.</p></body></html>",
},
compile: true,
});
});
|