11import { cloneRepoAndCheckoutLatestTag , cloneRepo , promptAndCreateAIFile } from './init.js'
22import { describe , expect , vi , test , beforeEach } from 'vitest'
3- import { downloadGitRepository } from '@shopify/cli-kit/node/git'
3+ import { downloadGitRepository , removeGitRemote } from '@shopify/cli-kit/node/git'
44import { renderSelectPrompt } from '@shopify/cli-kit/node/ui'
5- import { writeFile } from '@shopify/cli-kit/node/fs'
5+ import { writeFile , rmdir , fileExists } from '@shopify/cli-kit/node/fs'
66import { fetch } from '@shopify/cli-kit/node/http'
77import { joinPath } from '@shopify/cli-kit/node/path'
88
@@ -19,7 +19,12 @@ vi.mock('@shopify/cli-kit/node/ui', async () => {
1919} )
2020
2121describe ( 'cloneRepoAndCheckoutLatestTag()' , async ( ) => {
22- test ( 'calls downloadRepository function from git service to clone a repo without branch' , async ( ) => {
22+ beforeEach ( ( ) => {
23+ vi . mocked ( fileExists ) . mockResolvedValue ( true )
24+ vi . mocked ( joinPath ) . mockImplementation ( ( ...paths ) => paths . join ( '/' ) )
25+ } )
26+
27+ test ( 'calls downloadRepository function from git service to clone a repo with latest tag' , async ( ) => {
2328 // Given
2429 const repoUrl = 'https://github.com/Shopify/dawn.git'
2530 const destination = 'destination'
@@ -32,9 +37,40 @@ describe('cloneRepoAndCheckoutLatestTag()', async () => {
3237 // Then
3338 expect ( downloadGitRepository ) . toHaveBeenCalledWith ( { repoUrl, destination, latestTag, shallow} )
3439 } )
40+
41+ test ( 'removes git remote after cloning' , async ( ) => {
42+ // Given
43+ const repoUrl = 'https://github.com/Shopify/dawn.git'
44+ const destination = 'destination'
45+
46+ // When
47+ await cloneRepoAndCheckoutLatestTag ( repoUrl , destination )
48+
49+ // Then
50+ expect ( removeGitRemote ) . toHaveBeenCalledWith ( destination )
51+ } )
52+
53+ test ( 'removes .github directory from skeleton theme after cloning when it exists' , async ( ) => {
54+ // Given
55+ const repoUrl = 'https://github.com/Shopify/skeleton-theme.git'
56+ const destination = 'destination'
57+ vi . mocked ( fileExists ) . mockResolvedValue ( true )
58+
59+ // When
60+ await cloneRepoAndCheckoutLatestTag ( repoUrl , destination )
61+
62+ // Then
63+ expect ( fileExists ) . toHaveBeenCalledWith ( 'destination/.github' )
64+ expect ( rmdir ) . toHaveBeenCalledWith ( 'destination/.github' )
65+ } )
3566} )
3667
3768describe ( 'cloneRepo()' , async ( ) => {
69+ beforeEach ( ( ) => {
70+ vi . mocked ( fileExists ) . mockResolvedValue ( true )
71+ vi . mocked ( joinPath ) . mockImplementation ( ( ...paths ) => paths . join ( '/' ) )
72+ } )
73+
3874 test ( 'calls downloadRepository function from git service to clone a repo without branch' , async ( ) => {
3975 // Given
4076 const repoUrl = 'https://github.com/Shopify/dawn.git'
@@ -46,6 +82,32 @@ describe('cloneRepo()', async () => {
4682 // Then
4783 expect ( downloadGitRepository ) . toHaveBeenCalledWith ( { repoUrl, destination, shallow} )
4884 } )
85+
86+ test ( 'removes git remote after cloning' , async ( ) => {
87+ // Given
88+ const repoUrl = 'https://github.com/Shopify/dawn.git'
89+ const destination = 'destination'
90+
91+ // When
92+ await cloneRepo ( repoUrl , destination )
93+
94+ // Then
95+ expect ( removeGitRemote ) . toHaveBeenCalledWith ( destination )
96+ } )
97+
98+ test ( 'removes .github directory from skeleton theme after cloning when it exists' , async ( ) => {
99+ // Given
100+ const repoUrl = 'https://github.com/Shopify/skeleton-theme.git'
101+ const destination = 'destination'
102+ vi . mocked ( fileExists ) . mockResolvedValue ( true )
103+
104+ // When
105+ await cloneRepo ( repoUrl , destination )
106+
107+ // Then
108+ expect ( fileExists ) . toHaveBeenCalledWith ( 'destination/.github' )
109+ expect ( rmdir ) . toHaveBeenCalledWith ( 'destination/.github' )
110+ } )
49111} )
50112
51113describe ( 'promptAndCreateAIFile()' , ( ) => {
0 commit comments