@@ -14,6 +14,10 @@ const resolveRouterV6 = path.resolve(
1414 __dirname ,
1515 '../__tests__/mockRouterDir/router-v6/react-router-dom/dist/main.js' ,
1616) ;
17+ const resolveRouterV6Core = path . resolve (
18+ __dirname ,
19+ '../__tests__/mockRouterDir/router-v6/react-router' ,
20+ ) ;
1721const resolveRouterV6_PkgPath = path . resolve (
1822 __dirname ,
1923 '../__tests__/mockRouterDir/router-v6/react-router-dom/package.json' ,
@@ -26,6 +30,18 @@ const resolveRouterV7_PkgPath = path.resolve(
2630 __dirname ,
2731 '../__tests__/mockRouterDir/router-v7/react-router/package.json' ,
2832) ;
33+ const resolveRouterV8 = path . resolve (
34+ __dirname ,
35+ '../__tests__/mockRouterDir/router-v8/react-router' ,
36+ ) ;
37+ const resolveRouterV8Entry = path . join (
38+ resolveRouterV8 ,
39+ 'dist/production/index.js' ,
40+ ) ;
41+ const resolveRouterV8_PkgPath = path . resolve (
42+ __dirname ,
43+ '../__tests__/mockRouterDir/router-v8/react-router/package.json' ,
44+ ) ;
2945
3046describe ( 'test checkVersion: should return the correct major version for react-router-dom' , ( ) => {
3147 it ( 'should return 5' , ( ) => {
@@ -59,17 +75,26 @@ describe('test checkVersion: should return the correct major version for react-r
5975 it ( 'should return 7' , ( ) => {
6076 expect ( checkVersion ( '^7.0.0' ) ) . toBe ( 7 ) ;
6177 } ) ;
78+
79+ it ( 'should return 8' , ( ) => {
80+ expect ( checkVersion ( '8.0.0' ) ) . toBe ( 8 ) ;
81+ } ) ;
82+
83+ it ( 'should return 8' , ( ) => {
84+ expect ( checkVersion ( '^8.0.0' ) ) . toBe ( 8 ) ;
85+ } ) ;
6286} ) ;
6387
64- describe ( 'test findPackageJson: should return the correct package.json path for react-router-dom v5, v6 and react-router v7' , ( ) => {
88+ describe ( 'test findPackageJson: should return the correct package.json path for react-router-dom v5/ v6 and react-router v7/v8 ' , ( ) => {
6589 it ( 'should return the package.json path' , ( ) => {
6690 expect ( findPackageJson ( resolveRouterV5 ) ) . toBe ( resolveRouterV5_PkgPath ) ;
6791 expect ( findPackageJson ( resolveRouterV6 ) ) . toBe ( resolveRouterV6_PkgPath ) ;
6892 expect ( findPackageJson ( resolveRouterV7 ) ) . toBe ( resolveRouterV7_PkgPath ) ;
93+ expect ( findPackageJson ( resolveRouterV8 ) ) . toBe ( resolveRouterV8_PkgPath ) ;
6994 } ) ;
7095} ) ;
7196
72- describe ( 'test getBridgeRouterAlias: should return the correct alias for react-router-dom v5, v6 and react-router v7' , ( ) => {
97+ describe ( 'test getBridgeRouterAlias: should return the correct alias for react-router-dom v5/ v6 and react-router v7/v8 ' , ( ) => {
7398 it ( 'should return the correct alias for router v5' , ( ) => {
7499 const res = getBridgeRouterAlias ( resolveRouterV5 ) ;
75100 expect ( res ) . toEqual ( {
@@ -99,4 +124,69 @@ describe('test getBridgeRouterAlias: should return the correct alias for react-r
99124 'react-router-dom/dist/index.js' : resolveRouterV7 ,
100125 } ) ;
101126 } ) ;
127+
128+ it ( 'should return the correct alias for router v8' , ( ) => {
129+ const res = getBridgeRouterAlias ( resolveRouterV8 ) ;
130+ expect ( res ) . toEqual ( {
131+ 'react-router$' : '@module-federation/bridge-react/dist/router-v8.es.js' ,
132+ 'react-router/dom$' :
133+ '@module-federation/bridge-react/dist/router-v8-dom.es.js' ,
134+ 'react-router/dist/development/index.js' : resolveRouterV8 ,
135+ 'react-router/dist/production/index.js' : resolveRouterV8 ,
136+ 'react-router/dist/development/dom-export.js' : path . join (
137+ resolveRouterV8 ,
138+ 'dist/development/dom-export.js' ,
139+ ) ,
140+ 'react-router/dist/production/dom-export.js' : path . join (
141+ resolveRouterV8 ,
142+ 'dist/production/dom-export.js' ,
143+ ) ,
144+ } ) ;
145+ } ) ;
146+
147+ it ( 'should prefer an explicit react-router alias for router v8' , ( ) => {
148+ const res = getBridgeRouterAlias ( { reactRouterAlias : resolveRouterV8 } ) ;
149+ expect ( res [ 'react-router$' ] ) . toBe (
150+ '@module-federation/bridge-react/dist/router-v8.es.js' ,
151+ ) ;
152+ expect ( res [ 'react-router/dom$' ] ) . toBe (
153+ '@module-federation/bridge-react/dist/router-v8-dom.es.js' ,
154+ ) ;
155+ } ) ;
156+
157+ it ( 'should normalize an explicit react-router entry alias for router v8' , ( ) => {
158+ const res = getBridgeRouterAlias ( {
159+ reactRouterAlias : resolveRouterV8Entry ,
160+ } ) ;
161+
162+ expect ( res [ 'react-router/dist/production/index.js' ] ) . toBe ( resolveRouterV8 ) ;
163+ expect ( res [ 'react-router/dist/production/dom-export.js' ] ) . toBe (
164+ path . join ( resolveRouterV8 , 'dist/production/dom-export.js' ) ,
165+ ) ;
166+ } ) ;
167+
168+ it ( 'should prefer an explicit react-router-dom alias for router v6 when both aliases exist' , ( ) => {
169+ const res = getBridgeRouterAlias ( {
170+ reactRouterAlias : resolveRouterV6Core ,
171+ reactRouterDomAlias : resolveRouterV6 ,
172+ } ) ;
173+
174+ expect ( res ) . toEqual ( {
175+ 'react-router-dom$' :
176+ '@module-federation/bridge-react/dist/router-v6.es.js' ,
177+ 'react-router-dom/dist/index.js' : resolveRouterV6 ,
178+ } ) ;
179+ } ) ;
180+
181+ it ( 'should prefer an explicit react-router alias for router v7 when both aliases exist' , ( ) => {
182+ const res = getBridgeRouterAlias ( {
183+ reactRouterAlias : resolveRouterV7 ,
184+ reactRouterDomAlias : resolveRouterV6 ,
185+ } ) ;
186+
187+ expect ( res [ 'react-router$' ] ) . toBe (
188+ '@module-federation/bridge-react/dist/router-v7.es.js' ,
189+ ) ;
190+ expect ( res [ 'react-router-dom/dist/index.js' ] ) . toBe ( resolveRouterV7 ) ;
191+ } ) ;
102192} ) ;
0 commit comments