Skip to content

Commit aa14bd1

Browse files
authored
Merge pull request #21 from nyaomaru/study-deno-15
Add test workflow and fix lint errors
2 parents aa37968 + a42e85b commit aa14bd1

File tree

14 files changed

+54
-33
lines changed

14 files changed

+54
-33
lines changed

.github/workflows/test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Test
2+
on: [push]
3+
jobs:
4+
test:
5+
name: test
6+
runs-on: ubuntu-latest
7+
8+
steps:
9+
- name: Clone repository
10+
uses: actions/checkout@v4
11+
12+
- name: Install Deno
13+
uses: denoland/setup-deno@v1
14+
with:
15+
deno-version: v1.x
16+
17+
- name: Test step
18+
run: "deno task build"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ Then you can access to http://localhost:8000/
1717
If you try the deno test, you could run below command.
1818

1919
```sh
20-
deno test --allow-read --allow-env --allow-net
20+
deno task test
2121
```

deno.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"start": "deno run -A --watch=src/static/,src/routes/ --unstable src/dev.ts",
88
"build": "deno run -A --unstable src/dev.ts build",
99
"preview": "deno run -A --unstable src/main.ts",
10-
"update": "deno run -A -r https://fresh.deno.dev/update ."
10+
"update": "deno run -A -r https://fresh.deno.dev/update .",
11+
"test": "deno test --allow-read --allow-env --allow-net --unstable"
1112
},
1213
"lint": { "rules": { "tags": ["fresh", "recommended"] } },
1314
"exclude": ["**/_fresh/*"],

src/fresh.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// This file SHOULD be checked into source version control.
33
// This file is automatically updated during development when running `dev.ts`.
44

5-
import * as $_slug_ from "./routes/[slug].tsx";
65
import * as $_404 from "./routes/_404.tsx";
76
import * as $_500 from "./routes/_500.tsx";
87
import * as $_app from "./routes/_app.tsx";
@@ -20,6 +19,7 @@ import * as $greet_name_ from "./routes/greet/[name].tsx";
2019
import * as $greet_middleware from "./routes/greet/_middleware.ts";
2120
import * as $index from "./routes/index.tsx";
2221
import * as $map from "./routes/map.tsx";
22+
import * as $markdowns_slug_ from "./routes/markdowns/[slug].tsx";
2323
import * as $partials_about_id_ from "./routes/partials/about/[id].tsx";
2424
import * as $projects_id_ from "./routes/projects/[id].tsx";
2525
import * as $reportHandler from "./routes/reportHandler.ts";
@@ -34,7 +34,6 @@ import { type Manifest } from "$fresh/server.ts";
3434

3535
const manifest = {
3636
routes: {
37-
"./routes/[slug].tsx": $_slug_,
3837
"./routes/_404.tsx": $_404,
3938
"./routes/_500.tsx": $_500,
4039
"./routes/_app.tsx": $_app,
@@ -52,6 +51,7 @@ const manifest = {
5251
"./routes/greet/_middleware.ts": $greet_middleware,
5352
"./routes/index.tsx": $index,
5453
"./routes/map.tsx": $map,
54+
"./routes/markdowns/[slug].tsx": $markdowns_slug_,
5555
"./routes/partials/about/[id].tsx": $partials_about_id_,
5656
"./routes/projects/[id].tsx": $projects_id_,
5757
"./routes/reportHandler.ts": $reportHandler,

src/islands/Countdown.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ import { useEffect } from "preact/hooks";
44
const timeFmt = new Intl.RelativeTimeFormat("en-US");
55

66
export default function Countdown(props: { target: string }) {
7-
const target = new Date(props.target);
8-
const now = useSignal(new Date());
7+
const target = new Date(props.target);
8+
const now = useSignal(new Date());
99

10-
useEffect(() => {
11-
const timer = setInterval(() => {
12-
if (now.value > target) {
13-
clearInterval(timer);
14-
}
15-
now.value = new Date();
16-
}, 1000);
17-
return () => clearInterval(timer);
18-
}, [props.target]);
10+
useEffect(() => {
11+
const timer = setInterval(() => {
12+
if (now.value > target) {
13+
clearInterval(timer);
14+
}
15+
now.value = new Date();
16+
}, 1000);
17+
return () => clearInterval(timer);
18+
}, [props.target]);
1919

20-
const secondsLeft = Math.floor(
21-
(target.getTime() - now.value.getTime()) / 1000,
22-
);
20+
const secondsLeft = Math.floor(
21+
(target.getTime() - now.value.getTime()) / 1000,
22+
);
2323

24-
if (secondsLeft <= 0) {
25-
return <span>🎉</span>;
26-
}
24+
if (secondsLeft <= 0) {
25+
return <span>🎉</span>;
26+
}
2727

28-
return <span>{timeFmt.format(secondsLeft, "seconds")}</span>;
28+
return <span>{timeFmt.format(secondsLeft, "seconds")}</span>;
2929
}

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import "$std/dotenv/load.ts";
99

1010
import { start } from "$fresh/server.ts";
11-
import manifest from "./fresh.gen.ts";
12-
import config from "./fresh.config.ts";
11+
import manifest from "#src/fresh.gen.ts";
12+
import config from "#src/fresh.config.ts";
1313

1414
await start(manifest, config);

src/routes/_layout.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { PageProps } from "$fresh/server.ts";
22

3-
export default function Layout({ Component, state }: PageProps) {
4-
// do something with state here
3+
export default function Layout({ Component }: PageProps) {
54
return (
65
<div class="px-4 py-8 mx-auto bg-cyan-300 h-screen">
76
<Component />

src/routes/about.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Partial } from "$fresh/runtime.ts";
33
import NextContentButton from "#src/islands/NextContentButton.tsx";
44
import { Link } from "#src/components/Link.tsx";
55

6-
const loadFooValue = async () => {
6+
const loadFooValue = () => {
77
return "nyaomaru";
88
};
99

src/routes/countdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineRoute } from "$fresh/server.ts";
22
import Countdown from "#src/islands/Countdown.tsx";
33
import { Link } from "#src/components/Link.tsx";
44

5-
export default defineRoute(async (_req, _ctx) => {
5+
export default defineRoute((_req, _ctx) => {
66
const date = new Date();
77
date.setHours(date.getHours() + 1);
88
return (

src/routes/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default function Home({ data }: PageProps<string>) {
7070
href={`projects/${Math.round(Math.random()) + 1}`}
7171
/>
7272
<Link text="Chart" href="chart" />
73-
<Link text="Markdown" href="string" />
73+
<Link text="Markdown" href="markdowns/string" />
7474
<Link text="CSP" href="correctCSPwithReport" />
7575
</div>
7676
<div class="my-4 flex gap-4">

src/routes/map.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineRoute } from "$fresh/server.ts";
22
import { Link } from "#src/components/Link.tsx";
33
import { MapIsland } from "#src/islands/MapIsland.tsx";
44

5-
export default defineRoute(async (_req, _ctx) => {
5+
export default defineRoute((_req, _ctx) => {
66
return (
77
<>
88
<div>
File renamed without changes.

src/routes/partials/about/[id].tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const contents = [
66
"bla bla bla",
77
];
88

9-
const loadContent = async (id: string) => {
9+
const loadContent = (id: string) => {
1010
const currentContent = contents[Number(id) % 2];
1111

1212
return (
@@ -24,8 +24,8 @@ export const config: RouteConfig = {
2424
skipInheritedLayouts: true,
2525
};
2626

27-
export default defineRoute(async (req, ctx) => {
28-
const content = await loadContent(ctx.params.id);
27+
export default defineRoute((_req, ctx) => {
28+
const content = loadContent(ctx.params.id);
2929

3030
return (
3131
<Partial name="about-content">

src/services/database.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
// The purpose of this below line is to pass the test with unstable api..
2+
/// <reference lib="deno.unstable" />
3+
14
export const kv = await Deno.openKv();

0 commit comments

Comments
 (0)