forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread.test.js
63 lines (50 loc) · 1.97 KB
/
read.test.js
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
import {git} from '@commitlint/test';
import test from 'ava';
import execa from 'execa';
import * as sander from '@marionebl/sander';
import pkg from '../package';
import read from './read';
test('get edit commit message specified by the `edit` flag', async t => {
const cwd = await git.bootstrap();
await sander.writeFile(cwd, 'commit-msg-file', 'foo');
const expected = ['foo\n'];
const actual = await read({edit: 'commit-msg-file', cwd});
t.deepEqual(actual, expected);
});
test('get edit commit message from git root', async t => {
const cwd = await git.bootstrap();
await sander.writeFile(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});
t.deepEqual(actual, expected);
});
test('get history commit messages', async t => {
const cwd = await git.bootstrap();
await sander.writeFile(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});
t.deepEqual(actual, expected);
});
test('get edit commit message from git subdirectory', async t => {
const cwd = await git.bootstrap();
await sander.mkdir(cwd, 'beta');
await sander.writeFile(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});
t.deepEqual(actual, expected);
});
test('get history commit messages from shallow clone', async t => {
const cwd = await git.clone(pkg.repository.url, '--depth', '1');
const err = await t.throws(read({from: 'master', cwd}));
t.true(
err.message.indexOf('Could not get git history from shallow clone') > -1
);
});