Skip to content

Commit 3dcefb8

Browse files
committed
test: add e2e
1 parent a11be5f commit 3dcefb8

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

packages/plugin-rsc/e2e/basic.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ function defineTest(f: Fixture) {
247247
test('import environment', async ({ page }) => {
248248
await page.goto(f.url())
249249
await expect(page.getByTestId('import-environment')).toHaveText(
250-
'[test-import-environment: test-ssr]',
250+
'[test-import-environment: test-ssr-module: test-rsc-module]',
251251
)
252252
})
253253

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const testRscModule = async () => 'test-rsc-module'

packages/plugin-rsc/examples/basic/src/routes/import-environment/server.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
export async function TestImportEnvironment() {
2-
const ssr = await import.meta.viteRsc.import<typeof import('./ssr')>(
3-
'./ssr.tsx',
4-
{ environment: 'ssr' },
5-
)
6-
const html = ssr.testSsrModule()
2+
const { testSsrModule } = await import.meta.viteRsc.import<
3+
typeof import('./ssr')
4+
>('./ssr.tsx', { environment: 'ssr' })
5+
const html = await testSsrModule()
76
return (
87
<div data-testid="import-environment">
98
[test-import-environment:{' '}

packages/plugin-rsc/examples/basic/src/routes/import-environment/ssr.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@ import { renderToString } from 'react-dom/server'
44
// SSR-only: useState and renderToString are not available in RSC environment
55

66
function ClientComponent() {
7-
const [state] = useState('test-ssr')
8-
return <span>{state}</span>
7+
const [state] = useState('test-ssr-module')
8+
return <>{state}</>
99
}
1010

11-
export function testSsrModule(): string {
12-
return renderToString(<ClientComponent />)
11+
export async function testSsrModule() {
12+
const { testRscModule } = await import.meta.viteRsc.import<
13+
typeof import('./rsc')
14+
>('./rsc.tsx', { environment: 'rsc' })
15+
const value = await testRscModule()
16+
return renderToString(
17+
<>
18+
<ClientComponent />: {value}
19+
</>,
20+
)
1321
}

0 commit comments

Comments
 (0)