Colum Ferry 07f1215411
fix(module-federation): tuple remotes should have global identifier added if missing (#29811)
## Current Behavior
Our Module Federation Config allows passing tuple remotes:

```js
remotes: [
  ["remote1", "http://localhost:4201/remoteEntry.js"]
]
```

However, if the Module Federation system is expecting the remotes to be
loaded as Global variables in the browser, then we erroneously pass just
the url to webpack/rspack's `extractUrlAndGlobal` method.

This expects a string of format `name@url`. For non-tuple remote
configurations, we create this correctly.
However, when a tuple is passed, we simply return the url.


## Expected Behavior
We should ensure that the string is massaged to `name@url` even when a
tuple is provided.
2025-01-30 12:52:46 +00:00

59 lines
1.6 KiB
TypeScript

import { mapRemotes } from './remotes';
describe('mapRemotes', () => {
it('should map string remotes', () => {
expect(
mapRemotes(
['remote1', 'remote2', 'remote3'],
'js',
(remote) => {
return `http://localhost:300${remote.at(-1)}/remoteEntry.js`;
},
true
)
).toEqual({
remote1: 'remote1@http://localhost:3001/remoteEntry.js',
remote2: 'remote2@http://localhost:3002/remoteEntry.js',
remote3: 'remote3@http://localhost:3003/remoteEntry.js',
});
});
it('should map array remotes', () => {
expect(
mapRemotes(
[
['remote1', 'http://localhost:4201'],
['remote2', 'http://localhost:4202'],
['remote3', 'http://localhost:4203'],
],
'js',
(remote) => remote,
true
)
).toEqual({
remote1: 'remote1@http://localhost:4201/remoteEntry.js',
remote2: 'remote2@http://localhost:4202/remoteEntry.js',
remote3: 'remote3@http://localhost:4203/remoteEntry.js',
});
});
it('should map array remotes with path to remoteEntry', () => {
expect(
mapRemotes(
[
['remote1', 'http://localhost:4201/remoteEntry.js'],
['remote2', 'http://localhost:4202/remoteEntry.mjs'],
['remote3', 'http://localhost:4203/mf-manifest.json'],
],
'js',
(remote) => remote,
true
)
).toEqual({
remote1: 'remote1@http://localhost:4201/remoteEntry.js',
remote2: 'remote2@http://localhost:4202/remoteEntry.mjs',
remote3: 'remote3@http://localhost:4203/mf-manifest.json',
});
});
});