forked from JPeer264/node-git-commit-info
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
82 lines (65 loc) · 2.37 KB
/
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import test from 'ava';
import fs from 'fs-extra';
import { homedir } from 'os';
import path from 'path';
import gitCommitInfo from './index';
const fixtures = path.join(process.cwd(), 'test', 'fixtures');
const folders = [
'upToDate',
'multiline',
'merge',
];
test.before('rename git folders', () => {
folders.map(folder => fs.renameSync(path.join(fixtures, folder, 'git'), path.join(fixtures, folder, '.git')));
});
test.after.always('rename .git folders', () => {
folders.map(folder => fs.renameSync(path.join(fixtures, folder, '.git'), path.join(fixtures, folder, 'git')));
});
test('up to date', (t) => {
const latestInfo = gitCommitInfo({ cwd: path.join(fixtures, 'multiline')});
t.is(latestInfo.message, 'do not merge');
t.is(latestInfo.author, 'JPeer264');
t.is(latestInfo.email, '[email protected]');
t.is(latestInfo.commit, '19131a4a9465f38a5cab030beb173edd6e23c6de');
t.is(latestInfo.shortCommit, '19131a4');
});
test('specific commit', (t) => {
const latestInfo = gitCommitInfo({
cwd: path.join(fixtures, 'multiline'),
commit: '66d6043fb740278dac391ad8b41df74ef9e68afc',
});
t.is(latestInfo.message, 'Add: index.js\n \n Here is more information in the body\n \n BREAKING CHANGE: yes, here is a footer');
t.is(latestInfo.author, 'JPeer264');
t.is(latestInfo.email, '[email protected]');
t.is(latestInfo.commit, '66d6043fb740278dac391ad8b41df74ef9e68afc');
t.is(latestInfo.shortCommit, '66d6043');
});
test('unknown commit hash', (t) => {
const latestInfo = gitCommitInfo({
cwd: path.join(fixtures, 'multiline'),
commit: 'does not work',
});
t.deepEqual(latestInfo, {});
});
test('merge conflict - named automatically', (t) => {
const mergeInfo = gitCommitInfo({
cwd: path.join(fixtures, 'merge'),
commit: '76d090566587fa5e97035b8c133866eb0116d7c0',
});
t.is(mergeInfo.commit, '76d090566587fa5e97035b8c133866eb0116d7c0');
t.is(mergeInfo.message, `Merge branch 'test/merge'`);
});
test('merge conflict - named randomly', (t) => {
const mergeInfo = gitCommitInfo({
cwd: path.join(fixtures, 'merge'),
commit: 'e49bfdc2285f13aa5cc206a02a4f41b335026ea5',
});
t.is(mergeInfo.commit, 'e49bfdc2285f13aa5cc206a02a4f41b335026ea5');
t.is(mergeInfo.message, 'My message');
});
test('no git repo', (t) => {
const latestInfo = gitCommitInfo({
cwd: homedir(),
});
t.deepEqual(latestInfo, {});
});