@@ -27,6 +27,14 @@ class TestThemeCommand extends ThemeCommand {
2727 password : Flags . string ( {
2828 env : 'SHOPIFY_FLAG_PASSWORD' ,
2929 } ) ,
30+ path : Flags . string ( {
31+ env : 'SHOPIFY_FLAG_PATH' ,
32+ default : 'current/working/directory' ,
33+ } ) ,
34+ 'no-color' : Flags . boolean ( {
35+ env : 'SHOPIFY_FLAG_NO_COLOR' ,
36+ default : false ,
37+ } ) ,
3038 }
3139
3240 static multiEnvironmentsFlags : RequiredFlags = [ 'store' ]
@@ -119,7 +127,9 @@ describe('ThemeCommand', () => {
119127 await command . run ( )
120128
121129 // Then
122- expect ( loadEnvironment ) . toHaveBeenCalledWith ( 'development' , 'shopify.theme.toml' , { from : undefined } )
130+ expect ( loadEnvironment ) . toHaveBeenCalledWith ( 'development' , 'shopify.theme.toml' , {
131+ from : 'current/working/directory' ,
132+ } )
123133 expect ( ensureAuthenticatedThemes ) . toHaveBeenCalledTimes ( 1 )
124134 expect ( renderConcurrent ) . not . toHaveBeenCalled ( )
125135 expect ( command . commandCalls ) . toHaveLength ( 1 )
@@ -149,8 +159,14 @@ describe('ThemeCommand', () => {
149159 await command . run ( )
150160
151161 // Then
152- expect ( loadEnvironment ) . toHaveBeenCalledWith ( 'development' , 'shopify.theme.toml' , { from : undefined , silent : true } )
153- expect ( loadEnvironment ) . toHaveBeenCalledWith ( 'staging' , 'shopify.theme.toml' , { from : undefined , silent : true } )
162+ expect ( loadEnvironment ) . toHaveBeenCalledWith ( 'development' , 'shopify.theme.toml' , {
163+ from : 'current/working/directory' ,
164+ silent : true ,
165+ } )
166+ expect ( loadEnvironment ) . toHaveBeenCalledWith ( 'staging' , 'shopify.theme.toml' , {
167+ from : 'current/working/directory' ,
168+ silent : true ,
169+ } )
154170
155171 expect ( renderConcurrent ) . toHaveBeenCalledOnce ( )
156172 expect ( renderConcurrent ) . toHaveBeenCalledWith (
@@ -433,5 +449,51 @@ describe('ThemeCommand', () => {
433449 } ) ,
434450 )
435451 } )
452+
453+ test ( 'CLI and shopify.theme.toml flag values take precedence over defaults' , async ( ) => {
454+ // Given
455+ vi . mocked ( loadEnvironment )
456+ . mockResolvedValueOnce ( { store : 'store1.myshopify.com' , theme : 'theme1.myshopify.com' , path : 'theme/path' } )
457+ . mockResolvedValueOnce ( { store : 'store2.myshopify.com' , development : true , path : 'development/path' } )
458+ . mockResolvedValueOnce ( { store : 'store3.myshopify.com' , live : true , 'no-color' : false } )
459+
460+ vi . mocked ( renderConcurrent ) . mockImplementation ( async ( { processes} ) => {
461+ for ( const process of processes ) {
462+ // eslint-disable-next-line no-await-in-loop
463+ await process . action ( { } as Writable , { } as Writable , { } as any )
464+ }
465+ } )
466+
467+ await CommandConfig . load ( )
468+ const command = new TestThemeCommand (
469+ [ '--environment' , 'theme' , '--environment' , 'development' , '--environment' , 'live' , '--no-color' ] ,
470+ CommandConfig ,
471+ )
472+
473+ // When
474+ await command . run ( )
475+
476+ // Then
477+ const commandCalls = command . commandCalls
478+ expect ( commandCalls ) . toHaveLength ( 3 )
479+
480+ const themeEnvFlags = commandCalls [ 0 ] ?. flags
481+ expect ( themeEnvFlags ?. path ) . toEqual ( 'theme/path' )
482+ expect ( themeEnvFlags ?. store ) . toEqual ( 'store1.myshopify.com' )
483+ expect ( themeEnvFlags ?. theme ) . toEqual ( 'theme1.myshopify.com' )
484+ expect ( themeEnvFlags ?. [ 'no-color' ] ) . toEqual ( true )
485+
486+ const developmentEnvFlags = commandCalls [ 1 ] ?. flags
487+ expect ( developmentEnvFlags ?. path ) . toEqual ( 'development/path' )
488+ expect ( developmentEnvFlags ?. store ) . toEqual ( 'store2.myshopify.com' )
489+ expect ( developmentEnvFlags ?. development ) . toEqual ( true )
490+ expect ( developmentEnvFlags ?. [ 'no-color' ] ) . toEqual ( true )
491+
492+ const liveEnvFlags = commandCalls [ 2 ] ?. flags
493+ expect ( liveEnvFlags ?. path ) . toEqual ( 'current/working/directory' )
494+ expect ( liveEnvFlags ?. store ) . toEqual ( 'store3.myshopify.com' )
495+ expect ( liveEnvFlags ?. live ) . toEqual ( true )
496+ expect ( liveEnvFlags ?. [ 'no-color' ] ) . toEqual ( true )
497+ } )
436498 } )
437499} )
0 commit comments