forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread.test.ts
73 lines (59 loc) · 2.57 KB
/
read.test.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 path from 'path';
import {git} from '@commitlint/test';
import execa from 'execa';
import fs from 'fs-extra';
import read from './read';
test('get edit commit message specified by the `edit` flag', async () => {
const cwd: string = await git.bootstrap();
await fs.writeFile(path.join(cwd, 'commit-msg-file'), 'foo');
const expected = ['foo\n'];
const actual = await read({edit: 'commit-msg-file', cwd});
expect(actual).toEqual(expected);
});
test('get edit commit message from git root', async () => {
const cwd: string = await git.bootstrap();
await fs.writeFile(path.join(cwd, 'alpha.txt'), 'alpha');
await execa('git', ['add', '.'], {cwd});
await execa('git', ['commit', '-m', 'alpha'], {cwd});
const expected = ['alpha\n\n'];
const actual = await read({edit: true, cwd});
expect(actual).toEqual(expected);
});
test('get history commit messages', async () => {
const cwd: string = await git.bootstrap();
await fs.writeFile(path.join(cwd, 'alpha.txt'), 'alpha');
await execa('git', ['add', 'alpha.txt'], {cwd});
await execa('git', ['commit', '-m', 'alpha'], {cwd});
await execa('git', ['rm', 'alpha.txt'], {cwd});
await execa('git', ['commit', '-m', 'remove alpha'], {cwd});
const expected = ['remove alpha\n\n', 'alpha\n\n'];
const actual = await read({cwd});
expect(actual).toEqual(expected);
});
test('get edit commit message from git subdirectory', async () => {
const cwd: string = await git.bootstrap();
await fs.mkdir(path.join(cwd, 'beta'));
await fs.writeFile(path.join(cwd, 'beta/beta.txt'), 'beta');
await execa('git', ['add', '.'], {cwd});
await execa('git', ['commit', '-m', 'beta'], {cwd});
const expected = ['beta\n\n'];
const actual = await read({edit: true, cwd});
expect(actual).toEqual(expected);
});
test('get edit commit message while skipping first commit', async () => {
const cwd: string = await git.bootstrap();
await fs.mkdir(path.join(cwd, 'beta'));
await fs.writeFile(path.join(cwd, 'beta/beta.txt'), 'beta');
await fs.writeFile(path.join(cwd, 'alpha.txt'), 'alpha');
await execa('git', ['add', 'alpha.txt'], {cwd});
await execa('git', ['commit', '-m', 'alpha'], {cwd});
await fs.writeFile(path.join(cwd, 'beta.txt'), 'beta');
await execa('git', ['add', 'beta.txt'], {cwd});
await execa('git', ['commit', '-m', 'beta'], {cwd});
await fs.writeFile(path.join(cwd, 'gamma.txt'), 'gamma');
await execa('git', ['add', 'gamma.txt'], {cwd});
await execa('git', ['commit', '-m', 'gamma'], {cwd});
const expected = ['beta\n\n'];
const actual = await read({from: 'HEAD~2', cwd, gitLogArgs: '--skip 1'});
expect(actual).toEqual(expected);
});