Skip to content

Commit b6c6176

Browse files
cursoragentScriptedAlchemy
authored andcommitted
test(examples): expand playwright coverage for rsc federation
1 parent d74cb3b commit b6c6176

1 file changed

Lines changed: 98 additions & 0 deletions

File tree

examples/rsbuild-rsc-federation/e2e/app.spec.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ for (const app of appUrls) {
99
test(`renders ${app.name} demo app and supports interaction`, async ({
1010
page,
1111
}) => {
12+
const pageErrors: string[] = [];
13+
page.on('pageerror', (error) => {
14+
pageErrors.push(error.message);
15+
});
16+
1217
await page.goto(app.url);
1318

1419
await expect(page.getByTestId('app-ready')).toBeVisible();
@@ -24,5 +29,98 @@ for (const app of appUrls) {
2429
await page.getByTestId('increment-button').click();
2530

2631
await expect(page.getByTestId('counter-value')).toHaveText('2');
32+
expect(pageErrors).toEqual([]);
33+
});
34+
35+
test(`serves ${app.name} RSC federation artifacts`, async ({ request }) => {
36+
const baseUrl = app.url.replace(/\/$/, '');
37+
const [
38+
statsResponse,
39+
manifestResponse,
40+
clientStatsResponse,
41+
clientManifestResponse,
42+
remoteEntryResponse,
43+
remoteEntryClientResponse,
44+
] = await Promise.all([
45+
request.get(`${baseUrl}/mf-stats.json`),
46+
request.get(`${baseUrl}/mf-manifest.json`),
47+
request.get(`${baseUrl}/mf-manifest.client-stats.json`),
48+
request.get(`${baseUrl}/mf-manifest.client.json`),
49+
request.get(`${baseUrl}/remoteEntry.js`),
50+
request.get(`${baseUrl}/remoteEntry.client.js`),
51+
]);
52+
53+
expect(statsResponse.status()).toBe(200);
54+
expect(manifestResponse.status()).toBe(200);
55+
expect(clientStatsResponse.status()).toBe(200);
56+
expect(clientManifestResponse.status()).toBe(200);
57+
expect(remoteEntryResponse.status()).toBe(200);
58+
expect(remoteEntryClientResponse.status()).toBe(200);
59+
60+
const stats = await statsResponse.json();
61+
const manifest = await manifestResponse.json();
62+
const clientStats = await clientStatsResponse.json();
63+
const clientManifest = await clientManifestResponse.json();
64+
const remoteEntryText = await remoteEntryResponse.text();
65+
const remoteEntryClientText = await remoteEntryClientResponse.text();
66+
67+
const expectedServerExposes = [
68+
'./button',
69+
'./composed',
70+
'./consumer',
71+
'./server-mixed',
72+
];
73+
const expectedClientExposes = ['./button', './composed'];
74+
75+
const statsExposePaths = stats.exposes.map(
76+
(expose: { path: string }) => expose.path,
77+
);
78+
const manifestExposePaths = manifest.exposes.map(
79+
(expose: { path: string }) => expose.path,
80+
);
81+
const clientStatsExposePaths = clientStats.exposes.map(
82+
(expose: { path: string }) => expose.path,
83+
);
84+
const clientManifestExposePaths = clientManifest.exposes.map(
85+
(expose: { path: string }) => expose.path,
86+
);
87+
88+
for (const exposePath of expectedServerExposes) {
89+
expect(statsExposePaths).toContain(exposePath);
90+
expect(manifestExposePaths).toContain(exposePath);
91+
}
92+
93+
for (const exposePath of expectedClientExposes) {
94+
expect(clientStatsExposePaths).toContain(exposePath);
95+
expect(clientManifestExposePaths).toContain(exposePath);
96+
}
97+
98+
const sharedNames = stats.shared.map(
99+
(shared: { name: string }) => shared.name,
100+
);
101+
expect(sharedNames).toContain('rsc-shared-key');
102+
expect(sharedNames).toContain('rsc-shared-actions-key');
103+
104+
const sharedActionsEntry = stats.shared.find(
105+
(shared: {
106+
name: string;
107+
rsc?: { serverActions?: Array<{ id: string; name: string }> };
108+
}) => shared.name === 'rsc-shared-actions-key',
109+
);
110+
expect(sharedActionsEntry?.rsc?.serverActions?.length).toBeGreaterThan(0);
111+
112+
const remoteEntry = stats.remotes.find(
113+
(remote: {
114+
alias: string;
115+
moduleName: string;
116+
rsc?: { lookup?: string };
117+
}) => remote.alias === 'remote' && remote.moduleName === 'Button',
118+
);
119+
expect(remoteEntry?.rsc?.lookup).toBe('remote/Button');
120+
121+
expect(remoteEntryText).toContain('server-mixed');
122+
expect(remoteEntryText).toContain('composed');
123+
expect(remoteEntryClientText).toContain('composed');
124+
expect(remoteEntryClientText).toContain('button');
27125
});
28126
}

0 commit comments

Comments
 (0)