@@ -3,7 +3,7 @@ import { describe, expect, test } from 'vitest'
33import { transformServerActionServer } from './server-action'
44import { debugSourceMap } from './test-utils'
55
6- describe ( 'transformServerActionServer ' , ( ) => {
6+ describe ( 'internal transform function for server environment ' , ( ) => {
77 async function testTransform ( input : string ) {
88 const ast = await parseAstAsync ( input )
99 const result = transformServerActionServer ( input , ast , {
@@ -31,6 +31,61 @@ export default function App() {
3131 expect ( await testTransform ( input ) ) . toBeUndefined ( )
3232 } )
3333
34+ test . skip ( 'top-level use client' , ( ) => {
35+ // This test is skipped since transformServerActionServer only handles server transforms
36+ // The client transform would be handled by a different function
37+ // @ts -expect-error - unused in skipped test for documentation
38+ const input = `
39+ 'use client';
40+
41+ import { Component, createContext, useContext, memo } from 'react';
42+ import { atom } from 'jotai/vanilla';
43+ import { unstable_allowServer as allowServer } from 'waku/client';
44+
45+ const initialCount = 1;
46+ const TWO = 2;
47+ function double (x: number) {
48+ return x * TWO;
49+ }
50+ export const countAtom = allowServer(atom(double(initialCount)));
51+
52+ export const Empty = () => null;
53+
54+ function Private() {
55+ return "Secret";
56+ }
57+ const SecretComponent = () => <p>Secret</p>;
58+ const SecretFunction = (n: number) => 'Secret' + n;
59+
60+ export function Greet({ name }: { name: string }) {
61+ return <>Hello {name}</>;
62+ }
63+
64+ export class MyComponent extends Component {
65+ render() {
66+ return <p>Class Component</p>;
67+ }
68+ }
69+
70+ const MyContext = createContext();
71+
72+ export const useMyContext = () => useContext(MyContext);
73+
74+ const MyProvider = memo(MyContext);
75+
76+ export const NAME = 'World';
77+
78+ export default function App() {
79+ return (
80+ <MyProvider value="Hello">
81+ <div>Hello World</div>
82+ </MyProvider>
83+ );
84+ }
85+ `
86+ // Expected output would be registerClientReference calls for all exports
87+ } )
88+
3489 test ( 'top-level use server' , async ( ) => {
3590 const input = `
3691'use server';
@@ -352,69 +407,18 @@ export default defaultFn;
352407 } )
353408} )
354409
355- // Client transform tests for documentation (from Waku)
356- // These show expected client-side behavior but are skipped since
357- // transformServerActionServer only handles server transforms
358- describe ( 'client transform examples (for reference)' , ( ) => {
359- test . skip ( 'top-level use client' , ( ) => {
360- // Input:
410+ describe ( 'internal transform function for client environment' , ( ) => {
411+ test . skip ( 'no transformation' , ( ) => {
361412 // @ts -expect-error - unused in skipped test for documentation
362413 const input = `
363- 'use client';
364-
365- import { Component, createContext, useContext, memo } from 'react';
366- import { atom } from 'jotai/vanilla';
367- import { unstable_allowServer as allowServer } from 'waku/client';
368-
369- const initialCount = 1;
370- const TWO = 2;
371- function double (x: number) {
372- return x * TWO;
373- }
374- export const countAtom = allowServer(atom(double(initialCount)));
375-
376- export const Empty = () => null;
377-
378- function Private() {
379- return "Secret";
380- }
381- const SecretComponent = () => <p>Secret</p>;
382- const SecretFunction = (n: number) => 'Secret' + n;
383-
384- export function Greet({ name }: { name: string }) {
385- return <>Hello {name}</>;
386- }
387-
388- export class MyComponent extends Component {
389- render() {
390- return <p>Class Component</p>;
391- }
392- }
393-
394- const MyContext = createContext();
395-
396- export const useMyContext = () => useContext(MyContext);
397-
398- const MyProvider = memo(MyContext);
399-
400- export const NAME = 'World';
401-
402- export default function App() {
403- return (
404- <MyProvider value="Hello">
405- <div>Hello World</div>
406- </MyProvider>
407- );
408- }
414+ export const log = (mesg) => {
415+ console.log(mesg);
416+ };
409417`
410-
411- // Expected Output (from Waku client transform):
412- // registerClientReference calls for all exports
413- // Error-throwing stubs for server environment
418+ // Expected: no transformation for client environment
414419 } )
415420
416- test . skip ( 'top-level use server for client' , ( ) => {
417- // Input:
421+ test . skip ( 'top-level use server' , ( ) => {
418422 // @ts -expect-error - unused in skipped test for documentation
419423 const input = `
420424'use server';
@@ -437,14 +441,10 @@ export default async function log4(mesg) {
437441 console.log(mesg);
438442}
439443`
440-
441- // Expected Output (from Waku client transform):
442- // createServerReference calls for each export
443- // Client-side proxy functions
444+ // Expected Output: createServerReference calls for each export
444445 } )
445446
446447 test . skip ( 'top-level use server for SSR' , ( ) => {
447- // Input:
448448 // @ts -expect-error - unused in skipped test for documentation
449449 const input = `
450450'use server';
@@ -457,8 +457,6 @@ export async function log(mesg) {
457457 console.log(mesg);
458458}
459459`
460-
461- // Expected Output (from Waku SSR transform):
462- // Error-throwing stubs: "You cannot call server functions during SSR"
460+ // Expected Output: Error-throwing stubs "You cannot call server functions during SSR"
463461 } )
464462} )
0 commit comments