-
-
Notifications
You must be signed in to change notification settings - Fork 320
/
Copy pathlog-name-status.spec.ts
57 lines (51 loc) · 1.48 KB
/
log-name-status.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
import {
createTestContext,
like,
newSimpleGit,
setUpFilesAdded,
setUpInit,
SimpleGitTestContext,
} from '@simple-git/test-utils';
import { DiffNameStatus, DiffResultTextFile } from '../..';
describe('log-name-status', function () {
let context: SimpleGitTestContext;
const steps = ['mv a b', 'commit -m two'];
beforeEach(async () => {
context = await createTestContext();
await setUpInit(context);
await setUpFilesAdded(context, ['a'], '.', 'one');
for (const step of steps) {
await context.git.raw(step.split(' '));
}
});
it('detects files moved with --name-status', async () => {
const actual = await newSimpleGit(context.root).log(['--name-status']);
expect(actual.all).toEqual([
mockListLogLine('two', { b: [DiffNameStatus.RENAMED, 100, 'a'] }),
mockListLogLine('one', { a: [DiffNameStatus.ADDED] }),
]);
});
});
function mockListLogLine(
message: string,
changes: Record<string, [DiffNameStatus, number?, string?]>
) {
const files: DiffResultTextFile[] = Object.entries(changes).map(
([file, [status, similarity = 0, from]]) => {
return {
binary: false,
changes: 0,
deletions: 0,
file,
insertions: 0,
similarity,
status,
from,
};
}
);
return like({
message,
diff: like({ changed: files.length, deletions: 0, insertions: 0, files }),
});
}