Skip to content

Commit

Permalink
add mock test
Browse files Browse the repository at this point in the history
add dist serve option
  • Loading branch information
lkleuver authored and praseodym committed May 17, 2024
1 parent 205e5b6 commit 7005bd8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
30 changes: 30 additions & 0 deletions frontend/app/component/MockTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as React from "react";

export function MockTest() {
const [message, setMessage] = React.useState("...");

React.useEffect(() => {
const action = async () => {
const response = await fetch("/v1/ping", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ ping: "ping" }),
});

const data = (await response.json()) as object;
setMessage(`Response: ${JSON.stringify(data)}`);
};

action().catch((err: unknown) => {
setMessage(`Error: ${err instanceof Error ? err.message : String(err)}`);
});
}, []);
return (
<div>
<h4>Testing mockserver</h4>
{message && <p>{message}</p>}
</div>
);
}
3 changes: 3 additions & 0 deletions frontend/app/module/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MockTest } from "app/component/MockTest";
import { Link } from "react-router-dom";

export function HomePage() {
Expand All @@ -11,6 +12,8 @@ export function HomePage() {
<Link to={`/input`}>Input module</Link>
</li>
</ul>

<MockTest />
</div>
);
}
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<title>TBD</title>
<link rel="icon" href="favicon.svg" />
<link rel="icon" href="/favicon.svg" />
<meta viewport="width=device-width, initial-scale=1" />
</head>
<body>
Expand Down
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"ladle": "ladle serve",
"start:msw": "API_MODE=msw vite",
"gen:icons": "node scripts/gen_icons.js",
"gen:openapi": "vite-node ./scripts/gen_openapi_types.ts"
"gen:openapi": "vite-node ./scripts/gen_openapi_types.ts",
"serve": "npm run build:msw && npx serve dist"
},
"dependencies": {
"react": "^18.2.0",
Expand Down
7 changes: 6 additions & 1 deletion frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ export default defineConfig(() => ({
outDir: path.resolve(__dirname, "dist"),
emptyOutDir: true,
sourcemap: true,
// minify: false, // uncomment for debugging
minify: false,
rollupOptions: {
input: {
app: "index.html",
},
},
},
define: {
"process.env.MSW": apiMode === "mock",
Expand Down

0 comments on commit 7005bd8

Please sign in to comment.