11import { themeFlags } from './flags.js'
22import { describe , expect , test } from 'vitest'
33import Command from '@shopify/cli-kit/node/base-command'
4- import { inTemporaryDirectory } from '@shopify/cli-kit/node/fs'
5- import { cwd , resolvePath } from '@shopify/cli-kit/node/path'
4+ import { inTemporaryDirectory , writeFileSync } from '@shopify/cli-kit/node/fs'
5+ import { cwd , joinPath , resolvePath } from '@shopify/cli-kit/node/path'
66import { mockAndCaptureOutput } from '@shopify/cli-kit/node/testing/output'
77
88class MockCommand extends Command {
@@ -26,20 +26,34 @@ describe('themeFlags', () => {
2626 expect ( flags . path ) . toEqual ( cwd ( ) )
2727 } )
2828
29- test ( 'can be expclitly provided' , async ( ) => {
29+ test ( 'can be explicitly provided' , async ( ) => {
3030 await inTemporaryDirectory ( async ( tmpDir ) => {
3131 const flags = await MockCommand . run ( [ '--path' , tmpDir ] )
3232
3333 expect ( flags . path ) . toEqual ( resolvePath ( tmpDir ) )
3434 } )
3535 } )
3636
37- test ( "renders an error message and exists when the path doesn't exist" , async ( ) => {
37+ test ( "renders an error message and exits when the path doesn't exist" , async ( ) => {
3838 const mockOutput = mockAndCaptureOutput ( )
3939
4040 await MockCommand . run ( [ '--path' , 'boom' ] )
4141
4242 expect ( mockOutput . error ( ) ) . toMatch ( "A path was explicitly provided but doesn't exist" )
4343 } )
44+
45+ test ( 'renders an error message and exits when the path is a file instead of a directory' , async ( ) => {
46+ await inTemporaryDirectory ( async ( tmpDir ) => {
47+ const filePath = joinPath ( tmpDir , 'section.liquid' )
48+ writeFileSync ( filePath , '{% schema %}{% endschema %}' )
49+
50+ const mockOutput = mockAndCaptureOutput ( )
51+
52+ await MockCommand . run ( [ '--path' , filePath ] )
53+
54+ expect ( mockOutput . error ( ) ) . toMatch ( 'The path must be a directory, not a file' )
55+ expect ( mockOutput . error ( ) ) . toMatch ( 'section.liquid' )
56+ } )
57+ } )
4458 } )
4559} )
0 commit comments