@@ -28,43 +28,134 @@ describe('onCreateWebpackConfig', () => {
2828 setWebpackConfig : jest . fn ( ) ,
2929 } ;
3030
31- const getConfig = jest . fn ( ) ;
31+ const getConfig = jest . fn ( ) . mockReturnValue ( { devtool : 'source-map' } ) ;
3232
3333 onCreateWebpackConfig ( { actions, getConfig } , { } ) ;
3434
3535 expect ( actions . setWebpackConfig ) . toHaveBeenCalledTimes ( 1 ) ;
36- expect ( actions . setWebpackConfig ) . toHaveBeenLastCalledWith ( { plugins : expect . any ( Array ) } ) ;
36+ expect ( actions . setWebpackConfig ) . toHaveBeenLastCalledWith ( { devtool : 'source-map' , plugins : expect . any ( Array ) } ) ;
3737 } ) ;
3838
3939 it ( 'does not set a webpack config if enableClientWebpackPlugin is false' , ( ) => {
4040 const actions = {
4141 setWebpackConfig : jest . fn ( ) ,
4242 } ;
4343
44- const getConfig = jest . fn ( ) ;
44+ const getConfig = jest . fn ( ) . mockReturnValue ( { devtool : 'source-map' } ) ;
4545
4646 onCreateWebpackConfig ( { actions, getConfig } , { enableClientWebpackPlugin : false } ) ;
4747
4848 expect ( actions . setWebpackConfig ) . toHaveBeenCalledTimes ( 0 ) ;
4949 } ) ;
5050
51- it ( 'sets sourceMapFilesToDeleteAfterUpload when provided in options' , ( ) => {
51+ describe ( 'delete source maps after upload' , ( ) => {
52+ beforeEach ( ( ) => {
53+ jest . clearAllMocks ( ) ;
54+ } ) ;
55+
5256 const actions = {
5357 setWebpackConfig : jest . fn ( ) ,
5458 } ;
5559
5660 const getConfig = jest . fn ( ) ;
5761
58- onCreateWebpackConfig ( { actions, getConfig } , { deleteSourcemapsAfterUpload : true } ) ;
62+ it ( 'sets sourceMapFilesToDeleteAfterUpload when provided in options' , ( ) => {
63+ const actions = {
64+ setWebpackConfig : jest . fn ( ) ,
65+ } ;
5966
60- expect ( actions . setWebpackConfig ) . toHaveBeenCalledTimes ( 1 ) ;
67+ const getConfig = jest . fn ( ) . mockReturnValue ( { devtool : 'source-map' } ) ;
6168
62- expect ( sentryWebpackPlugin ) . toHaveBeenCalledWith (
63- expect . objectContaining ( {
64- sourcemaps : expect . objectContaining ( {
65- filesToDeleteAfterUpload : [ './public/**/*.map' ] ,
69+ onCreateWebpackConfig ( { actions, getConfig } , { deleteSourcemapsAfterUpload : true } ) ;
70+
71+ expect ( actions . setWebpackConfig ) . toHaveBeenCalledTimes ( 1 ) ;
72+
73+ expect ( sentryWebpackPlugin ) . toHaveBeenCalledWith (
74+ expect . objectContaining ( {
75+ sourcemaps : expect . objectContaining ( {
76+ filesToDeleteAfterUpload : [ './public/**/*.map' ] ,
77+ } ) ,
78+ } ) ,
79+ ) ;
80+ } ) ;
81+
82+ test . each ( [
83+ {
84+ name : 'without provided options: sets hidden source maps and deletes source maps' ,
85+ initialConfig : undefined ,
86+ options : { } ,
87+ expected : {
88+ devtool : 'hidden-source-map' ,
89+ deleteSourceMaps : true ,
90+ } ,
91+ } ,
92+ {
93+ name : "preserves enabled source-map and doesn't delete" ,
94+ initialConfig : { devtool : 'source-map' } ,
95+ options : { } ,
96+ expected : {
97+ devtool : 'source-map' ,
98+ deleteSourceMaps : false ,
99+ } ,
100+ } ,
101+ {
102+ name : "preserves enabled hidden-source-map and doesn't delete" ,
103+ initialConfig : { devtool : 'hidden-source-map' } ,
104+ options : { } ,
105+ expected : {
106+ devtool : 'hidden-source-map' ,
107+ deleteSourceMaps : false ,
108+ } ,
109+ } ,
110+ {
111+ name : 'deletes source maps, when user explicitly sets it' ,
112+ initialConfig : { devtool : 'eval' } ,
113+ options : { } ,
114+ expected : {
115+ devtool : 'hidden-source-map' ,
116+ deleteSourceMaps : true ,
117+ } ,
118+ } ,
119+ {
120+ name : 'explicit deleteSourcemapsAfterUpload true' ,
121+ initialConfig : { devtool : 'source-map' } ,
122+ options : { deleteSourcemapsAfterUpload : true } ,
123+ expected : {
124+ devtool : 'source-map' ,
125+ deleteSourceMaps : true ,
126+ } ,
127+ } ,
128+ {
129+ name : 'explicit deleteSourcemapsAfterUpload false' ,
130+ initialConfig : { devtool : 'hidden-source-map' } ,
131+ options : { deleteSourcemapsAfterUpload : false } ,
132+ expected : {
133+ devtool : 'hidden-source-map' ,
134+ deleteSourceMaps : false ,
135+ } ,
136+ } ,
137+ ] ) ( '$name' , ( { initialConfig, options, expected } ) => {
138+ getConfig . mockReturnValue ( initialConfig ) ;
139+
140+ onCreateWebpackConfig ( { actions : actions , getConfig : getConfig } , options ) ;
141+
142+ expect ( actions . setWebpackConfig ) . toHaveBeenCalledTimes ( 1 ) ;
143+
144+ expect ( actions . setWebpackConfig ) . toHaveBeenCalledWith (
145+ expect . objectContaining ( {
146+ devtool : expected . devtool ,
147+ plugins : expect . arrayContaining ( [ expect . any ( Object ) ] ) ,
148+ } ) ,
149+ ) ;
150+
151+ expect ( sentryWebpackPlugin ) . toHaveBeenCalledWith (
152+ expect . objectContaining ( {
153+ sourcemaps : expect . objectContaining ( {
154+ assets : [ './public/**' ] ,
155+ filesToDeleteAfterUpload : expected . deleteSourceMaps ? [ './public/**/*.map' ] : undefined ,
156+ } ) ,
66157 } ) ,
67- } ) ,
68- ) ;
158+ ) ;
159+ } ) ;
69160 } ) ;
70161} ) ;
0 commit comments