Skip to content

Commit 15ebd9d

Browse files
committed
test: valid imports
1 parent 85f1e63 commit 15ebd9d

File tree

1 file changed

+58
-10
lines changed

1 file changed

+58
-10
lines changed

packages/plugin-rsc/e2e/validate-imports.test.ts

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,66 @@
11
import { test, expect } from '@playwright/test'
2-
import { setupInlineFixture, useFixture } from './fixture'
2+
import { setupInlineFixture, useFixture, type Fixture } from './fixture'
33
import { x } from 'tinyexec'
44
import path from 'node:path'
5+
import { expectNoPageError, waitForHydration } from './helper'
56

67
test.describe('validate imports', () => {
8+
test.describe('valid imports', () => {
9+
const root = 'examples/e2e/temp/validate-imports-server-only-client'
10+
test.beforeAll(async () => {
11+
await setupInlineFixture({
12+
src: 'examples/starter',
13+
dest: root,
14+
files: {
15+
'src/client.tsx': /* tsx */ `
16+
"use client";
17+
import 'client-only';
18+
19+
export function TestClient() {
20+
return <div>[test-client]</div>
21+
}
22+
`,
23+
'src/root.tsx': /* tsx */ `
24+
import { TestClient } from './client.tsx'
25+
import 'server-only';
26+
27+
export function Root() {
28+
return (
29+
<html lang="en">
30+
<head>
31+
<meta charSet="UTF-8" />
32+
</head>
33+
<body>
34+
<div>[test-server]</div>
35+
<TestClient />
36+
</body>
37+
</html>
38+
)
39+
}
40+
`,
41+
},
42+
})
43+
})
44+
45+
test.describe('dev', () => {
46+
const f = useFixture({ root, mode: 'dev' })
47+
defineTest(f)
48+
})
49+
50+
test.describe('build', () => {
51+
const f = useFixture({ root, mode: 'build' })
52+
defineTest(f)
53+
})
54+
55+
function defineTest(f: Fixture) {
56+
test('basic', async ({ page }) => {
57+
using _ = expectNoPageError(page)
58+
await page.goto(f.url())
59+
await waitForHydration(page)
60+
})
61+
}
62+
})
63+
764
test('should fail build when server-only is imported in client component', async () => {
865
const root = 'examples/e2e/temp/validate-imports-server-only-client'
966

@@ -102,15 +159,6 @@ test.describe('validate imports', () => {
102159
},
103160
})
104161

105-
// Install dependencies
106-
await x('pnpm', ['i'], {
107-
throwOnError: true,
108-
nodeOptions: {
109-
cwd: root,
110-
stdio: 'ignore',
111-
},
112-
})
113-
114162
// Expect build to fail
115163
const result = await x('pnpm', ['build'], {
116164
throwOnError: false,

0 commit comments

Comments
 (0)