Skip to content

Conversation

@hi-ogawa
Copy link
Contributor

Summary

Port server action test cases from Waku's vite-plugin-rsc-transform-internals.test.ts to ensure @vitejs/plugin-rsc covers the same use cases as Waku adoption progresses.

Test Coverage

Added 8 comprehensive test cases covering:

  • No transformation - Basic cases that shouldn't be transformed
  • Top-level 'use server' - File-level server directives with various export patterns
  • Inline server actions - Function declarations, arrow functions, anonymous functions
  • Server actions in objects - Actions defined within object properties
  • Various patterns - Multiple server action declaration styles in one file
  • Mixed scenarios - Top-level and inline server actions together
  • Closure capture - Variable hoisting and binding for server actions

Test Verification

✅ All 42 tests pass (8 new + 34 existing)
pnpm -C packages/plugin-rsc test - successful
pnpm -C packages/plugin-rsc tsc - no type errors

Context

As Waku adopts @vitejs/plugin-rsc, these tests ensure feature parity and compatibility for server action transforms across both projects.

🤖 Generated with Claude Code

hi-ogawa and others added 10 commits July 30, 2025 14:03
Port server action test cases from Waku's vite-plugin-rsc-transform-internals.test.ts
to ensure @vitejs/plugin-rsc covers the same use cases as Waku adoption progresses.

Test coverage includes:
- Top-level 'use server' directives
- Inline server actions (function declarations, arrow functions, anonymous functions)
- Server actions in objects
- Various function declaration patterns
- Mixed server/client scenarios
- Closure capture and variable hoisting

All 8 new test cases pass alongside existing tests.
Verified with both `pnpm test` and `pnpm tsc`.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- 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]>
Add @ts-expect-error comments for unused variables in documentation-only skipped tests.
All tests pass and TypeScript compiles without errors.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Reorder test cases to exactly match the sequence in Waku's
vite-plugin-rsc-transform-internals.test.ts for easier comparison
and maintenance consistency.

Order now matches:
1. no transformation
2. top-level use server
3. server action in object
4. top-level use server and inline use server
5-9. inline use server variations (function declaration, const function expression, const arrow function, anonymous arrow function, various patterns)

All tests continue to pass with proper snapshots.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Change __registerServerReference to 81712register for cleaner snapshots
- Remove unused testTransform options (rejectNonAsyncFunction, encode)
- Simplify testTransform function signature to just accept input string
- All tests continue to pass with simplified assertions

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
The test file covers broader RSC transform functionality ported from Waku's
vite-plugin-rsc-transform-internals.test.ts, not just server actions.
It tests server actions, client references, and various RSC patterns.

The name 'waku.test.ts' better reflects that this is a comprehensive port
of Waku's RSC transform test cases for compatibility verification.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Update test structure to exactly match Waku's original:

1. Change describe block names:
   - 'transformServerActionServer' → 'internal transform function for server environment'
   - 'client transform examples (for reference)' → 'internal transform function for client environment'

2. Add missing 'top-level use client' test in server environment (skipped)

3. Update client environment tests to match original sequence:
   - 'no transformation' (skipped)
   - 'top-level use server' (skipped)
   - 'top-level use server for SSR' (skipped)

4. Remove duplicate client test content

Final structure matches Waku's vite-plugin-rsc-transform-internals.test.ts:
- Server environment: 10 tests (9 active + 1 skipped)
- Client environment: 3 tests (all skipped for reference)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Replace commented expected outputs with proper string literals for better
documentation and readability. This makes it easier to understand what
the Waku transforms produce for each test case.

Changes:
- 'top-level use client' server transform: registerClientReference calls with error-throwing stubs
- 'top-level use server' client transform: createServerReference calls
- 'top-level use server for SSR': error-throwing stubs for SSR environment

All outputs copied directly from Waku's actual test snapshots.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Enable previously skipped tests for complete coverage
- Implement proper client environment transforms using vitePluginUseServer approach
- Unify transformDirectiveProxyExport usage with single testDirectiveTransform utility
- Enable keep option for 'use client' directive to preserve original code structure
- All 13 tests now passing with comprehensive RSC transform coverage

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Change server environment $$register calls to $runtime
- Maintain consistent runtime interface across all transforms
- All server and client transforms now use unified $runtime pattern

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@hi-ogawa hi-ogawa changed the title test(rsc): add comprehensive server action transform tests test(rsc): port test case from waku Jul 30, 2025
@hi-ogawa hi-ogawa changed the title test(rsc): port test case from waku test(rsc): port transform tests from waku Jul 30, 2025
@hi-ogawa hi-ogawa merged commit c602225 into main Jul 30, 2025
21 checks passed
@hi-ogawa hi-ogawa deleted the test/server-action-tests branch July 30, 2025 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant