|
| 1 | +import { test, expect } from '@playwright/test' |
| 2 | +import { setupInlineFixture } from './fixture' |
| 3 | +import { x } from 'tinyexec' |
| 4 | + |
| 5 | +test.describe('invalid directives', () => { |
| 6 | + test.describe('"use server" in "use client"', () => { |
| 7 | + const root = 'examples/e2e/temp/use-server-in-use-client' |
| 8 | + test.beforeAll(async () => { |
| 9 | + await setupInlineFixture({ |
| 10 | + src: 'examples/starter', |
| 11 | + dest: root, |
| 12 | + files: { |
| 13 | + 'src/client.tsx': /* tsx */ ` |
| 14 | + "use client"; |
| 15 | + |
| 16 | + export function TestClient() { |
| 17 | + return <div>[test-client]</div> |
| 18 | + } |
| 19 | +
|
| 20 | + function testFn() { |
| 21 | + "use server"; |
| 22 | + console.log("testFn"); |
| 23 | + } |
| 24 | + `, |
| 25 | + 'src/root.tsx': /* tsx */ ` |
| 26 | + import { TestClient } from './client.tsx' |
| 27 | + |
| 28 | + export function Root() { |
| 29 | + return ( |
| 30 | + <html lang="en"> |
| 31 | + <head> |
| 32 | + <meta charSet="UTF-8" /> |
| 33 | + </head> |
| 34 | + <body> |
| 35 | + <div>[test-server]</div> |
| 36 | + <TestClient /> |
| 37 | + </body> |
| 38 | + </html> |
| 39 | + ) |
| 40 | + } |
| 41 | + `, |
| 42 | + }, |
| 43 | + }) |
| 44 | + }) |
| 45 | + |
| 46 | + test('build', async () => { |
| 47 | + const result = await x('pnpm', ['build'], { |
| 48 | + throwOnError: false, |
| 49 | + nodeOptions: { cwd: root }, |
| 50 | + }) |
| 51 | + expect(result.stderr).toContain( |
| 52 | + `'use server' directive is not allowed inside 'use client'`, |
| 53 | + ) |
| 54 | + expect(result.exitCode).not.toBe(0) |
| 55 | + }) |
| 56 | + }) |
| 57 | +}) |
0 commit comments