@@ -3,7 +3,12 @@ import { assert, describe, it } from 'vitest';
3
3
import { FederationHost , init } from '../src/index' ;
4
4
import { mockRemoteSnapshot } from './mock/utils' ;
5
5
import { matchRemoteWithNameAndExpose } from '../src/utils/manifest' ;
6
- import { addGlobalSnapshot , getGlobalSnapshot , Global } from '../src/global' ;
6
+ import {
7
+ addGlobalSnapshot ,
8
+ getGlobalSnapshot ,
9
+ Global ,
10
+ setGlobalFederationConstructor ,
11
+ } from '../src/global' ;
7
12
import { requestList } from './mock/env' ;
8
13
9
14
describe ( 'matchRemote' , ( ) => {
@@ -395,7 +400,7 @@ describe('loadRemote with manifest.json', () => {
395
400
} ) ;
396
401
397
402
it ( 'circulate deps' , async ( ) => {
398
- globalThis . __FEDERATION__ . __DEBUG_CONSTRUCTOR__ = FederationHost ;
403
+ setGlobalFederationConstructor ( FederationHost , true ) ;
399
404
const FM = init ( {
400
405
name : '@circulate-deps/app1' ,
401
406
remotes : [
@@ -415,7 +420,7 @@ describe('loadRemote with manifest.json', () => {
415
420
expect ( res ) . toBe ( '@circulate-deps/app2' ) ;
416
421
417
422
Global . __FEDERATION__ . __INSTANCES__ = [ ] ;
418
- globalThis . __FEDERATION__ . __DEBUG_CONSTRUCTOR__ = undefined ;
423
+ setGlobalFederationConstructor ( undefined , true ) ;
419
424
} ) ;
420
425
421
426
it ( 'manifest.json with query' , async ( ) => {
@@ -479,6 +484,10 @@ describe('lazy loadRemote add remote into snapshot', () => {
479
484
} ) ;
480
485
const snapshot = getGlobalSnapshot ( ) ;
481
486
const hostModuleInfo = snapshot [ '@demo/app1' ] ;
487
+ assert (
488
+ hostModuleInfo && 'remotesInfo' in hostModuleInfo ,
489
+ 'hostModuleInfo Cannot be empty' ,
490
+ ) ;
482
491
const beforeHostRemotesInfo = hostModuleInfo . remotesInfo ;
483
492
const beforeRemotesLength = Object . keys ( beforeHostRemotesInfo ) . length ;
484
493
expect ( beforeRemotesLength ) . toBe ( 0 ) ;
@@ -519,6 +528,10 @@ describe('lazy loadRemote add remote into snapshot', () => {
519
528
} ) ;
520
529
const snapshot = getGlobalSnapshot ( ) ;
521
530
const hostModuleInfo = snapshot [ '@demo/app1' ] ;
531
+ assert (
532
+ hostModuleInfo && 'remotesInfo' in hostModuleInfo ,
533
+ 'hostModuleInfo Cannot be empty' ,
534
+ ) ;
522
535
const beforeHostRemotesInfo = hostModuleInfo . remotesInfo ;
523
536
const beforeRemotesLength = Object . keys ( beforeHostRemotesInfo ) . length ;
524
537
expect ( beforeRemotesLength ) . toBe ( 0 ) ;
@@ -595,7 +608,7 @@ describe('loadRemote', () => {
595
608
) ;
596
609
// @ts -ignore fakeSrc is local mock attr, which value is the same as src
597
610
const loadedSrcs = [ ...document . querySelectorAll ( 'script' ) ] . map (
598
- ( i ) => i . fakeSrc ,
611
+ ( i ) => ( i as any ) . fakeSrc ,
599
612
) ;
600
613
expect ( loadedSrcs . includes ( `${ remotePublicPath } ${ jsSyncAssetPath } ` ) ) ;
601
614
reset ( ) ;
0 commit comments