@@ -8,6 +8,7 @@ const { dir: getTmpDir } = require('tmp-promise')
8
8
const plugin = require ( '../src' )
9
9
10
10
const { HANDLER_FUNCTION_NAME , ODB_FUNCTION_NAME } = require ( '../src/constants' )
11
+ const { setBundler } = require ( '../src/helpers/config' )
11
12
12
13
const FIXTURES_DIR = `${ __dirname } /fixtures`
13
14
const SAMPLE_PROJECT_DIR = `${ __dirname } /../demo`
@@ -191,3 +192,84 @@ describe('onPostBuild', () => {
191
192
} )
192
193
} )
193
194
} )
195
+
196
+ describe ( 'target checking' , ( ) => {
197
+ const warn = jest . spyOn ( global . console , 'warn' )
198
+ beforeEach ( ( ) => {
199
+ warn . mockReset ( )
200
+ } )
201
+ test ( 'changes nothing if target is serverless' , ( ) => {
202
+ const netlifyConfig = {
203
+ functions : {
204
+ [ HANDLER_FUNCTION_NAME ] : {
205
+ node_bundler : 'esbuild' ,
206
+ } ,
207
+ } ,
208
+ }
209
+ setBundler ( { target : 'serverless' , netlifyConfig } )
210
+ expect ( netlifyConfig . functions [ HANDLER_FUNCTION_NAME ] . node_bundler ) . toBe ( 'esbuild' )
211
+ } )
212
+
213
+ test ( 'changes both bundlers if target is server and default is esbuild' , ( ) => {
214
+ const netlifyConfig = {
215
+ functions : {
216
+ '*' : {
217
+ node_bundler : 'esbuild' ,
218
+ } ,
219
+ } ,
220
+ }
221
+ setBundler ( { target : 'server' , netlifyConfig } )
222
+ expect ( warn ) . toHaveBeenCalledWith ( `esbuild is not supported for target=server. Setting to "zisi"` )
223
+ expect ( netlifyConfig . functions [ HANDLER_FUNCTION_NAME ] . node_bundler ) . toBe ( 'zisi' )
224
+ expect ( netlifyConfig . functions [ ODB_FUNCTION_NAME ] . node_bundler ) . toBe ( 'zisi' )
225
+ } )
226
+
227
+ test ( 'does not warn if default bundler is zisi and target is server' , ( ) => {
228
+ const netlifyConfig = {
229
+ functions : {
230
+ '*' : {
231
+ node_bundler : 'zisi' ,
232
+ } ,
233
+ } ,
234
+ }
235
+ setBundler ( { target : 'server' , netlifyConfig } )
236
+ expect ( warn ) . not . toHaveBeenCalled ( )
237
+ } )
238
+
239
+ test ( 'changes both bundlers if default is undefined and both are esbuild' , ( ) => {
240
+ const netlifyConfig = {
241
+ functions : {
242
+ '*' : { } ,
243
+ [ HANDLER_FUNCTION_NAME ] : {
244
+ node_bundler : 'esbuild' ,
245
+ } ,
246
+ [ ODB_FUNCTION_NAME ] : {
247
+ node_bundler : 'esbuild' ,
248
+ } ,
249
+ } ,
250
+ }
251
+ setBundler ( { target : 'server' , netlifyConfig } )
252
+ expect ( warn ) . toHaveBeenCalledWith ( `esbuild is not supported for target=server. Setting to "zisi"` )
253
+
254
+ expect ( netlifyConfig . functions [ HANDLER_FUNCTION_NAME ] . node_bundler ) . toBe ( 'zisi' )
255
+ expect ( netlifyConfig . functions [ ODB_FUNCTION_NAME ] . node_bundler ) . toBe ( 'zisi' )
256
+ } )
257
+
258
+ test ( 'does not warn if default is esbuild but others are both zisi' , ( ) => {
259
+ const netlifyConfig = {
260
+ functions : {
261
+ '*' : {
262
+ node_bundler : 'esbuild' ,
263
+ } ,
264
+ [ HANDLER_FUNCTION_NAME ] : {
265
+ node_bundler : 'zisi' ,
266
+ } ,
267
+ [ ODB_FUNCTION_NAME ] : {
268
+ node_bundler : 'zisi' ,
269
+ } ,
270
+ } ,
271
+ }
272
+ setBundler ( { target : 'server' , netlifyConfig } )
273
+ expect ( warn ) . not . toHaveBeenCalled ( )
274
+ } )
275
+ } )
0 commit comments