-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into integrate-exp-show
- Loading branch information
Showing
37 changed files
with
657 additions
and
150 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
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
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
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,71 @@ | ||
import { EventEmitter } from 'vscode' | ||
import { Disposable, Disposer } from '@hediet/std/disposable' | ||
import { GitReader } from './reader' | ||
import { CliResult, CliStarted } from '..' | ||
import { createProcess } from '../../process/execution' | ||
import { getMockedProcess } from '../../test/util/jest' | ||
|
||
jest.mock('vscode') | ||
jest.mock('@hediet/std/disposable') | ||
jest.mock('fs') | ||
jest.mock('../../process/execution') | ||
jest.mock('../../env') | ||
jest.mock('../../common/logger') | ||
|
||
const mockedDisposable = jest.mocked(Disposable) | ||
|
||
const mockedCreateProcess = jest.mocked(createProcess) | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
|
||
describe('GitReader', () => { | ||
mockedDisposable.fn.mockReturnValueOnce({ | ||
track: function <T>(disposable: T): T { | ||
return disposable | ||
}, | ||
untrack: function <T>(disposable: T): T { | ||
return disposable | ||
} | ||
} as unknown as (() => void) & Disposer) | ||
|
||
const gitReader = new GitReader({ | ||
processCompleted: { | ||
event: jest.fn(), | ||
fire: jest.fn() | ||
} as unknown as EventEmitter<CliResult>, | ||
processStarted: { | ||
event: jest.fn(), | ||
fire: jest.fn() | ||
} as unknown as EventEmitter<CliStarted> | ||
}) | ||
|
||
describe('getBranches', () => { | ||
it('should match the expected output', async () => { | ||
const cwd = __dirname | ||
const branches = ['main', 'exp-12', 'fix-bug-11', 'other'] | ||
mockedCreateProcess.mockReturnValueOnce( | ||
getMockedProcess(branches.join('\n')) | ||
) | ||
|
||
const cliOutput = await gitReader.getBranches(cwd) | ||
expect(cliOutput).toStrictEqual(branches) | ||
expect(mockedCreateProcess).toHaveBeenCalledWith({ | ||
args: ['branch', '--no-merge'], | ||
cwd, | ||
executable: 'git' | ||
}) | ||
}) | ||
|
||
it('should return an empty array if the cli returns any type of error', async () => { | ||
const cwd = __dirname | ||
mockedCreateProcess.mockImplementationOnce(() => { | ||
throw new Error('unexpected error - something something') | ||
}) | ||
|
||
const cliOutput = await gitReader.getBranches(cwd) | ||
expect(cliOutput).toStrictEqual([]) | ||
}) | ||
}) | ||
}) |
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
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
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
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
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
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
Oops, something went wrong.