Skip to content

Commit e9f09d3

Browse files
committed
test(rsc-mf): assert config expose map matches expected userland keys
1 parent 7dde578 commit e9f09d3

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const EXPECTED_REMOTE_EXPOSE_PATHS = [
3535
'./actionBundle',
3636
'./infoBundle',
3737
].sort();
38+
const REMOTE_EXPOSE_ENTRY_PATTERN =
39+
/'(\.\/[^']+)':\s*'(\.\/src\/components\/[^']+)'/g;
3840

3941
type Mode = 'dev' | 'build';
4042

@@ -93,6 +95,15 @@ function createHostEnv(remotePort: number) {
9395
};
9496
}
9597

98+
function getRemoteExposeEntries(configSource: string) {
99+
return Array.from(configSource.matchAll(REMOTE_EXPOSE_ENTRY_PATTERN)).map(
100+
([, exposeKey, importPath]) => ({
101+
exposeKey,
102+
importPath,
103+
}),
104+
);
105+
}
106+
96107
async function renderRemoteRscIntoHost({ hostPort, page }: TestContext) {
97108
const response = await fetch(`http://127.0.0.1:${hostPort}${HOST_RSC_URL}`);
98109
const html = await response.text();
@@ -497,6 +508,12 @@ function runTests({ mode }: TestConfig) {
497508
path.join(remoteDir, 'module-federation.config.ts'),
498509
'utf-8',
499510
);
511+
const remoteExposeEntries = getRemoteExposeEntries(
512+
moduleFederationConfigSource,
513+
);
514+
const remoteExposeKeys = remoteExposeEntries
515+
.map(({ exposeKey }) => exposeKey)
516+
.sort();
500517

501518
expect(
502519
componentSources.every(
@@ -535,6 +552,12 @@ function runTests({ mode }: TestConfig) {
535552
expect(moduleFederationConfigSource).toContain(
536553
'nonComponentExposeEntries',
537554
);
555+
expect(remoteExposeKeys).toEqual(EXPECTED_REMOTE_EXPOSE_PATHS);
556+
expect(
557+
remoteExposeEntries.every(({ importPath }) =>
558+
importPath.startsWith('./src/components/'),
559+
),
560+
).toBe(true);
538561
});
539562

540563
it('should not load callback helper expose chunk', () => {

0 commit comments

Comments
 (0)