@@ -600,17 +600,20 @@ describe('loadRemote', () => {
600
600
const loadedSrcs = [ ...document . querySelectorAll ( 'script' ) ] . map (
601
601
( i ) => ( i as any ) . fakeSrc ,
602
602
) ;
603
+ const loadedStyles = [ ...document . querySelectorAll ( 'link' ) ] . map (
604
+ ( link ) => link . href ,
605
+ ) ;
603
606
expect ( loadedSrcs . includes ( `${ remotePublicPath } ${ jsSyncAssetPath } ` ) ) ;
607
+ expect ( loadedStyles . includes ( `${ remotePublicPath } sub2/say.sync.css` ) ) ;
608
+
604
609
reset ( ) ;
605
610
} ) ;
606
611
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' ;
611
614
const remotePublicPath = 'http://localhost:1111/' ;
612
615
const reset = addGlobalSnapshot ( {
613
- '@federation-test/shadow-css ' : {
616
+ '@federation-test/globalinfo ' : {
614
617
globalName : '' ,
615
618
buildVersion : '' ,
616
619
publicPath : '' ,
@@ -639,11 +642,11 @@ describe('loadRemote', () => {
639
642
moduleName : 'say' ,
640
643
assets : {
641
644
css : {
642
- sync : [ cssSyncPath ] ,
643
- async : [ cssAsyncPath ] ,
645
+ sync : [ 'sub2/say.sync.css' ] ,
646
+ async : [ 'sub2/say.async.css' ] ,
644
647
} ,
645
648
js : {
646
- sync : [ 'resources/load-remote/app2/say.sync.js' ] ,
649
+ sync : [ jsSyncAssetPath ] ,
647
650
async : [ ] ,
648
651
} ,
649
652
} ,
@@ -655,7 +658,7 @@ describe('loadRemote', () => {
655
658
} ) ;
656
659
657
660
const FederationInstance = new FederationHost ( {
658
- name : '@federation-test/shadow-css ' ,
661
+ name : '@federation-test/globalinfo ' ,
659
662
remotes : [
660
663
{
661
664
name : '@federation-test/app2' ,
@@ -664,32 +667,24 @@ describe('loadRemote', () => {
664
667
] ,
665
668
} ) ;
666
669
670
+ const root = document . createElement ( 'div' ) ;
667
671
await FederationInstance . loadRemote < ( ) => string > (
668
672
'@federation-test/app2/say' ,
669
- { root : shadowRoot } ,
673
+ { root } ,
670
674
) ;
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 ,
685
678
) ;
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 ,
691
681
) ;
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 ( [ ] ) ;
693
688
694
689
reset ( ) ;
695
690
} ) ;
0 commit comments