Skip to content

Commit 36fd2cb

Browse files
committed
Add test for GET /_pera/app.js
1 parent a1e6f63 commit 36fd2cb

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

tests/sample-app.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const App = () => {
2+
return <div>Hello, World!</div>;
3+
};

tests/serve_test.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
import { assertEquals, assertMatch } from "@std/assert";
22
import { delay } from "@std/async";
33
import { serve } from "../src/mod.ts";
4-
5-
const App = () => {
6-
return <div>Hello, World!</div>;
7-
};
4+
import { App } from "./sample-app.tsx";
85

96
const port: number = 9090;
107
let finished: Promise<void>;
118
let controller: AbortController;
129

1310
Deno.test.beforeEach(async () => {
11+
const sampleAppFile = new URL("sample-app.tsx", import.meta.url);
1412
controller = new AbortController();
1513
finished = serve(App, {
1614
port,
1715
title: "Test Server",
18-
moduleUrl: import.meta.url,
19-
props: { initial: 7 },
16+
moduleUrl: sampleAppFile.href,
2017
api: (app) => {
2118
app.get(
2219
"/users/:name",
@@ -73,5 +70,11 @@ Deno.test("serve() responds to GET /_pera/hmr", async () => {
7370
});
7471

7572
Deno.test("serve() responds to GET /_pera/app.js", async () => {
76-
// TODO(d2verb): Implement this test
73+
const resAppJs = await fetch(`http://localhost:${port}/_pera/app.js`);
74+
assertEquals(resAppJs.status, 200);
75+
assertEquals(
76+
resAppJs.headers.get("content-type"),
77+
"application/javascript; charset=utf-8",
78+
);
79+
await resAppJs.text();
7780
});

0 commit comments

Comments
 (0)