-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21f9ee6
commit 3706ef8
Showing
2 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
jest.mock('../../utils/process'); | ||
|
||
import {dedent} from 'ts-dedent'; | ||
import {constants} from 'os'; | ||
import {mocked} from 'ts-jest/utils'; | ||
import {spawnProcessOutput} from '../../utils/process'; | ||
import {getFakeCommand} from './testsUtils/utils'; | ||
|
||
import {IsGitInstalled} from './git'; | ||
|
||
describe('IsGitInstalled', () => { | ||
const mockedSpawnProcessOutput = mocked(spawnProcessOutput); | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('when git is not installed', () => { | ||
beforeEach(() => { | ||
mockedSpawnProcessOutput.mockResolvedValue({ | ||
exitCode: constants.errno.ENOENT, | ||
stderr: 'spawn git ENOENT', | ||
stdout: '', | ||
}); | ||
}); | ||
|
||
it('should return false and warn', async () => { | ||
const fakeCommand = getFakeCommand(); | ||
|
||
await expect(IsGitInstalled()(fakeCommand)).resolves.toBe(false); | ||
expect(fakeCommand.warn).toHaveBeenCalledTimes(2); | ||
expect(fakeCommand.warn).toHaveBeenNthCalledWith( | ||
1, | ||
'foo requires Git to run.' | ||
); | ||
expect(fakeCommand.warn).toHaveBeenNthCalledWith( | ||
2, | ||
dedent` | ||
Please visit https://git-scm.com/book/en/v2/Getting-Started-Installing-Git for more detailed installation information. | ||
` | ||
); | ||
}); | ||
}); | ||
|
||
describe('when an unknown error happens while checking for git', () => { | ||
beforeEach(() => { | ||
mockedSpawnProcessOutput.mockResolvedValue({ | ||
exitCode: 1, | ||
stderr: 'some random error oh no', | ||
stdout: '', | ||
}); | ||
}); | ||
|
||
it('should return false and warn', async () => { | ||
const fakeCommand = getFakeCommand(); | ||
|
||
await expect(IsGitInstalled()(fakeCommand)).resolves.toBe(false); | ||
expect(fakeCommand.warn).toHaveBeenCalledTimes(2); | ||
expect(fakeCommand.warn).toHaveBeenCalledWith(dedent` | ||
foo requires a valid Git installation to run. | ||
An unknown error happened while running git --version. | ||
some random error oh no | ||
`); | ||
expect(fakeCommand.warn).toHaveBeenCalledWith(dedent` | ||
Please visit https://git-scm.com/book/en/v2/Getting-Started-Installing-Git for more detailed installation information. | ||
`); | ||
}); | ||
}); | ||
|
||
describe('when git is installed', () => { | ||
beforeEach(() => { | ||
mockedSpawnProcessOutput.mockResolvedValue({ | ||
exitCode: 0, | ||
stderr: '', | ||
stdout: '', | ||
}); | ||
}); | ||
|
||
it('should return true and not warn', async () => { | ||
const fakeCommand = getFakeCommand(); | ||
|
||
await expect(IsGitInstalled()(fakeCommand)).resolves.toBe(true); | ||
expect(fakeCommand.warn).toHaveBeenCalledTimes(0); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import {getBinInstalledPrecondition} from './binPreconditionsFactory'; | ||
|
||
export const IsGitInstalled = getBinInstalledPrecondition('git', { | ||
prettyName: 'git', | ||
howToInstallBinText: | ||
'https://git-scm.com/book/en/v2/Getting-Started-Installing-Git', | ||
prettyName: 'Git', | ||
installLink: 'https://git-scm.com/book/en/v2/Getting-Started-Installing-Git', | ||
}); |