1
1
import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
2
+ import { makeConfigInjectorPlugin } from '../../src/vite/makeConfigInjectorPlugin' ;
2
3
import { makeCustomSentryVitePlugins } from '../../src/vite/makeCustomSentryVitePlugins' ;
3
4
import { makeEnableSourceMapsPlugin } from '../../src/vite/makeEnableSourceMapsPlugin' ;
4
5
import { sentryReactRouter } from '../../src/vite/plugin' ;
@@ -12,57 +13,61 @@ vi.spyOn(console, 'warn').mockImplementation(() => {
12
13
13
14
vi . mock ( '../../src/vite/makeCustomSentryVitePlugins' ) ;
14
15
vi . mock ( '../../src/vite/makeEnableSourceMapsPlugin' ) ;
16
+ vi . mock ( '../../src/vite/makeConfigInjectorPlugin' ) ;
15
17
16
18
describe ( 'sentryReactRouter' , ( ) => {
17
19
const mockPlugins = [ { name : 'test-plugin' } ] ;
18
20
const mockSourceMapsPlugin = { name : 'source-maps-plugin' } ;
21
+ const mockConfigInjectorPlugin = { name : 'sentry-config-injector' } ;
19
22
20
23
beforeEach ( ( ) => {
21
24
vi . clearAllMocks ( ) ;
22
25
vi . mocked ( makeCustomSentryVitePlugins ) . mockResolvedValue ( mockPlugins ) ;
23
26
vi . mocked ( makeEnableSourceMapsPlugin ) . mockReturnValue ( mockSourceMapsPlugin ) ;
27
+ vi . mocked ( makeConfigInjectorPlugin ) . mockReturnValue ( mockConfigInjectorPlugin ) ;
24
28
} ) ;
25
29
26
30
afterEach ( ( ) => {
27
31
vi . resetModules ( ) ;
28
32
} ) ;
29
33
30
- it ( 'should return an empty array in development mode' , async ( ) => {
34
+ it ( 'should return sentry config injector plugin in development mode' , async ( ) => {
31
35
const originalNodeEnv = process . env . NODE_ENV ;
32
36
process . env . NODE_ENV = 'development' ;
33
37
34
38
const result = await sentryReactRouter ( { } , { command : 'build' , mode : 'production' } ) ;
35
39
36
- expect ( result ) . toEqual ( [ ] ) ;
40
+ expect ( result ) . toEqual ( [ mockConfigInjectorPlugin ] ) ;
37
41
expect ( makeCustomSentryVitePlugins ) . not . toHaveBeenCalled ( ) ;
38
42
expect ( makeEnableSourceMapsPlugin ) . not . toHaveBeenCalled ( ) ;
39
43
40
44
process . env . NODE_ENV = originalNodeEnv ;
41
45
} ) ;
42
46
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 ( ) => {
44
48
const result = await sentryReactRouter ( { } , { command : 'serve' , mode : 'production' } ) ;
45
49
46
- expect ( result ) . toEqual ( [ ] ) ;
50
+ expect ( result ) . toEqual ( [ mockConfigInjectorPlugin ] ) ;
47
51
expect ( makeCustomSentryVitePlugins ) . not . toHaveBeenCalled ( ) ;
48
52
expect ( makeEnableSourceMapsPlugin ) . not . toHaveBeenCalled ( ) ;
49
53
} ) ;
50
54
51
- it ( 'should return an empty array when in development mode' , async ( ) => {
55
+ it ( 'should return config injector plugin in development build mode' , async ( ) => {
52
56
const result = await sentryReactRouter ( { } , { command : 'build' , mode : 'development' } ) ;
53
57
54
- expect ( result ) . toEqual ( [ ] ) ;
58
+ expect ( result ) . toEqual ( [ mockConfigInjectorPlugin ] ) ;
55
59
expect ( makeCustomSentryVitePlugins ) . not . toHaveBeenCalled ( ) ;
56
60
expect ( makeEnableSourceMapsPlugin ) . not . toHaveBeenCalled ( ) ;
57
61
} ) ;
58
62
59
- it ( 'should return plugins in production build mode' , async ( ) => {
63
+ it ( 'should return all plugins in production build mode' , async ( ) => {
60
64
const originalNodeEnv = process . env . NODE_ENV ;
61
65
process . env . NODE_ENV = 'production' ;
62
66
63
67
const result = await sentryReactRouter ( { } , { command : 'build' , mode : 'production' } ) ;
64
68
65
- expect ( result ) . toEqual ( [ mockSourceMapsPlugin , ...mockPlugins ] ) ;
69
+ expect ( result ) . toEqual ( [ mockConfigInjectorPlugin , mockSourceMapsPlugin , ...mockPlugins ] ) ;
70
+ expect ( makeConfigInjectorPlugin ) . toHaveBeenCalledWith ( { } ) ;
66
71
expect ( makeCustomSentryVitePlugins ) . toHaveBeenCalledWith ( { } ) ;
67
72
expect ( makeEnableSourceMapsPlugin ) . toHaveBeenCalledWith ( { } ) ;
68
73
@@ -81,6 +86,7 @@ describe('sentryReactRouter', () => {
81
86
82
87
await sentryReactRouter ( options , { command : 'build' , mode : 'production' } ) ;
83
88
89
+ expect ( makeConfigInjectorPlugin ) . toHaveBeenCalledWith ( options ) ;
84
90
expect ( makeCustomSentryVitePlugins ) . toHaveBeenCalledWith ( options ) ;
85
91
expect ( makeEnableSourceMapsPlugin ) . toHaveBeenCalledWith ( options ) ;
86
92
0 commit comments