diff --git a/__test__/git-directory-helper.test.ts b/__test__/git-directory-helper.test.ts index a783177..02118ae 100644 --- a/__test__/git-directory-helper.test.ts +++ b/__test__/git-directory-helper.test.ts @@ -281,6 +281,65 @@ describe('git-directory-helper tests', () => { expect(git.branchDelete).toHaveBeenCalledWith(false, 'local-branch-2') }) + const cleanWhenSubmoduleStatusIsFalse = + 'cleans when submodule status is false' + + it(cleanWhenSubmoduleStatusIsFalse, async () => { + // Arrange + await setup(cleanWhenSubmoduleStatusIsFalse) + await fs.promises.writeFile(path.join(repositoryPath, 'my-file'), '') + + //mock bad submodule + + const submoduleStatus = git.submoduleStatus as jest.Mock + submoduleStatus.mockImplementation(async (remote: boolean) => { + return false + }) + + // Act + await gitDirectoryHelper.prepareExistingDirectory( + git, + repositoryPath, + repositoryUrl, + clean, + ref + ) + + // Assert + const files = await fs.promises.readdir(repositoryPath) + expect(files).toHaveLength(0) + expect(git.tryClean).toHaveBeenCalled() + }) + + const doesNotCleanWhenSubmoduleStatusIsTrue = + 'does not clean when submodule status is true' + + it(doesNotCleanWhenSubmoduleStatusIsTrue, async () => { + // Arrange + await setup(doesNotCleanWhenSubmoduleStatusIsTrue) + await fs.promises.writeFile(path.join(repositoryPath, 'my-file'), '') + + const submoduleStatus = git.submoduleStatus as jest.Mock + submoduleStatus.mockImplementation(async (remote: boolean) => { + return true + }) + + // Act + await gitDirectoryHelper.prepareExistingDirectory( + git, + repositoryPath, + repositoryUrl, + clean, + ref + ) + + // Assert + + const files = await fs.promises.readdir(repositoryPath) + expect(files.sort()).toEqual(['.git', 'my-file']) + expect(git.tryClean).toHaveBeenCalled() + }) + const removesLockFiles = 'removes lock files' it(removesLockFiles, async () => { // Arrange