Skip to content

Commit d3b25fa

Browse files
authored
Upgrading to [email protected] (#5)
1 parent c1b52c1 commit d3b25fa

File tree

8 files changed

+166
-36
lines changed

8 files changed

+166
-36
lines changed

deno.jsonc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"imports": {
3-
"fullsoak": "jsr:@fullsoak/[email protected].0-alpha.2",
3+
"fullsoak": "jsr:@fullsoak/[email protected]",
44
"preact": "npm:[email protected]",
55
"preact-iso": "npm:[email protected]",
6-
"@std/testing": "jsr:@std/testing@^1.0.9"
6+
"@std/testing": "jsr:@std/testing@^1.0.9",
7+
"superoak": "https://deno.land/x/[email protected]/mod.ts"
78
},
89
"nodeModulesDir": "auto",
910
"compilerOptions": {

deno.lock

Lines changed: 110 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/MyComponent/index.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { type FunctionComponent } from "preact";
1+
import type { FunctionComponent } from "preact";
2+
import type { RoutableProps } from "preact-iso";
23
import { useEffect, useState } from "preact/hooks";
34
import { MyOtherComponent } from "../MyOtherComponent/index.tsx";
45

56
console.log("MyComponent is being synchronously imported...");
67

7-
type MyProps = {
8+
type MyProps = RoutableProps & {
89
foo: string;
910
};
1011

@@ -24,8 +25,12 @@ export const MyComponent: FunctionComponent<MyProps> = ({ foo }) => {
2425
<li>props 'foo' is {foo}</li>
2526
<li>
2627
state count is {count}{" "}
27-
<button onClick={() => setCount((x) => x + 1)}>+</button>
28-
<button onClick={() => setCount((x) => x - 1)}>-</button>
28+
<button type="button" onClick={() => setCount((x) => x + 1)}>
29+
+
30+
</button>
31+
<button type="button" onClick={() => setCount((x) => x - 1)}>
32+
-
33+
</button>
2934
</li>
3035
<li>
3136
<a href="/app">Route Aware App Component</a>

src/components/MyRouteAwareComponent/routes/Home.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { FunctionComponent } from "preact";
2-
import type { RoutableProps } from "preact/iso";
2+
import type { RoutableProps } from "preact-iso";
33

44
type Props = RoutableProps & { foo: string };
55

src/components/MyRouteAwareComponent/routes/_404.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { FunctionComponent } from "preact";
2-
import type { RoutableProps } from "preact/iso";
2+
import type { RoutableProps } from "preact-iso";
33

44
export const NotFound: FunctionComponent<RoutableProps> = () => (
55
<main>

src/main.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
ssr,
77
useFullSoak,
88
} from "fullsoak";
9-
import { byoHat } from "fullsoak/batteries";
9+
import { makeHat } from "fullsoak/batteries";
1010
import { MyComponent } from "./components/MyComponent/index.tsx";
1111
import { MyRouteAwareComponent } from "./components/MyRouteAwareComponent/index.tsx";
1212

@@ -17,16 +17,19 @@ const GLOBAL_COMPONENTS_DIR: string = Deno.cwd() + "/src/components";
1717
@Controller()
1818
class MyController {
1919
@Get("/")
20-
simpleExample() {
21-
return ssr(MyComponent, { foo: "bar" });
20+
simpleExample(ctx: Context) {
21+
return ssr(MyComponent, {
22+
path: ctx.request.url.pathname,
23+
foo: "bar",
24+
});
2225
}
2326

2427
@Get("/app/:page*")
2528
renderMyRouteAwareComponent(ctx: Context) {
2629
return ssr(MyRouteAwareComponent, {
27-
foo: "Lorem Ipsum",
2830
path: ctx.request.url.pathname,
29-
}, { headContent: byoHat({ title: "FullSoak App" }) });
31+
foo: "Lorem Ipsum",
32+
}, { headContent: makeHat({ title: "FullSoak App" }) });
3033
}
3134
}
3235

tests/MyComponent.test.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1-
import { ssr } from "fullsoak";
2-
import { MyComponent } from "../src/components/MyComponent/index.tsx";
1+
import { useFullSoak } from "fullsoak/testing";
32
import { assertSnapshot } from "@std/testing/snapshot";
3+
import { superoak } from "superoak";
4+
import { Controller, Get, ssr } from "fullsoak";
5+
import { MyComponent } from "../src/components/MyComponent/index.tsx";
6+
7+
@Controller()
8+
class FooController {
9+
@Get("/")
10+
serve() {
11+
return ssr(MyComponent, { path: "/", foo: "bar" });
12+
}
13+
}
414

515
Deno.test("MyComponent", async (t) => {
6-
const output = await ssr(MyComponent, { foo: "bar" });
7-
await assertSnapshot(t, output);
16+
const app = await useFullSoak({ controllers: [FooController] });
17+
const req = await superoak(app);
18+
const resp = await req.get("/");
19+
assertSnapshot(t, resp.text);
820
});

tests/MyRouteAwareComponent.test.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1-
import { ssr } from "fullsoak";
1+
import { useFullSoak } from "fullsoak/testing";
22
import { assertSnapshot } from "@std/testing/snapshot";
3+
import { superoak } from "superoak";
4+
import { Controller, Get, ssr } from "fullsoak";
5+
import { makeHat } from "fullsoak/batteries";
36
import { MyRouteAwareComponent } from "../src/components/MyRouteAwareComponent/index.tsx";
47

8+
@Controller()
9+
class MyController {
10+
@Get("/:whatever*")
11+
serve() {
12+
return ssr(MyRouteAwareComponent, { path: "/do/some/thing", foo: "bar" }, {
13+
headContent: makeHat({ title: "FullSoak SSR App" }),
14+
});
15+
}
16+
}
17+
518
Deno.test("MyRouteAwareComponent", async (t) => {
6-
const output = await ssr(MyRouteAwareComponent, {
7-
url: "http://localhost/bar",
8-
});
9-
await assertSnapshot(t, output);
19+
const app = await useFullSoak({ controllers: [MyController] });
20+
const req = await superoak(app);
21+
const resp = await req.get("/do/some/thing");
22+
assertSnapshot(t, resp.text);
1023
});

0 commit comments

Comments
 (0)