Skip to content

Commit 90142a3

Browse files
hi-ogawaclaude
andcommitted
docs(plugin-rsc): simplify contributing guide and fix commands
- Remove Project Structure section and verbose code examples - Reference existing test files instead of inline examples - Fix test commands to use correct test-e2e script name - Add --ui and -g filter options for better developer experience - Streamline content for contributors and coding agents 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 555bb2d commit 90142a3

File tree

1 file changed

+26
-187
lines changed

1 file changed

+26
-187
lines changed

packages/plugin-rsc/CONTRIBUTING.md

Lines changed: 26 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22

33
This guide provides essential tips for contributors working on the RSC plugin.
44

5-
## Project Structure
6-
7-
- `src/` - Plugin source code
8-
- `examples/` - Example projects for testing and documentation
9-
- `e2e/` - End-to-end tests using Playwright
10-
- `types/` - TypeScript type definitions
11-
125
## Testing
136

147
### E2E Test Setup
@@ -17,134 +10,51 @@ The e2e testing uses a scalable approach inspired by React Router's integration
1710

1811
#### Test Fixture Patterns
1912

20-
**1. Using existing examples directly:**
21-
22-
```typescript
23-
// Test against existing example projects
24-
const f = useFixture({ root: 'examples/basic', mode: 'dev' })
25-
```
26-
27-
**2. Creating isolated fixtures (full copy):**
13+
**1. Using existing examples directly:** See `e2e/starter.test.ts` for examples using `useFixture` with existing example projects.
2814

29-
```typescript
30-
// For tests that need to modify files
31-
test.beforeAll(async () => {
32-
await setupIsolatedFixture({
33-
src: 'examples/basic',
34-
dest: 'examples/e2e/temp/my-test',
35-
})
36-
})
37-
```
15+
**2. Creating isolated fixtures:** See `e2e/basic.test.ts` for examples using `setupIsolatedFixture` for tests that need to modify files.
3816

39-
**3. Creating inline fixtures (recommended for new tests):**
40-
41-
```typescript
42-
// For creating test-specific variations
43-
test.beforeAll(async () => {
44-
await setupInlineFixture({
45-
src: 'examples/starter',
46-
dest: 'examples/e2e/temp/my-test',
47-
files: {
48-
'src/root.tsx': /* tsx */ `
49-
export function Root() {
50-
return <div>Custom test content</div>
51-
}
52-
`,
53-
'src/client.tsx': /* tsx */ `
54-
"use client";
55-
export function MyComponent() {
56-
return <span>Client component</span>
57-
}
58-
`,
59-
},
60-
})
61-
})
62-
```
17+
**3. Creating inline fixtures (recommended for new tests):** See `e2e/ssr-thenable.test.ts` for examples using `setupInlineFixture` to create test-specific variations.
6318

6419
The new test structure uses:
6520

6621
- `examples/e2e/temp/` as base directory for test projects
6722
- `setupInlineFixture` utility for creating test environments
6823
- `examples/starter` as the lightweight base template (faster than `examples/basic`)
69-
- Each test project is runnable locally: `pnpm -C packages/plugin-rsc/examples/e2e/temp/my-test dev`
24+
- Each test project is runnable locally
7025

7126
### Adding New Test Cases
7227

73-
#### Option 1: Using `setupInlineFixture` (Recommended)
74-
75-
Best for testing specific features or edge cases:
76-
77-
```typescript
78-
import { setupInlineFixture, useFixture } from './fixture'
79-
80-
test.describe('my-feature', () => {
81-
const root = 'examples/e2e/temp/my-feature'
82-
83-
test.beforeAll(async () => {
84-
await setupInlineFixture({
85-
src: 'examples/starter', // Base template
86-
dest: root,
87-
files: {
88-
// Override/add specific files for your test
89-
'vite.config.ts': /* js */ `
90-
import rsc from '@vitejs/plugin-rsc'
91-
export default {
92-
plugins: [rsc({ /* test options */ })]
93-
}
94-
`,
95-
'src/test-component.tsx': /* tsx */ `
96-
"use client";
97-
export function TestComponent() {
98-
return <div data-testid="test">Hello</div>
99-
}
100-
`,
101-
},
102-
})
103-
})
104-
105-
test.describe('dev', () => {
106-
const f = useFixture({ root, mode: 'dev' })
107-
// Your tests here
108-
})
109-
110-
test.describe('build', () => {
111-
const f = useFixture({ root, mode: 'build' })
112-
// Your tests here
113-
})
114-
})
115-
```
116-
117-
#### Option 2: Expanding `examples/basic`
28+
**Option 1: Using `setupInlineFixture` (Recommended)**
29+
Best for testing specific features or edge cases. See `e2e/ssr-thenable.test.ts` for the pattern.
11830

31+
**Option 2: Expanding `examples/basic`**
11932
Best for comprehensive features that should be part of the main test suite:
12033

12134
1. Add your test case files to `examples/basic/src/routes/`
12235
2. Update the routing in `examples/basic/src/routes/root.tsx`
12336
3. Add corresponding tests in `e2e/basic.test.ts`
12437

125-
### Test Utilities
126-
127-
Key helper functions available in `e2e/helper.ts`:
128-
129-
- `waitForHydration(page)` - Wait for React hydration to complete
130-
- `expectNoReload(page)` - Ensure no page reload during operations
131-
- `expectNoPageError(page)` - Assert no JavaScript errors
132-
- `testNoJs` - Test variant with JavaScript disabled
133-
13438
### Running Tests
13539

13640
```bash
13741
# Run all e2e tests
138-
pnpm test:e2e
42+
pnpm -C packages/plugin-rsc test-e2e
13943

14044
# Run specific test file
141-
pnpm test:e2e basic
45+
pnpm -C packages/plugin-rsc test-e2e basic
46+
47+
# Run with filter/grep
48+
pnpm -C packages/plugin-rsc test-e2e -g "hmr"
49+
50+
# Run with UI (convenient for development)
51+
pnpm -C packages/plugin-rsc test-e2e --ui
14252

14353
# Run with debug output
144-
TEST_DEBUG=1 pnpm test:e2e
54+
TEST_DEBUG=1 pnpm -C packages/plugin-rsc test-e2e
14555

14656
# Skip build step (faster during development)
147-
TEST_SKIP_BUILD=1 pnpm test:e2e
57+
TEST_SKIP_BUILD=1 pnpm -C packages/plugin-rsc test-e2e
14858
```
14959

15060
## Development Workflow
@@ -154,98 +64,27 @@ TEST_SKIP_BUILD=1 pnpm test:e2e
15464
1. Make changes to plugin source code in `src/`
15565
2. Test changes using existing examples:
15666
```bash
157-
cd examples/starter
158-
pnpm dev
67+
# From repo root
68+
pnpm -C packages/plugin-rsc dev
69+
# Or from plugin directory
70+
cd packages/plugin-rsc && pnpm dev
15971
```
16072
3. Run e2e tests to ensure no regressions
16173
4. Add new tests for new features using `setupInlineFixture`
16274

163-
### Plugin Configuration Testing
164-
165-
When testing plugin options, create focused inline fixtures:
166-
167-
```typescript
168-
await setupInlineFixture({
169-
src: 'examples/starter',
170-
dest: root,
171-
files: {
172-
'vite.config.ts': /* js */ `
173-
import rsc from '@vitejs/plugin-rsc'
174-
export default {
175-
plugins: [
176-
rsc({
177-
// Test specific plugin options here
178-
loadModuleDevProxy: true,
179-
rscCssTransform: { filter: id => id.includes('test') }
180-
})
181-
]
182-
}
183-
`,
184-
},
185-
})
186-
```
187-
188-
### CSS and Style Testing
189-
190-
CSS handling is a key feature. Test CSS injection patterns:
191-
192-
```typescript
193-
files: {
194-
'src/styles.css': /* css */ `
195-
.test-class { color: red; }
196-
`,
197-
'src/component.tsx': /* tsx */ `
198-
import './styles.css'
199-
export function Component() {
200-
return <div className="test-class">Styled</div>
201-
}
202-
`
203-
}
204-
```
75+
### Test Project Debugging
20576

206-
## Common Testing Patterns
207-
208-
### Server Actions Testing
209-
210-
```typescript
211-
files: {
212-
'src/actions.tsx': /* tsx */ `
213-
"use server";
214-
export async function myAction(formData: FormData) {
215-
return { success: true }
216-
}
217-
`,
218-
'src/form.tsx': /* tsx */ `
219-
import { myAction } from './actions'
220-
export function Form() {
221-
return <form action={myAction}>...</form>
222-
}
223-
`
224-
}
225-
```
77+
Test projects created with `setupInlineFixture` are locally runnable:
22678

227-
### HMR Testing
228-
229-
Use the `expectNoReload` pattern and file editors:
230-
231-
```typescript
232-
test('hmr works', async ({ page }) => {
233-
using _ = await expectNoReload(page)
234-
const editor = f.createEditor('src/component.tsx')
235-
236-
await page.goto(f.url())
237-
editor.edit((content) => content.replace('Hello', 'Hi'))
238-
239-
await expect(page.locator('[data-testid="greeting"]')).toHaveText('Hi')
240-
})
79+
```bash
80+
pnpm -C packages/plugin-rsc/examples/e2e/temp/my-test dev
24181
```
24282

24383
## Tips
24484

245-
- Use `/* tsx */` and `/* css */` comments for syntax highlighting in template literals
85+
- Study existing test patterns in `e2e/` directory
24686
- Prefer `setupInlineFixture` for new tests - it's more maintainable and faster
24787
- Always test both dev and build modes when adding new features
24888
- Use `TEST_DEBUG=1` to see detailed output during test development
249-
- Test projects are locally runnable for debugging: `pnpm -C packages/plugin-rsc/examples/e2e/temp/my-test dev`
25089
- The `examples/basic` project contains comprehensive test scenarios - study it for inspiration
25190
- Dependencies for temp test projects are managed in `examples/e2e/package.json`

0 commit comments

Comments
 (0)