11import path from 'node:path' ;
2- import {
3- checkVersion ,
4- findPackageJson ,
5- getBridgeRouterAlias ,
6- } from '../src/utis' ;
2+ import { checkVersion , findPackageJson } from '../src/utils' ;
3+ import { getBridgeRouterAlias } from '../src/router-alias' ;
74
85const resolveRouterV5 = path . resolve (
96 __dirname ,
@@ -21,6 +18,14 @@ const resolveRouterV6_PkgPath = path.resolve(
2118 __dirname ,
2219 '../__tests__/mockRouterDir/router-v6/react-router-dom/package.json' ,
2320) ;
21+ const resolveRouterV7 = path . resolve (
22+ __dirname ,
23+ '../__tests__/mockRouterDir/router-v7/react-router' ,
24+ ) ;
25+ const resolveRouterV7_PkgPath = path . resolve (
26+ __dirname ,
27+ '../__tests__/mockRouterDir/router-v7/react-router/package.json' ,
28+ ) ;
2429
2530describe ( 'test checkVersion: should return the correct major version for react-router-dom' , ( ) => {
2631 it ( 'should return 5' , ( ) => {
@@ -42,16 +47,29 @@ describe('test checkVersion: should return the correct major version for react-r
4247 it ( 'should return 6' , ( ) => {
4348 expect ( checkVersion ( '^6.0.0' ) ) . toBe ( 6 ) ;
4449 } ) ;
50+
51+ it ( 'should return 7' , ( ) => {
52+ expect ( checkVersion ( '7.0.0' ) ) . toBe ( 7 ) ;
53+ } ) ;
54+
55+ it ( 'should return 7' , ( ) => {
56+ expect ( checkVersion ( '~7.0.0' ) ) . toBe ( 7 ) ;
57+ } ) ;
58+
59+ it ( 'should return 7' , ( ) => {
60+ expect ( checkVersion ( '^7.0.0' ) ) . toBe ( 7 ) ;
61+ } ) ;
4562} ) ;
4663
47- describe ( 'test findPackageJson: should return the correct package.json path for react-router-dom v5 and v6 ' , ( ) => {
64+ describe ( 'test findPackageJson: should return the correct package.json path for react-router-dom v5, v6 and react-router v7 ' , ( ) => {
4865 it ( 'should return the package.json path' , ( ) => {
4966 expect ( findPackageJson ( resolveRouterV5 ) ) . toBe ( resolveRouterV5_PkgPath ) ;
5067 expect ( findPackageJson ( resolveRouterV6 ) ) . toBe ( resolveRouterV6_PkgPath ) ;
68+ expect ( findPackageJson ( resolveRouterV7 ) ) . toBe ( resolveRouterV7_PkgPath ) ;
5169 } ) ;
5270} ) ;
5371
54- describe ( 'test getBridgeRouterAlias: should return the correct alias for react-router-dom v5 and v6 ' , ( ) => {
72+ describe ( 'test getBridgeRouterAlias: should return the correct alias for react-router-dom v5, v6 and react-router v7 ' , ( ) => {
5573 it ( 'should return the correct alias for router v5' , ( ) => {
5674 const res = getBridgeRouterAlias ( resolveRouterV5 ) ;
5775 expect ( res ) . toEqual ( {
@@ -66,6 +84,19 @@ describe('test getBridgeRouterAlias: should return the correct alias for react-r
6684 expect ( res ) . toEqual ( {
6785 'react-router-dom$' :
6886 '@module-federation/bridge-react/dist/router-v6.es.js' ,
87+ 'react-router-dom/dist/index.js' : resolveRouterV6 ,
88+ } ) ;
89+ } ) ;
90+
91+ it ( 'should return the correct alias for router v7' , ( ) => {
92+ const res = getBridgeRouterAlias ( resolveRouterV7 ) ;
93+ expect ( res ) . toEqual ( {
94+ 'react-router$' : '@module-federation/bridge-react/dist/router-v7.es.js' ,
95+ 'react-router-dom$' :
96+ '@module-federation/bridge-react/dist/router-v7.es.js' ,
97+ 'react-router/dist/development/index.js' : resolveRouterV7 ,
98+ 'react-router/dist/production/index.js' : resolveRouterV7 ,
99+ 'react-router-dom/dist/index.js' : resolveRouterV7 ,
69100 } ) ;
70101 } ) ;
71102} ) ;
0 commit comments