|
1 | 1 | import { test, expect } from '@playwright/test' |
2 | | -import { setupInlineFixture, useFixture } from './fixture' |
| 2 | +import { setupInlineFixture, useFixture, type Fixture } from './fixture' |
3 | 3 | import { x } from 'tinyexec' |
4 | 4 | import path from 'node:path' |
| 5 | +import { expectNoPageError, waitForHydration } from './helper' |
5 | 6 |
|
6 | 7 | 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 | + |
7 | 64 | test('should fail build when server-only is imported in client component', async () => { |
8 | 65 | const root = 'examples/e2e/temp/validate-imports-server-only-client' |
9 | 66 |
|
@@ -102,15 +159,6 @@ test.describe('validate imports', () => { |
102 | 159 | }, |
103 | 160 | }) |
104 | 161 |
|
105 | | - // Install dependencies |
106 | | - await x('pnpm', ['i'], { |
107 | | - throwOnError: true, |
108 | | - nodeOptions: { |
109 | | - cwd: root, |
110 | | - stdio: 'ignore', |
111 | | - }, |
112 | | - }) |
113 | | - |
114 | 162 | // Expect build to fail |
115 | 163 | const result = await x('pnpm', ['build'], { |
116 | 164 | throwOnError: false, |
|
0 commit comments