Skip to content

Commit 79df8db

Browse files
authored
test: put test cases into fixtures (#191)
* test: put test cases into fixtures * lint: fix * fix: ci * fix: update * fix: lint
1 parent 58f28a5 commit 79df8db

21 files changed

+416
-80
lines changed

e2e/async.spec.ts

-12
This file was deleted.

e2e/counter-dev.spec.ts

-11
This file was deleted.

e2e/counter.spec.ts

-20
This file was deleted.

e2e/fixtures/rsc-basic/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# RSC Basic
2+
3+
Only RSC features, no SSR.

e2e/fixtures/rsc-basic/package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "rsc-basic",
3+
"version": "0.1.0",
4+
"type": "module",
5+
"private": true,
6+
"scripts": {
7+
"dev": "waku dev",
8+
"build": "waku build",
9+
"start": "waku start"
10+
},
11+
"dependencies": {
12+
"@hono/node-server": "^1.2.2",
13+
"hono": "^3.10.0",
14+
"react": "18.3.0-canary-6c7b41da3-20231123",
15+
"react-dom": "18.3.0-canary-6c7b41da3-20231123",
16+
"react-server-dom-webpack": "18.3.0-canary-6c7b41da3-20231123",
17+
"waku": "0.17.1"
18+
},
19+
"devDependencies": {
20+
"@swc/core": "1.3.96",
21+
"@types/react": "^18.2.37",
22+
"@types/react-dom": "^18.2.15",
23+
"@vitejs/plugin-react": "4.1.1",
24+
"typescript": "^5.2.2",
25+
"vite": "4.5.0"
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* no "use server" detective
3+
*/
4+
import { ClientCounter } from './ClientCounter.js';
5+
import { ServerPing } from './ServerPing/index.js';
6+
import { ServerBox } from './Box.js';
7+
8+
const App = ({ name }: { name: string }) => {
9+
return (
10+
<ServerBox>
11+
<p data-testid="app-name">{name}</p>
12+
<ClientCounter />
13+
<ServerPing />
14+
</ServerBox>
15+
);
16+
};
17+
18+
export default App;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { PropsWithChildren, HTMLAttributes } from 'react';
2+
3+
export const ServerBox = ({
4+
children,
5+
...props
6+
}: PropsWithChildren<HTMLAttributes<HTMLDivElement>>) => {
7+
return (
8+
<div
9+
{...props}
10+
style={{ border: '3px red dashed', margin: '1em', padding: '1em' }}
11+
>
12+
{children}
13+
</div>
14+
);
15+
};
16+
17+
// use div props
18+
export const ClientBox = ({
19+
children,
20+
...props
21+
}: PropsWithChildren<HTMLAttributes<HTMLDivElement>>) => {
22+
return (
23+
<div
24+
{...props}
25+
style={{ border: '3px blue dashed', margin: '1em', padding: '1em' }}
26+
>
27+
{children}
28+
</div>
29+
);
30+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use client';
2+
import { useState } from 'react';
3+
import { ClientBox } from './Box.js';
4+
5+
export const ClientCounter = () => {
6+
const [count, setCount] = useState(0);
7+
return (
8+
<ClientBox data-testid="client-counter">
9+
<p data-testid="count">{count}</p>
10+
<button data-testid="increment" onClick={() => setCount((c) => c + 1)}>
11+
Increment
12+
</button>
13+
</ClientBox>
14+
);
15+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use client';
2+
3+
import { useCallback, useState } from 'react';
4+
5+
export type CounterProps = {
6+
ping: () => Promise<string>;
7+
increase: (value: number) => Promise<number>;
8+
};
9+
10+
export function Counter({ increase, ping }: CounterProps) {
11+
const [pong, setPong] = useState<string | null>(null);
12+
const [counter, setCounter] = useState(0);
13+
return (
14+
<div>
15+
<p data-testid="pong">{pong}</p>
16+
<button
17+
data-testid="ping"
18+
onClick={() => {
19+
ping().then((value) => {
20+
setPong(value);
21+
});
22+
}}
23+
>
24+
ping
25+
</button>
26+
<p data-testid="counter">{counter}</p>
27+
<button
28+
data-testid="increase"
29+
onClick={useCallback(() => {
30+
increase(counter)
31+
.then((value) => setCounter(value))
32+
.catch(console.error);
33+
}, [counter, increase])}
34+
>
35+
Increase
36+
</button>
37+
</div>
38+
);
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use server';
2+
3+
export const ping = async () => {
4+
return 'pong';
5+
};
6+
7+
export const increase = async (value: number) => {
8+
return value + 1;
9+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { ServerBox } from '../Box.js';
2+
import { Counter } from './Counter.js';
3+
import { increase, ping } from './actions.js';
4+
5+
export function ServerPing() {
6+
return (
7+
<ServerBox data-testid="server-ping">
8+
<Counter ping={ping} increase={increase} />
9+
</ServerBox>
10+
);
11+
}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { lazy } from 'react';
2+
import { defineEntries } from 'waku/server';
3+
import { Slot } from 'waku/client';
4+
5+
const App = lazy(() => import('./components/App.js'));
6+
7+
export default defineEntries(
8+
// renderEntries
9+
async (input) => {
10+
return {
11+
App: <App name={input || 'Waku'} />,
12+
};
13+
},
14+
// getBuildConfig
15+
async () => {
16+
return {
17+
'/': {
18+
entries: [['']],
19+
},
20+
};
21+
},
22+
// getSsrConfig
23+
async (pathStr) => {
24+
switch (pathStr) {
25+
case '/':
26+
return {
27+
input: '',
28+
unstable_render: () => <Slot id="App" />,
29+
};
30+
default:
31+
return null;
32+
}
33+
},
34+
);

e2e/fixtures/rsc-basic/src/index.html

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Waku example</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<style>
8+
@keyframes spinner {
9+
to {
10+
transform: rotate(360deg);
11+
}
12+
}
13+
.spinner {
14+
width: 36px;
15+
height: 36px;
16+
margin: auto;
17+
border: 2px solid #ddd;
18+
border-top-color: #222;
19+
border-radius: 50%;
20+
animation: spinner 1s linear infinite;
21+
}
22+
#root > .spinner {
23+
margin-top: calc(50% - 18px);
24+
}
25+
</style>
26+
</head>
27+
<body>
28+
<!--placeholder1-->
29+
<div id="root">
30+
<div class="spinner"></div>
31+
</div>
32+
<!--/placeholder1-->
33+
<script src="/main.tsx" async type="module"></script>
34+
<!--placeholder2-->
35+
<!--/placeholder2-->
36+
</body>
37+
</html>

e2e/fixtures/rsc-basic/src/main.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { StrictMode } from 'react';
2+
import { createRoot } from 'react-dom/client';
3+
import { Root, Slot } from 'waku/client';
4+
5+
const rootElement = (
6+
<StrictMode>
7+
<Root>
8+
<Slot id="App" />
9+
</Root>
10+
</StrictMode>
11+
);
12+
13+
createRoot(document.getElementById('root')!).render(rootElement);

e2e/fixtures/rsc-basic/tsconfig.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"composite": true,
4+
"strict": true,
5+
"target": "esnext",
6+
"downlevelIteration": true,
7+
"esModuleInterop": true,
8+
"module": "nodenext",
9+
"skipLibCheck": true,
10+
"noUncheckedIndexedAccess": true,
11+
"exactOptionalPropertyTypes": true,
12+
"jsx": "react-jsx",
13+
"rootDir": "./src",
14+
"outDir": "./dist"
15+
}
16+
}

0 commit comments

Comments
 (0)