Skip to content

Commit

Permalink
fix: test and lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
nyaomaru committed Sep 1, 2024
1 parent aa37968 commit 2aca777
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 33 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test
on: [push]
jobs:
test:
name: test
runs-on: ubuntu-latest

steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Install Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: Test step
run: "deno task build"

- name: Upload to Deno Deploy
uses: denoland/deployctl@v1
with:
project: "nyaomaru-deno-sample"
entrypoint: "src/main.ts"
root: "."
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ Then you can access to http://localhost:8000/
If you try the deno test, you could run below command.

```sh
deno test --allow-read --allow-env --allow-net
deno task test
```
3 changes: 2 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"start": "deno run -A --watch=src/static/,src/routes/ --unstable src/dev.ts",
"build": "deno run -A --unstable src/dev.ts build",
"preview": "deno run -A --unstable src/main.ts",
"update": "deno run -A -r https://fresh.deno.dev/update ."
"update": "deno run -A -r https://fresh.deno.dev/update .",
"test": "deno test --allow-read --allow-env --allow-net --unstable"
},
"lint": { "rules": { "tags": ["fresh", "recommended"] } },
"exclude": ["**/_fresh/*"],
Expand Down
4 changes: 2 additions & 2 deletions src/fresh.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This file SHOULD be checked into source version control.
// This file is automatically updated during development when running `dev.ts`.

import * as $_slug_ from "./routes/[slug].tsx";
import * as $_404 from "./routes/_404.tsx";
import * as $_500 from "./routes/_500.tsx";
import * as $_app from "./routes/_app.tsx";
Expand All @@ -20,6 +19,7 @@ import * as $greet_name_ from "./routes/greet/[name].tsx";
import * as $greet_middleware from "./routes/greet/_middleware.ts";
import * as $index from "./routes/index.tsx";
import * as $map from "./routes/map.tsx";
import * as $markdowns_slug_ from "./routes/markdowns/[slug].tsx";
import * as $partials_about_id_ from "./routes/partials/about/[id].tsx";
import * as $projects_id_ from "./routes/projects/[id].tsx";
import * as $reportHandler from "./routes/reportHandler.ts";
Expand All @@ -34,7 +34,6 @@ import { type Manifest } from "$fresh/server.ts";

const manifest = {
routes: {
"./routes/[slug].tsx": $_slug_,
"./routes/_404.tsx": $_404,
"./routes/_500.tsx": $_500,
"./routes/_app.tsx": $_app,
Expand All @@ -52,6 +51,7 @@ const manifest = {
"./routes/greet/_middleware.ts": $greet_middleware,
"./routes/index.tsx": $index,
"./routes/map.tsx": $map,
"./routes/markdowns/[slug].tsx": $markdowns_slug_,
"./routes/partials/about/[id].tsx": $partials_about_id_,
"./routes/projects/[id].tsx": $projects_id_,
"./routes/reportHandler.ts": $reportHandler,
Expand Down
36 changes: 18 additions & 18 deletions src/islands/Countdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import { useEffect } from "preact/hooks";
const timeFmt = new Intl.RelativeTimeFormat("en-US");

export default function Countdown(props: { target: string }) {
const target = new Date(props.target);
const now = useSignal(new Date());
const target = new Date(props.target);
const now = useSignal(new Date());

useEffect(() => {
const timer = setInterval(() => {
if (now.value > target) {
clearInterval(timer);
}
now.value = new Date();
}, 1000);
return () => clearInterval(timer);
}, [props.target]);
useEffect(() => {
const timer = setInterval(() => {
if (now.value > target) {
clearInterval(timer);
}
now.value = new Date();
}, 1000);
return () => clearInterval(timer);
}, [props.target]);

const secondsLeft = Math.floor(
(target.getTime() - now.value.getTime()) / 1000,
);
const secondsLeft = Math.floor(
(target.getTime() - now.value.getTime()) / 1000,
);

if (secondsLeft <= 0) {
return <span>🎉</span>;
}
if (secondsLeft <= 0) {
return <span>🎉</span>;
}

return <span>{timeFmt.format(secondsLeft, "seconds")}</span>;
return <span>{timeFmt.format(secondsLeft, "seconds")}</span>;
}
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import "$std/dotenv/load.ts";

import { start } from "$fresh/server.ts";
import manifest from "./fresh.gen.ts";
import config from "./fresh.config.ts";
import manifest from "#src/fresh.gen.ts";
import config from "#src/fresh.config.ts";

await start(manifest, config);
3 changes: 1 addition & 2 deletions src/routes/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { PageProps } from "$fresh/server.ts";

export default function Layout({ Component, state }: PageProps) {
// do something with state here
export default function Layout({ Component }: PageProps) {
return (
<div class="px-4 py-8 mx-auto bg-cyan-300 h-screen">
<Component />
Expand Down
2 changes: 1 addition & 1 deletion src/routes/about.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Partial } from "$fresh/runtime.ts";
import NextContentButton from "#src/islands/NextContentButton.tsx";
import { Link } from "#src/components/Link.tsx";

const loadFooValue = async () => {
const loadFooValue = () => {
return "nyaomaru";
};

Expand Down
2 changes: 1 addition & 1 deletion src/routes/countdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineRoute } from "$fresh/server.ts";
import Countdown from "#src/islands/Countdown.tsx";
import { Link } from "#src/components/Link.tsx";

export default defineRoute(async (_req, _ctx) => {
export default defineRoute((_req, _ctx) => {
const date = new Date();
date.setHours(date.getHours() + 1);
return (
Expand Down
2 changes: 1 addition & 1 deletion src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function Home({ data }: PageProps<string>) {
href={`projects/${Math.round(Math.random()) + 1}`}
/>
<Link text="Chart" href="chart" />
<Link text="Markdown" href="string" />
<Link text="Markdown" href="markdowns/string" />
<Link text="CSP" href="correctCSPwithReport" />
</div>
<div class="my-4 flex gap-4">
Expand Down
2 changes: 1 addition & 1 deletion src/routes/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineRoute } from "$fresh/server.ts";
import { Link } from "#src/components/Link.tsx";
import { MapIsland } from "#src/islands/MapIsland.tsx";

export default defineRoute(async (_req, _ctx) => {
export default defineRoute((_req, _ctx) => {
return (
<>
<div>
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/routes/partials/about/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const contents = [
"bla bla bla",
];

const loadContent = async (id: string) => {
const loadContent = (id: string) => {
const currentContent = contents[Number(id) % 2];

return (
Expand All @@ -24,8 +24,8 @@ export const config: RouteConfig = {
skipInheritedLayouts: true,
};

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

return (
<Partial name="about-content">
Expand Down
3 changes: 3 additions & 0 deletions src/services/database.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
// The purpose of this below line is to pass the test with unstable api..
/// <reference lib="deno.unstable" />

export const kv = await Deno.openKv();

0 comments on commit 2aca777

Please sign in to comment.