@@ -215,4 +215,83 @@ describe('buildFunctionExtension', () => {
215215 ) . rejects . toThrow ( AbortError )
216216 expect ( releaseLock ) . not . toHaveBeenCalled ( )
217217 } )
218+
219+ test ( 'handles function with undefined build config' , async ( ) => {
220+ // Given
221+ const configWithoutBuild = {
222+ name : 'MyFunction' ,
223+ type : 'product_discounts' ,
224+ description : '' ,
225+ configuration_ui : true ,
226+ api_version : '2022-07' ,
227+ metafields : [ ] ,
228+ } as unknown as FunctionConfigType
229+
230+ extension = await testFunctionExtension ( { config : configWithoutBuild , entryPath : 'src/index.js' } )
231+ vi . mocked ( fileExistsSync ) . mockResolvedValue ( true )
232+
233+ // When
234+ await expect (
235+ buildFunctionExtension ( extension , {
236+ stdout,
237+ stderr,
238+ signal,
239+ app,
240+ environment : 'production' ,
241+ } ) ,
242+ ) . resolves . toBeUndefined ( )
243+
244+ // Then
245+ expect ( buildJSFunction ) . toHaveBeenCalledWith ( extension , {
246+ stdout,
247+ stderr,
248+ signal,
249+ app,
250+ environment : 'production' ,
251+ } )
252+ expect ( releaseLock ) . toHaveBeenCalled ( )
253+ // wasm_opt should not be called when build config is undefined
254+ expect ( runWasmOpt ) . not . toHaveBeenCalled ( )
255+ } )
256+
257+ test ( 'handles function with build config but undefined path' , async ( ) => {
258+ // Given
259+ const configWithoutPath = {
260+ name : 'MyFunction' ,
261+ type : 'product_discounts' ,
262+ description : '' ,
263+ build : {
264+ command : 'make build' ,
265+ wasm_opt : true ,
266+ // path is undefined
267+ } ,
268+ configuration_ui : true ,
269+ api_version : '2022-07' ,
270+ metafields : [ ] ,
271+ } as unknown as FunctionConfigType
272+
273+ extension = await testFunctionExtension ( { config : configWithoutPath } )
274+ vi . mocked ( fileExistsSync ) . mockResolvedValue ( true )
275+
276+ // When
277+ await expect (
278+ buildFunctionExtension ( extension , {
279+ stdout,
280+ stderr,
281+ signal,
282+ app,
283+ environment : 'production' ,
284+ } ) ,
285+ ) . resolves . toBeUndefined ( )
286+
287+ // Then
288+ expect ( exec ) . toHaveBeenCalledWith ( 'make' , [ 'build' ] , {
289+ stdout,
290+ stderr,
291+ cwd : extension . directory ,
292+ signal,
293+ } )
294+ expect ( releaseLock ) . toHaveBeenCalled ( )
295+ expect ( runWasmOpt ) . toHaveBeenCalled ( )
296+ } )
218297} )
0 commit comments