forked from steveukx/git-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathts-default-from-root.spec.ts
73 lines (59 loc) · 2.05 KB
/
ts-default-from-root.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
69
70
71
72
73
import simpleGit, {
CleanOptions,
CleanSummary,
GitResponseError,
MergeSummary,
SimpleGit,
TaskConfigurationError
} from 'simple-git';
import {
createSingleConflict,
createTestContext,
setUpConflicted,
setUpInit,
SimpleGitTestContext
} from '../__fixtures__';
describe('TS consume root export', () => {
let context: SimpleGitTestContext;
beforeEach(async () => context = await createTestContext());
beforeEach(() => setUpInit(context));
it('log types', () => {
expect(simpleGit().log<{ message: string }>({n: 10, format: {message: 'something'}})).not.toBeFalsy();
});
it('imports', () => {
expect(typeof simpleGit).toBe('function');
expect(CleanOptions).toEqual(expect.objectContaining({
'FORCE': 'f',
}));
});
it('finds types, enums and errors', async () => {
await setUpInit(context);
const git: SimpleGit = simpleGit(context.root);
await context.file('file.txt', 'content');
const error: TaskConfigurationError | CleanSummary = await git.clean(CleanOptions.DRY_RUN, ['--interactive'])
.catch((e: TaskConfigurationError) => e);
expect(error).toBeInstanceOf(Error);
const clean: CleanSummary = await git.clean(CleanOptions.FORCE);
expect(clean).toEqual(expect.objectContaining({
dryRun: false,
files: ['file.txt'],
}));
});
it('handles exceptions', async () => {
const git: SimpleGit = simpleGit(context.root);
await setUpConflicted(context);
const branchName = await createSingleConflict(context);
let wasError = false;
const mergeSummary: MergeSummary = await git.merge([branchName])
.catch((e: Error | GitResponseError<MergeSummary>) => {
if (e instanceof GitResponseError) {
wasError = true;
return e.git;
}
throw e;
});
expect(wasError).toBe(true);
expect(mergeSummary.conflicts).toHaveLength(1);
expect(String(mergeSummary)).toBe('CONFLICTS: aaa.txt:content');
})
});