11import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
2+ import { makeConfigInjectorPlugin } from '../../src/vite/makeConfigInjectorPlugin' ;
23import { makeCustomSentryVitePlugins } from '../../src/vite/makeCustomSentryVitePlugins' ;
34import { makeEnableSourceMapsPlugin } from '../../src/vite/makeEnableSourceMapsPlugin' ;
45import { sentryReactRouter } from '../../src/vite/plugin' ;
@@ -12,57 +13,61 @@ vi.spyOn(console, 'warn').mockImplementation(() => {
1213
1314vi . mock ( '../../src/vite/makeCustomSentryVitePlugins' ) ;
1415vi . mock ( '../../src/vite/makeEnableSourceMapsPlugin' ) ;
16+ vi . mock ( '../../src/vite/makeConfigInjectorPlugin' ) ;
1517
1618describe ( 'sentryReactRouter' , ( ) => {
1719 const mockPlugins = [ { name : 'test-plugin' } ] ;
1820 const mockSourceMapsPlugin = { name : 'source-maps-plugin' } ;
21+ const mockConfigInjectorPlugin = { name : 'sentry-config-injector' } ;
1922
2023 beforeEach ( ( ) => {
2124 vi . clearAllMocks ( ) ;
2225 vi . mocked ( makeCustomSentryVitePlugins ) . mockResolvedValue ( mockPlugins ) ;
2326 vi . mocked ( makeEnableSourceMapsPlugin ) . mockReturnValue ( mockSourceMapsPlugin ) ;
27+ vi . mocked ( makeConfigInjectorPlugin ) . mockReturnValue ( mockConfigInjectorPlugin ) ;
2428 } ) ;
2529
2630 afterEach ( ( ) => {
2731 vi . resetModules ( ) ;
2832 } ) ;
2933
30- it ( 'should return an empty array in development mode' , async ( ) => {
34+ it ( 'should return sentry config injector plugin in development mode' , async ( ) => {
3135 const originalNodeEnv = process . env . NODE_ENV ;
3236 process . env . NODE_ENV = 'development' ;
3337
3438 const result = await sentryReactRouter ( { } , { command : 'build' , mode : 'production' } ) ;
3539
36- expect ( result ) . toEqual ( [ ] ) ;
40+ expect ( result ) . toEqual ( [ mockConfigInjectorPlugin ] ) ;
3741 expect ( makeCustomSentryVitePlugins ) . not . toHaveBeenCalled ( ) ;
3842 expect ( makeEnableSourceMapsPlugin ) . not . toHaveBeenCalled ( ) ;
3943
4044 process . env . NODE_ENV = originalNodeEnv ;
4145 } ) ;
4246
43- it ( 'should return an empty array when not in build mode' , async ( ) => {
47+ it ( 'should return config injector plugin when not in build mode' , async ( ) => {
4448 const result = await sentryReactRouter ( { } , { command : 'serve' , mode : 'production' } ) ;
4549
46- expect ( result ) . toEqual ( [ ] ) ;
50+ expect ( result ) . toEqual ( [ mockConfigInjectorPlugin ] ) ;
4751 expect ( makeCustomSentryVitePlugins ) . not . toHaveBeenCalled ( ) ;
4852 expect ( makeEnableSourceMapsPlugin ) . not . toHaveBeenCalled ( ) ;
4953 } ) ;
5054
51- it ( 'should return an empty array when in development mode' , async ( ) => {
55+ it ( 'should return config injector plugin in development build mode' , async ( ) => {
5256 const result = await sentryReactRouter ( { } , { command : 'build' , mode : 'development' } ) ;
5357
54- expect ( result ) . toEqual ( [ ] ) ;
58+ expect ( result ) . toEqual ( [ mockConfigInjectorPlugin ] ) ;
5559 expect ( makeCustomSentryVitePlugins ) . not . toHaveBeenCalled ( ) ;
5660 expect ( makeEnableSourceMapsPlugin ) . not . toHaveBeenCalled ( ) ;
5761 } ) ;
5862
59- it ( 'should return plugins in production build mode' , async ( ) => {
63+ it ( 'should return all plugins in production build mode' , async ( ) => {
6064 const originalNodeEnv = process . env . NODE_ENV ;
6165 process . env . NODE_ENV = 'production' ;
6266
6367 const result = await sentryReactRouter ( { } , { command : 'build' , mode : 'production' } ) ;
6468
65- expect ( result ) . toEqual ( [ mockSourceMapsPlugin , ...mockPlugins ] ) ;
69+ expect ( result ) . toEqual ( [ mockConfigInjectorPlugin , mockSourceMapsPlugin , ...mockPlugins ] ) ;
70+ expect ( makeConfigInjectorPlugin ) . toHaveBeenCalledWith ( { } ) ;
6671 expect ( makeCustomSentryVitePlugins ) . toHaveBeenCalledWith ( { } ) ;
6772 expect ( makeEnableSourceMapsPlugin ) . toHaveBeenCalledWith ( { } ) ;
6873
@@ -81,6 +86,7 @@ describe('sentryReactRouter', () => {
8186
8287 await sentryReactRouter ( options , { command : 'build' , mode : 'production' } ) ;
8388
89+ expect ( makeConfigInjectorPlugin ) . toHaveBeenCalledWith ( options ) ;
8490 expect ( makeCustomSentryVitePlugins ) . toHaveBeenCalledWith ( options ) ;
8591 expect ( makeEnableSourceMapsPlugin ) . toHaveBeenCalledWith ( options ) ;
8692
0 commit comments