Skip to content

Commit 2b682ab

Browse files
committed
add more tests
1 parent f791267 commit 2b682ab

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { createEffect, createSignal } from "solid-js";
2+
3+
async function ping(value: Date) {
4+
"use server";
5+
6+
const current = [
7+
value,
8+
{
9+
name: 'example',
10+
*[Symbol.iterator]() {
11+
yield 'foo';
12+
yield 'bar';
13+
yield 'baz';
14+
}
15+
}
16+
];
17+
18+
return current;
19+
}
20+
21+
export default function App() {
22+
const [output, setOutput] = createSignal<{ result?: boolean }>({});
23+
24+
createEffect(async () => {
25+
const value = new Date();
26+
const result = await ping(value);
27+
setOutput((prev) => ({ ...prev, result: value.toString() === result[0].toString() }));
28+
});
29+
30+
return (
31+
<main>
32+
<span id="server-fn-test">{JSON.stringify(output())}</span>
33+
</main>
34+
);
35+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { createEffect, createSignal } from "solid-js";
2+
3+
async function sleep(value: unknown, ms: number) {
4+
return new Promise((res) => {
5+
setTimeout(res, ms, value);
6+
})
7+
}
8+
9+
async function ping(value: URLSearchParams, clone: URLSearchParams) {
10+
"use server";
11+
12+
const current = [
13+
value.toString() === clone.toString(),
14+
value,
15+
clone,
16+
] as const;
17+
18+
return current;
19+
}
20+
21+
export default function App() {
22+
const [output, setOutput] = createSignal<{ result?: boolean }>({});
23+
24+
createEffect(async () => {
25+
const value = new URLSearchParams([
26+
['foo', 'bar'],
27+
['hello', 'world'],
28+
]);
29+
const result = await ping(value, value);
30+
setOutput((prev) => ({ ...prev, result: result[0] }));
31+
});
32+
33+
return (
34+
<main>
35+
<span id="server-fn-test">{JSON.stringify(output())}</span>
36+
</main>
37+
);
38+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { createEffect, createSignal } from "solid-js";
2+
3+
async function sleep<T>(value: T, ms: number) {
4+
return new Promise<T>((res) => {
5+
setTimeout(res, ms, value);
6+
})
7+
}
8+
9+
async function ping(value: ReadableStream<string>) {
10+
"use server";
11+
return value;
12+
}
13+
14+
export default function App() {
15+
const [output, setOutput] = createSignal<{ result?: boolean }>({});
16+
17+
createEffect(async () => {
18+
const result = await ping(
19+
new ReadableStream({
20+
async start(controller) {
21+
controller.enqueue(await sleep('foo', 100));
22+
controller.enqueue(await sleep('bar', 100));
23+
controller.enqueue(await sleep('baz', 100));
24+
controller.close();
25+
},
26+
})
27+
);
28+
29+
const reader = result.getReader();
30+
const first = await reader.read();
31+
setOutput((prev) => ({ ...prev, result: first.value === 'foo' }));
32+
});
33+
34+
return (
35+
<main>
36+
<span id="server-fn-test">{JSON.stringify(output())}</span>
37+
</main>
38+
);
39+
}

0 commit comments

Comments
 (0)