Skip to content

Commit a11be5f

Browse files
committed
test: add e2e
1 parent a3953ec commit a11be5f

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,13 @@ function defineTest(f: Fixture) {
244244
await page.getByRole('button', { name: 'client-counter: 1' }).click()
245245
})
246246

247+
test('import environment', async ({ page }) => {
248+
await page.goto(f.url())
249+
await expect(page.getByTestId('import-environment')).toHaveText(
250+
'[test-import-environment: test-ssr]',
251+
)
252+
})
253+
247254
test('server action @js', async ({ page }) => {
248255
await page.goto(f.url())
249256
await waitForHydration(page)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
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()
7+
return (
8+
<div data-testid="import-environment">
9+
[test-import-environment:{' '}
10+
<span dangerouslySetInnerHTML={{ __html: html }} />]
11+
</div>
12+
)
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useState } from 'react'
2+
import { renderToString } from 'react-dom/server'
3+
4+
// SSR-only: useState and renderToString are not available in RSC environment
5+
6+
function ClientComponent() {
7+
const [state] = useState('test-ssr')
8+
return <span>{state}</span>
9+
}
10+
11+
export function testSsrModule(): string {
12+
return renderToString(<ClientComponent />)
13+
}

packages/plugin-rsc/examples/basic/src/routes/root.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { TestHmrSharedServer } from './hmr-shared/server'
3434
import { TestHmrSwitchClient } from './hmr-switch/client'
3535
import { TestHmrSwitchServer } from './hmr-switch/server'
3636
import { TestHydrationMismatch } from './hydration-mismatch/server'
37+
import { TestImportEnvironment } from './import-environment/server'
3738
import { TestImportMetaGlob } from './import-meta-glob/server'
3839
import { TestLazyCssClientToClient } from './lazy-css/client-to-client'
3940
import { TestLazyCssServerToClient } from './lazy-css/server-to-client'
@@ -111,6 +112,7 @@ export function Root(props: { url: URL }) {
111112
<TestReactCache url={props.url} />
112113
<TestCssQueries />
113114
<TestImportMetaGlob />
115+
<TestImportEnvironment />
114116
<TestAssetsServer />
115117
<TestTreeShakeServer />
116118
<TestTreeShake2 />

0 commit comments

Comments
 (0)