Skip to content

Commit 1a291c7

Browse files
committed
test(rsc-mf): cover federation remotes-array and ssr-only path fallbacks
1 parent fc5e851 commit 1a291c7

1 file changed

Lines changed: 90 additions & 0 deletions

File tree

tests/integration/rsc-mf/tests/forceRemotePublicPath.test.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,53 @@ describe('host forceRemotePublicPath runtime plugin', () => {
146146
);
147147
});
148148

149+
it('resolves remote public paths from __FEDERATION__ remotes array entries', () => {
150+
(
151+
globalThis as typeof globalThis & {
152+
__FEDERATION__?: unknown;
153+
}
154+
).__FEDERATION__ = {
155+
__INSTANCES__: [
156+
{
157+
options: {
158+
remotes: [
159+
{
160+
alias: 'rscRemote',
161+
entry:
162+
'https://federation-array.example.com/static/mf-manifest.json',
163+
},
164+
],
165+
},
166+
},
167+
],
168+
} as any;
169+
const plugin = forceRemotePublicPath();
170+
const args = {
171+
remoteInfo: {
172+
alias: 'rscRemote',
173+
},
174+
remoteSnapshot: {
175+
publicPath: 'http://stale.example.com/',
176+
metaData: {
177+
publicPath: 'http://stale.example.com/',
178+
ssrPublicPath: 'http://stale.example.com/bundles/',
179+
},
180+
},
181+
};
182+
183+
plugin.loadRemoteSnapshot?.(args as any);
184+
185+
expect(args.remoteSnapshot.publicPath).toBe(
186+
'https://federation-array.example.com/',
187+
);
188+
expect(args.remoteSnapshot.metaData.publicPath).toBe(
189+
'https://federation-array.example.com/',
190+
);
191+
expect(args.remoteSnapshot.metaData.ssrPublicPath).toBe(
192+
'https://federation-array.example.com/bundles/',
193+
);
194+
});
195+
149196
it('resolves remote public paths from __FEDERATION__ module metadata fallback', () => {
150197
(
151198
globalThis as typeof globalThis & {
@@ -190,6 +237,49 @@ describe('host forceRemotePublicPath runtime plugin', () => {
190237
);
191238
});
192239

240+
it('derives publicPath from __FEDERATION__ ssrPublicPath-only metadata', () => {
241+
(
242+
globalThis as typeof globalThis & {
243+
__FEDERATION__?: unknown;
244+
}
245+
).__FEDERATION__ = {
246+
moduleInfo: {
247+
customModuleInfoKey: {
248+
alias: 'rscRemote',
249+
metaData: {
250+
ssrPublicPath:
251+
'https://federation-ssr-only.example.com/assets/bundles/?cache=1#hash',
252+
},
253+
},
254+
},
255+
} as any;
256+
const plugin = forceRemotePublicPath();
257+
const args = {
258+
remoteInfo: {
259+
alias: 'rscRemote',
260+
},
261+
remoteSnapshot: {
262+
publicPath: 'http://stale.example.com/',
263+
metaData: {
264+
publicPath: 'http://stale.example.com/',
265+
ssrPublicPath: 'http://stale.example.com/bundles/',
266+
},
267+
},
268+
};
269+
270+
plugin.loadRemoteSnapshot?.(args as any);
271+
272+
expect(args.remoteSnapshot.publicPath).toBe(
273+
'https://federation-ssr-only.example.com/assets/',
274+
);
275+
expect(args.remoteSnapshot.metaData.publicPath).toBe(
276+
'https://federation-ssr-only.example.com/assets/',
277+
);
278+
expect(args.remoteSnapshot.metaData.ssrPublicPath).toBe(
279+
'https://federation-ssr-only.example.com/assets/bundles/',
280+
);
281+
});
282+
193283
it('does not mutate when entry is not a valid URL', () => {
194284
const plugin = forceRemotePublicPath();
195285
const args = {

0 commit comments

Comments
 (0)