11import type { Plugin } from 'vite' ;
2- import { beforeEach , describe , expect , it , vi } from 'vitest' ;
2+ import { afterAll , beforeEach , describe , expect , it , vi } from 'vitest' ;
33import { getLoadShareImportId } from '../virtualModules/virtualShared_preBuild' ;
44
55const { hasPackageDependencyMock, mfWarn } = vi . hoisted ( ( ) => ( {
@@ -99,6 +99,37 @@ function getModuleFederationVitePlugin(): Plugin {
9999 return plugin ;
100100}
101101
102+ describe ( 'federation in test environment' , ( ) => {
103+ const originalEnv = process . env ;
104+
105+ beforeEach ( ( ) => {
106+ process . env = { } ;
107+ } ) ;
108+
109+ afterAll ( ( ) => {
110+ process . env = originalEnv ;
111+ } ) ;
112+
113+ it ( 'returns empty plugin array when in test environment' , ( ) => {
114+ process . env . NODE_ENV = 'test' ;
115+ const plugins = federation ( {
116+ name : 'host' ,
117+ filename : 'remoteEntry.js' ,
118+ } ) ;
119+ expect ( plugins ) . toEqual ( [ ] ) ;
120+ } ) ;
121+
122+ it ( 'returns plugins when MFE_VITE_NO_TEST_ENV_CHECK is true' , ( ) => {
123+ process . env . NODE_ENV = 'test' ;
124+ process . env . MFE_VITE_NO_TEST_ENV_CHECK = 'true' ;
125+ const plugins = federation ( {
126+ name : 'host' ,
127+ filename : 'remoteEntry.js' ,
128+ } ) ;
129+ expect ( plugins . length ) . toBeGreaterThan ( 0 ) ;
130+ } ) ;
131+ } ) ;
132+
102133describe ( 'module-federation-esm-shims' , ( ) => {
103134 beforeEach ( ( ) => {
104135 vi . clearAllMocks ( ) ;
@@ -213,7 +244,10 @@ describe('vite:module-federation-early-init', () => {
213244 } ;
214245
215246 const configHook = typeof plugin . config === 'function' ? plugin . config : plugin . config ?. handler ;
216- configHook ?. call ( { meta : { } } as any , config , { command : 'serve' , mode : 'test' } ) ;
247+ configHook ?. call ( { meta : { } } as any , config , {
248+ command : 'serve' ,
249+ mode : 'test' ,
250+ } ) ;
217251
218252 expect ( config . optimizeDeps . include ) . toContain ( getPreBuildLibImportId ( 'vue' ) ) ;
219253 expect ( config . optimizeDeps . include ) . toContain ( getLoadShareImportId ( 'vue' , false , 'serve' ) ) ;
@@ -253,7 +287,10 @@ describe('vite:module-federation-early-init', () => {
253287 } ;
254288
255289 const configHook = typeof plugin . config === 'function' ? plugin . config : plugin . config ?. handler ;
256- configHook ?. call ( { meta : { } } as any , config , { command : 'build' , mode : 'test' } ) ;
290+ configHook ?. call ( { meta : { } } as any , config , {
291+ command : 'build' ,
292+ mode : 'test' ,
293+ } ) ;
257294
258295 expect ( config . define . ENV_TARGET ) . toBe ( 'undefined' ) ;
259296 } ) ;
@@ -273,7 +310,10 @@ describe('vite:module-federation-early-init', () => {
273310 } ;
274311
275312 const configHook = typeof plugin . config === 'function' ? plugin . config : plugin . config ?. handler ;
276- configHook ?. call ( { meta : { } } as any , config , { command : 'build' , mode : 'test' } ) ;
313+ configHook ?. call ( { meta : { } } as any , config , {
314+ command : 'build' ,
315+ mode : 'test' ,
316+ } ) ;
277317
278318 expect ( config . define . ENV_TARGET ) . toBe ( '"node"' ) ;
279319 } ) ;
@@ -304,7 +344,10 @@ describe('vite:module-federation-early-init with import: false', () => {
304344 } ;
305345
306346 const configHook = typeof plugin . config === 'function' ? plugin . config : plugin . config ?. handler ;
307- configHook ?. call ( { meta : { } } as any , config , { command : 'serve' , mode : 'test' } ) ;
347+ configHook ?. call ( { meta : { } } as any , config , {
348+ command : 'serve' ,
349+ mode : 'test' ,
350+ } ) ;
308351
309352 // Should not include prebuild or loadShare for import: false deps
310353 const includeStr = config . optimizeDeps . include . join ( ',' ) ;
0 commit comments