Skip to content

Commit

Permalink
feat: enable git diff on submodules (#353)
Browse files Browse the repository at this point in the history
* feat: enable git diff on submodules
Fixes isGit method to check whether .git is a folder or file (this is the case on submodules)

* test: fix fs mock for files in sub folders
fix fs mock for files in sub folders

* test: adds coverage for git repo check for submodules
adds coverage for git repo check on submodules

* style: removes unecessary data setup
removes unecessary data setup

* refactor: changes beforeAll to beforeEach on tests to avoid parallelism

Co-authored-by: Heitor Araujo <[email protected]>
  • Loading branch information
hsaraujo and Heitor Araujo authored Sep 21, 2022
1 parent a29baec commit 263e37d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion __mocks__/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fs.__setMockFiles = newMockFiles => {
mockContent = new Map()
filePathList = new Set()
for (const file in newMockFiles) {
filePathList.add(path.basename(file))
filePathList.add(file)
const dir = path.basename(path.dirname(file))
if (!mockFiles.has(dir)) {
mockFiles.set(dir, [])
Expand Down
44 changes: 39 additions & 5 deletions __tests__/unit/lib/utils/cliHelper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ const testConfig = {
apiVersion: '46',
}

const mockFiles = {
output: '',
'.': '',
}

describe(`test if the application`, () => {
beforeAll(() => {
beforeEach(() => {
fs.errorMode = false
fs.statErrorMode = false
fs.__setMockFiles({
output: '',
'.': '',
})
fs.__setMockFiles(mockFiles)
})

test('throws errors when to parameter is not filled', async () => {
Expand Down Expand Up @@ -222,4 +224,36 @@ describe(`test if the application`, () => {
format(messages.errorParameterIsNotGitSHA, 'from', TAG_REF_TYPE)
)
})

test('do not throw errors when repo contains submodule git file', async () => {
fs.__setMockFiles({
...mockFiles,
'submodule/.git': 'lorem ipsum',
})
let cliHelper = new CLIHelper({
...testConfig,
repo: 'submodule/',
})
expect.assertions(1)
await expect(cliHelper.validateConfig()).rejects.not.toThrow(
format(messages.errorPathIsNotGit, 'submodule/')
)
})

test('do not throw errors when repo submodule git folder', async () => {
fs.__setMockFiles({
...mockFiles,
'submodule/.git': '',
})
let cliHelper = new CLIHelper({
...testConfig,
repo: 'submodule/',
})
// let cliHelper = new CLIHelper({ ...testConfig, repo: './submodule' })
expect.assertions(1)
// cliHelper.validateConfig()
await expect(cliHelper.validateConfig()).rejects.not.toThrow(
format(messages.errorPathIsNotGit, 'submodule/.git')
)
})
})
5 changes: 4 additions & 1 deletion src/utils/cliHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ const dirExists = async dir => await fsExists(dir, 'isDirectory')
const fileExists = async file => await fsExists(file, 'isFile')

const isGit = async dir => {
return await dirExists(join(dir, GIT_FOLDER))
const isGitDir = await dirExists(join(dir, GIT_FOLDER))
const isGitFile = await fileExists(join(dir, GIT_FOLDER))

return isGitDir || isGitFile
}

const isBlank = str => !str || /^\s*$/.test(str)
Expand Down

0 comments on commit 263e37d

Please sign in to comment.