Skip to content

Commit b1c2710

Browse files
committed
fix: add some failing tests
1 parent 46b008a commit b1c2710

File tree

3 files changed

+27
-32
lines changed

3 files changed

+27
-32
lines changed

packages/runtime-core/src/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export class FederationHost {
247247
// eslint-disable-next-line @typescript-eslint/member-ordering
248248
async loadRemote<T>(
249249
id: string,
250-
options?: { loadFactory?: boolean; from: CallFrom; root?: HTMLElement },
250+
options?: { loadFactory?: boolean; from?: CallFrom; root?: HTMLElement },
251251
): Promise<T | null> {
252252
return this.remoteHandler.loadRemote(id, options);
253253
}

packages/runtime-core/src/remote/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export class RemoteHandler {
198198
// eslint-disable-next-line @typescript-eslint/member-ordering
199199
async loadRemote<T>(
200200
id: string,
201-
options?: { loadFactory?: boolean; from: CallFrom; root?: HTMLElement },
201+
options?: { loadFactory?: boolean; from?: CallFrom; root?: HTMLElement },
202202
): Promise<T | null> {
203203
const { host } = this;
204204
try {

packages/runtime/__tests__/load-remote.spec.ts

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -600,17 +600,20 @@ describe('loadRemote', () => {
600600
const loadedSrcs = [...document.querySelectorAll('script')].map(
601601
(i) => (i as any).fakeSrc,
602602
);
603+
const loadedStyles = [...document.querySelectorAll('link')].map(
604+
(link) => link.href,
605+
);
603606
expect(loadedSrcs.includes(`${remotePublicPath}${jsSyncAssetPath}`));
607+
expect(loadedStyles.includes(`${remotePublicPath}sub2/say.sync.css`));
608+
604609
reset();
605610
});
606611

607-
it('renders css in shadowRoot when providing a different root', async () => {
608-
const shadowRoot = document.createElement('div');
609-
const cssSyncPath = 'sub2/say.sync.css';
610-
const cssAsyncPath = 'sub2/say.async.css';
612+
it('loads remote synchronously in a custom root', async () => {
613+
const jsSyncAssetPath = 'resources/load-remote/app2/say.sync.js';
611614
const remotePublicPath = 'http://localhost:1111/';
612615
const reset = addGlobalSnapshot({
613-
'@federation-test/shadow-css': {
616+
'@federation-test/globalinfo': {
614617
globalName: '',
615618
buildVersion: '',
616619
publicPath: '',
@@ -639,11 +642,11 @@ describe('loadRemote', () => {
639642
moduleName: 'say',
640643
assets: {
641644
css: {
642-
sync: [cssSyncPath],
643-
async: [cssAsyncPath],
645+
sync: ['sub2/say.sync.css'],
646+
async: ['sub2/say.async.css'],
644647
},
645648
js: {
646-
sync: ['resources/load-remote/app2/say.sync.js'],
649+
sync: [jsSyncAssetPath],
647650
async: [],
648651
},
649652
},
@@ -655,7 +658,7 @@ describe('loadRemote', () => {
655658
});
656659

657660
const FederationInstance = new FederationHost({
658-
name: '@federation-test/shadow-css',
661+
name: '@federation-test/globalinfo',
659662
remotes: [
660663
{
661664
name: '@federation-test/app2',
@@ -664,32 +667,24 @@ describe('loadRemote', () => {
664667
],
665668
});
666669

670+
const root = document.createElement('div');
667671
await FederationInstance.loadRemote<() => string>(
668672
'@federation-test/app2/say',
669-
{ root: shadowRoot },
673+
{ root },
670674
);
671-
672-
// Verify CSS links were appended to the shadowRoot
673-
const cssLinks = shadowRoot.querySelectorAll('link');
674-
console.log(document.head.querySelectorAll('link'));
675-
expect(cssLinks.length).toBeGreaterThan(0); // Should have CSS links
676-
677-
// Check that the CSS links have the correct href attributes
678-
const hrefs = Array.from(cssLinks).map((link) => link.getAttribute('href'));
679-
680-
// At least one of the CSS files should be loaded in the shadowRoot
681-
const hasCssInShadowRoot = hrefs.some(
682-
(href) =>
683-
href === `${remotePublicPath}${cssSyncPath}` ||
684-
href === `${remotePublicPath}${cssAsyncPath}`,
675+
// @ts-ignore fakeSrc is local mock attr, which value is the same as src
676+
const loadedSrcs = [...document.querySelectorAll('script')].map(
677+
(i) => (i as any).fakeSrc,
685678
);
686-
expect(hasCssInShadowRoot).toBe(true);
687-
688-
// Verify the links have the correct rel attribute for stylesheets
689-
const stylesheetLinks = Array.from(cssLinks).filter(
690-
(link) => link.getAttribute('rel') === 'stylesheet',
679+
const loadedStyles = [...root.querySelectorAll('link')].map(
680+
(link) => link.href,
691681
);
692-
expect(stylesheetLinks.length).toBeGreaterThan(0);
682+
const documentStyles = [...document.head.querySelectorAll('link')].map(
683+
(link) => link.href,
684+
);
685+
expect(loadedSrcs.includes(`${remotePublicPath}${jsSyncAssetPath}`));
686+
expect(loadedStyles.includes(`${remotePublicPath}sub2/say.sync.css`));
687+
expect(documentStyles).toEqual([]);
693688

694689
reset();
695690
});

0 commit comments

Comments
 (0)