-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
144 lines (133 loc) · 4.09 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import fs from 'fs-extra';
import { homedir } from 'os';
import test from 'ava';
import path from 'path';
import taggedCommit from './index';
const fixtures = path.join(process.cwd(), 'test', 'fixtures');
test.before('rename git folders', () => {
fs.renameSync(path.join(fixtures, 'local-tagged-3', 'git'), path.join(fixtures, 'local-tagged-3', '.git'));
fs.renameSync(path.join(fixtures, 'local-tagged-0', 'git'), path.join(fixtures, 'local-tagged-0', '.git'));
fs.renameSync(path.join(fixtures, 'remote-tagged-1', 'git'), path.join(fixtures, 'remote-tagged-1', '.git'));
});
test.after.always('rename .git folders', () => {
fs.renameSync(path.join(fixtures, 'local-tagged-3', '.git'), path.join(fixtures, 'local-tagged-3', 'git'));
fs.renameSync(path.join(fixtures, 'local-tagged-0', '.git'), path.join(fixtures, 'local-tagged-0', 'git'));
fs.renameSync(path.join(fixtures, 'remote-tagged-1', '.git'), path.join(fixtures, 'remote-tagged-1', 'git'));
});
test('get the latest local tag', (t) => {
t.deepEqual(taggedCommit({
path: 'test/fixtures/local-tagged-3',
lookBehind: 1,
}),
[{
commit: 'af6919c58065af276780ebbb8f16b6cdadd2c17c',
shortCommit: 'af6919c',
hash: 'af6919c58065af276780ebbb8f16b6cdadd2c17c',
shortHash: 'af6919c',
version: 'v0.0.3',
refsTags: 'refs/tags/v0.0.3',
}],
);
});
test('get the latest local tag without passing the lookBehind', (t) => {
t.deepEqual(taggedCommit({
path: 'test/fixtures/local-tagged-3',
}),
[{
commit: 'af6919c58065af276780ebbb8f16b6cdadd2c17c',
shortCommit: 'af6919c',
hash: 'af6919c58065af276780ebbb8f16b6cdadd2c17c',
shortHash: 'af6919c',
version: 'v0.0.3',
refsTags: 'refs/tags/v0.0.3',
}],
);
});
test('get the latest two local tags', (t) => {
t.deepEqual(taggedCommit({
path: 'test/fixtures/local-tagged-3',
lookBehind: 2,
}),
[
{
commit: '76486fab54307f961ffa83c283f15f49adce30bb',
shortCommit: '76486fa',
hash: '76486fab54307f961ffa83c283f15f49adce30bb',
shortHash: '76486fa',
version: 'v0.0.2',
refsTags: 'refs/tags/v0.0.2',
},
{
commit: 'af6919c58065af276780ebbb8f16b6cdadd2c17c',
shortCommit: 'af6919c',
hash: 'af6919c58065af276780ebbb8f16b6cdadd2c17c',
shortHash: 'af6919c',
version: 'v0.0.3',
refsTags: 'refs/tags/v0.0.3',
},
],
);
});
test('get the latest three local tags', (t) => {
t.deepEqual(taggedCommit({
path: 'test/fixtures/local-tagged-3',
lookBehind: 3,
}),
[
{
commit: '31107b9051efe17e57c583937e027993860b11a9',
shortCommit: '31107b9',
hash: '31107b9051efe17e57c583937e027993860b11a9',
shortHash: '31107b9',
version: 'v0.0.1',
refsTags: 'refs/tags/v0.0.1',
},
{
commit: '76486fab54307f961ffa83c283f15f49adce30bb',
shortCommit: '76486fa',
hash: '76486fab54307f961ffa83c283f15f49adce30bb',
shortHash: '76486fa',
version: 'v0.0.2',
refsTags: 'refs/tags/v0.0.2',
},
{
commit: 'af6919c58065af276780ebbb8f16b6cdadd2c17c',
shortCommit: 'af6919c',
hash: 'af6919c58065af276780ebbb8f16b6cdadd2c17c',
shortHash: 'af6919c',
version: 'v0.0.3',
refsTags: 'refs/tags/v0.0.3',
},
],
);
});
test('get an emty array if local repo has no tags', (t) => {
t.deepEqual(taggedCommit({
path: 'test/fixtures/local-tagged-0',
lookBehind: 3,
}), []);
});
test('get an emty array if the directory is not a repo', (t) => {
t.deepEqual(taggedCommit({
path: homedir(),
lookBehind: 3,
}), []);
});
test('get tags from remote repository', (t) => {
t.deepEqual(taggedCommit({
path: 'test/fixtures/remote-tagged-1',
local: false,
remote: 'origin',
}),
[
{
commit: '31107b9051efe17e57c583937e027993860b11a9',
shortCommit: '31107b9',
hash: '31107b9051efe17e57c583937e027993860b11a9',
shortHash: '31107b9',
version: 'v0.0.0',
refsTags: 'refs/tags/v0.0.0',
},
],
);
});