Skip to content

Commit 92c8176

Browse files
committed
feat(kit): add e2e tests
1 parent f1beb85 commit 92c8176

8 files changed

Lines changed: 25 additions & 7 deletions

File tree

packages/kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@wavekit/kit",
33
"type": "module",
4-
"version": "0.0.3",
4+
"version": "0.0.4",
55
"module": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"exports": {

packages/kit/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export type {
77
SsgRenderProps,
88
CreateWaveKitProps,
99
WaveKitHandler,
10+
WaveKitContext,
1011
} from "./server";

packages/kit/src/server.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { buildRoutes, createWaveKit } from "./server";
55
const TEST_DIR = path.join(__dirname, "..", "test", "app");
66

77
const FAKE_ROUTES = {
8-
"/": path.join(TEST_DIR, "index.test.ts"),
8+
"/html.test": path.join(TEST_DIR, "html.test.ts"),
99
};
1010

1111
it("should prepare routes", async () => {
1212
const routes = await buildRoutes({ routes: FAKE_ROUTES });
13-
expect(routes["/"]).toHaveProperty("GET");
13+
expect(routes["/html.test"]).toHaveProperty("GET");
1414
});
1515

1616
it("should create wavekit config", async () => {
1717
const routes = await createWaveKit({ routesDir: TEST_DIR });
18-
expect(routes["/index.test"]).toHaveProperty("GET");
18+
expect(routes["/html.test"]).toHaveProperty("GET");
1919
});

packages/kit/src/server.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ const defaultRoutesDir = isDev
1010

1111
const defaultOutDir = path.join(process.cwd(), "build");
1212

13-
type WaveKitContext = {
13+
export type WaveKitContext = {
1414
req: BunRequest;
1515
res: WaveKitResponse;
1616
html: typeof WaveKitResponse.html;
1717
json: typeof WaveKitResponse.json;
18+
redirect: typeof WaveKitResponse.redirect;
19+
store: Map<string, unknown>;
1820
};
1921

2022
export type WaveKitHandler = (
@@ -53,8 +55,7 @@ export async function buildRoutes({
5355
html: WaveKitResponse.html,
5456
json: WaveKitResponse.json,
5557
redirect: WaveKitResponse.redirect,
56-
set: contextStore.set,
57-
get: contextStore.get,
58+
store: contextStore,
5859
};
5960
return methodHandler(context);
6061
};

packages/kit/test/app/json.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { WaveKitHandler } from "@wavekit/kit";
2+
3+
export const GET: WaveKitHandler = (c) => {
4+
return c.json({ hello: "world" });
5+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { WaveKitHandler } from "@wavekit/kit";
2+
3+
export const GET: WaveKitHandler = (c) => {
4+
return c.redirect("/html.test");
5+
};

packages/kit/test/app/set.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { WaveKitHandler } from "@wavekit/kit";
2+
3+
export const GET: WaveKitHandler = async (c) => {
4+
c.store.set("hello", "world");
5+
return c.json({ hello: c.store.get("hello") });
6+
};

0 commit comments

Comments
 (0)