Skip to content

Commit d167674

Browse files
hi-ogawaclaude
andcommitted
Add missing server action test case and client transform documentation
- Add missing 'inline use server (const function expression)' test case to match Waku coverage - Add skipped client transform tests for reference documentation - Now covers 9 server action test cases + 3 client reference examples - All active tests pass (12 total, 3 skipped) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent caf51d1 commit d167674

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

packages/plugin-rsc/src/transforms/server-action.test.ts

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,34 @@ export default function App() {
114114
`)
115115
})
116116

117+
test('inline use server (const function expression)', async () => {
118+
const input = `
119+
export default function App() {
120+
const rand = Math.random();
121+
const log = async function (mesg) {
122+
'use server';
123+
console.log(mesg, rand);
124+
};
125+
return log;
126+
}
127+
`
128+
expect(await testTransform(input)).toMatchInlineSnapshot(`
129+
"
130+
export default function App() {
131+
const rand = Math.random();
132+
const log = /* #__PURE__ */ __registerServerReference($$hoist_0_log, "<id>", "$$hoist_0_log").bind(null, rand);
133+
return log;
134+
}
135+
136+
;export async function $$hoist_0_log(rand, mesg) {
137+
'use server';
138+
console.log(mesg, rand);
139+
};
140+
/* #__PURE__ */ Object.defineProperty($$hoist_0_log, "name", { value: "log" });
141+
"
142+
`)
143+
})
144+
117145
test('inline use server (const arrow function)', async () => {
118146
const input = `
119147
const now = Date.now();
@@ -332,3 +360,111 @@ export default async () => null;
332360
`)
333361
})
334362
})
363+
364+
// Client transform tests for documentation (from Waku)
365+
// These show expected client-side behavior but are skipped since
366+
// transformServerActionServer only handles server transforms
367+
describe('client transform examples (for reference)', () => {
368+
test.skip('top-level use client', () => {
369+
// Input:
370+
const input = `
371+
'use client';
372+
373+
import { Component, createContext, useContext, memo } from 'react';
374+
import { atom } from 'jotai/vanilla';
375+
import { unstable_allowServer as allowServer } from 'waku/client';
376+
377+
const initialCount = 1;
378+
const TWO = 2;
379+
function double (x: number) {
380+
return x * TWO;
381+
}
382+
export const countAtom = allowServer(atom(double(initialCount)));
383+
384+
export const Empty = () => null;
385+
386+
function Private() {
387+
return "Secret";
388+
}
389+
const SecretComponent = () => <p>Secret</p>;
390+
const SecretFunction = (n: number) => 'Secret' + n;
391+
392+
export function Greet({ name }: { name: string }) {
393+
return <>Hello {name}</>;
394+
}
395+
396+
export class MyComponent extends Component {
397+
render() {
398+
return <p>Class Component</p>;
399+
}
400+
}
401+
402+
const MyContext = createContext();
403+
404+
export const useMyContext = () => useContext(MyContext);
405+
406+
const MyProvider = memo(MyContext);
407+
408+
export const NAME = 'World';
409+
410+
export default function App() {
411+
return (
412+
<MyProvider value="Hello">
413+
<div>Hello World</div>
414+
</MyProvider>
415+
);
416+
}
417+
`
418+
419+
// Expected Output (from Waku client transform):
420+
// registerClientReference calls for all exports
421+
// Error-throwing stubs for server environment
422+
})
423+
424+
test.skip('top-level use server for client', () => {
425+
// Input:
426+
const input = `
427+
'use server';
428+
429+
const privateFunction = () => 'Secret';
430+
431+
export const log1 = async function(mesg) {
432+
console.log(mesg);
433+
}
434+
435+
export const log2 = async (mesg) => {
436+
console.log(mesg);
437+
};
438+
439+
export async function log3(mesg) {
440+
console.log(mesg);
441+
}
442+
443+
export default async function log4(mesg) {
444+
console.log(mesg);
445+
}
446+
`
447+
448+
// Expected Output (from Waku client transform):
449+
// createServerReference calls for each export
450+
// Client-side proxy functions
451+
})
452+
453+
test.skip('top-level use server for SSR', () => {
454+
// Input:
455+
const input = `
456+
'use server';
457+
458+
import { getEnv } from 'waku';
459+
460+
const privateFunction = () => getEnv('SECRET');
461+
462+
export async function log(mesg) {
463+
console.log(mesg);
464+
}
465+
`
466+
467+
// Expected Output (from Waku SSR transform):
468+
// Error-throwing stubs: "You cannot call server functions during SSR"
469+
})
470+
})

0 commit comments

Comments
 (0)