@@ -133,7 +133,7 @@ suite("Config Functions", () => {
133133 expect ( result . buildType ) . toBe ( "Release" )
134134 } )
135135
136- test ( "should handle cross compilation flags " , async ( ) => {
136+ test ( "should detect os cross compilation" , async ( ) => {
137137 const partialConfig : Partial < BuildConfiguration > = {
138138 os : process . platform === "win32" ? "linux" : "win32" ,
139139 arch : "x64" ,
@@ -142,6 +142,7 @@ suite("Config Functions", () => {
142142 const result = await getBuildConfig ( mockBuildOptions , partialConfig , mockConfigFile )
143143
144144 expect ( result . cross ) . toBe ( true )
145+ expect ( result . os ) . toBe ( process . platform === "win32" ? "linux" : "win32" )
145146 } )
146147
147148 test ( "should respect npm_config_target_arch when it matches config.arch" , async ( ) => {
@@ -195,7 +196,7 @@ suite("Config Functions", () => {
195196 vi . restoreAllMocks ( )
196197 } )
197198
198- test ( "should respect npm_config_target_arch when it differs from process.arch" , async ( ) => {
199+ test ( "should respect config.arch when it differs from process.arch even if npm_config_target_arch is set " , async ( ) => {
199200 // Set npm_config_target_arch to a different architecture than the current one
200201 process . env . npm_config_target_arch = process . arch === "x64" ? "arm64" : "x64"
201202
@@ -206,7 +207,29 @@ suite("Config Functions", () => {
206207
207208 const result = await getBuildConfig ( mockBuildOptions , partialConfig , mockConfigFile )
208209
210+ expect ( result . cross ) . toBe ( false )
211+ expect ( result . arch ) . toBe ( process . arch )
212+ } )
213+
214+ test ( "should respect npm_config_target_arch when it differs from process.arch with default config" , async ( ) => {
215+ // Set npm_config_target_arch to a different architecture than the current one
216+ process . env . npm_config_target_arch = process . arch === "x64" ? "arm64" : "x64"
217+
218+ const result = await getBuildConfig ( mockBuildOptions , { } , mockConfigFile )
219+
220+ expect ( result . cross ) . toBe ( true )
221+ expect ( result . arch ) . toBe ( process . env . npm_config_target_arch )
222+ expect ( result . os ) . toBe ( process . platform )
223+ } )
224+
225+ test ( "should respect npm_config_target_os when it differs from process.platform with default config" , async ( ) => {
226+ // Set npm_config_target_os to a different platform than the current one
227+ process . env . npm_config_target_os = process . platform === "win32" ? "linux" : "win32"
228+
229+ const result = await getBuildConfig ( mockBuildOptions , { } , mockConfigFile )
230+
209231 expect ( result . cross ) . toBe ( true )
232+ expect ( result . os ) . toBe ( process . env . npm_config_target_os )
210233 expect ( result . arch ) . toBe ( process . arch )
211234 } )
212235
0 commit comments