/
scm.spec.ts
68 lines (54 loc) · 1.83 KB
/
scm.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { execSync as _execSync } from 'node:child_process';
import { mockedFunction } from '../../../../test/util';
import { LocalFs } from './scm';
jest.mock('node:child_process');
const execSync = mockedFunction(_execSync);
describe('modules/platform/local/scm', () => {
let localFs: LocalFs;
beforeEach(() => {
localFs = new LocalFs();
});
describe('dummy functions', () => {
it('behindBaseBranch', async () => {
expect(await localFs.isBranchBehindBase('', '')).toBe(false);
});
it('isBranchModified', async () => {
expect(await localFs.isBranchModified('')).toBe(false);
});
it('isBranchConflicted', async () => {
expect(await localFs.isBranchConflicted('', '')).toBe(false);
});
it('branchExists', async () => {
expect(await localFs.branchExists('')).toBe(true);
});
it('getBranchCommit', async () => {
expect(await localFs.getBranchCommit('')).toBeNull();
});
it('deleteBranch', async () => {
expect(await localFs.deleteBranch('')).toBeUndefined();
});
it('commitAndPush', async () => {
expect(await localFs.commitAndPush({} as any)).toBeNull();
});
it('checkoutBranch', async () => {
expect(await localFs.checkoutBranch('')).toBe('');
});
});
describe('getFileList', () => {
it('should return file list using git', async () => {
execSync.mockReturnValueOnce('file1\nfile2');
expect(await localFs.getFileList()).toHaveLength(2);
});
it('should return file list using glob', async () => {
execSync.mockImplementationOnce(() => {
throw new Error();
});
jest.mock('glob', () => ({
glob: jest
.fn()
.mockImplementation(() => Promise.resolve(['file1', 'file2'])),
}));
expect(await localFs.getFileList()).toHaveLength(2);
});
});
});