1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29import { test, expect } from "@playwright/test";
const BASE = "http://localhost:4174";
test.describe("CJS interop", () => {
test("server component with CJS require('server-only') renders correctly", async ({
page,
}) => {
await page.goto(`${BASE}/cjs/server-only`);
await expect(page.getByTestId("cjs-server-only")).toContainText(
"This page uses CJS require",
);
});
test("server component with CJS require() and module.exports renders correctly", async ({
page,
}) => {
await page.goto(`${BASE}/cjs/basic`);
await expect(page.getByTestId("cjs-basic")).toContainText("Random: 4");
});
// The server-only-violation test lives in a separate fixture
// (tests/fixtures/app-cjs-violation/) because the intentional violation
// causes a fatal error during production builds of app-basic, breaking
// unrelated tests. The RSC plugin's server-only boundary enforcement for
// CJS require("server-only") is verified by the production build validation.
});