11import { buildFunctionExtension } from './extension.js'
22import { testFunctionExtension } from '../../models/app/app.test-data.js'
3- import { buildJSFunction } from '../function/build.js'
3+ import { buildJSFunction , runWasmOpt } from '../function/build.js'
44import { ExtensionInstance } from '../../models/extensions/extension-instance.js'
55import { FunctionConfigType } from '../../models/extensions/specifications/function.js'
66import { beforeEach , describe , expect , test , vi } from 'vitest'
77import { exec } from '@shopify/cli-kit/node/system'
88import lockfile from 'proper-lockfile'
99import { AbortError } from '@shopify/cli-kit/node/error'
10+ import { fileExistsSync } from '@shopify/cli-kit/node/fs'
1011
1112vi . mock ( '@shopify/cli-kit/node/system' )
1213vi . mock ( '../function/build.js' )
1314vi . mock ( 'proper-lockfile' )
15+ vi . mock ( '@shopify/cli-kit/node/fs' )
1416
1517describe ( 'buildFunctionExtension' , ( ) => {
1618 let extension : ExtensionInstance < FunctionConfigType >
@@ -26,6 +28,7 @@ describe('buildFunctionExtension', () => {
2628 build : {
2729 command : 'make build' ,
2830 path : 'dist/index.wasm' ,
31+ wasm_opt : true ,
2932 } ,
3033 configuration_ui : true ,
3134 api_version : '2022-07' ,
@@ -138,6 +141,45 @@ describe('buildFunctionExtension', () => {
138141 expect ( releaseLock ) . toHaveBeenCalled ( )
139142 } )
140143
144+ test ( 'performs wasm-opt execution by default' , async ( ) => {
145+ // Given
146+ vi . mocked ( fileExistsSync ) . mockResolvedValue ( true )
147+
148+ // When
149+ await expect (
150+ buildFunctionExtension ( extension , {
151+ stdout,
152+ stderr,
153+ signal,
154+ app,
155+ environment : 'production' ,
156+ } ) ,
157+ ) . resolves . toBeUndefined ( )
158+
159+ // Then
160+ expect ( runWasmOpt ) . toHaveBeenCalled ( )
161+ } )
162+
163+ test ( 'skips wasm-opt execution when the disable-wasm-opt is true' , async ( ) => {
164+ // Given
165+ vi . mocked ( fileExistsSync ) . mockResolvedValue ( true )
166+ extension . configuration . build . wasm_opt = false
167+
168+ // When
169+ await expect (
170+ buildFunctionExtension ( extension , {
171+ stdout,
172+ stderr,
173+ signal,
174+ app,
175+ environment : 'production' ,
176+ } ) ,
177+ ) . resolves . toBeUndefined ( )
178+
179+ // Then
180+ expect ( runWasmOpt ) . not . toHaveBeenCalled ( )
181+ } )
182+
141183 test ( 'fails when build lock cannot be acquired' , async ( ) => {
142184 // Given
143185 vi . mocked ( lockfile . lock ) . mockRejectedValue ( 'failed to acquire lock' )
0 commit comments