Skip to content

Commit c48caaa

Browse files
committed
test: add e2e
1 parent ea20779 commit c48caaa

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
})

packages/plugin-rsc/src/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ function vitePluginUseClient(
11401140
const directives = findDirectives(ast, 'use server')
11411141
if (directives.length > 0) {
11421142
this.error(
1143-
`'use server' directive is not allowed within 'use client'`,
1143+
`'use server' directive is not allowed inside 'use client'`,
11441144
directives[0]?.start,
11451145
)
11461146
}

0 commit comments

Comments
 (0)