-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest.js
More file actions
211 lines (175 loc) · 5.69 KB
/
test.js
File metadata and controls
211 lines (175 loc) · 5.69 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import path from 'path';
import { homedir } from 'os';
import fs from 'fs';
import getCommitRange from './index';
const fixtures = path.join(process.cwd(), 'test', 'fixtures');
beforeAll(async () => {
// move git to .git
await fs.renameSync(path.join(fixtures, 'repo-ten-commits', 'git'), path.join(fixtures, 'repo-ten-commits', '.git'));
await fs.renameSync(path.join(fixtures, 'repo-body-commits', 'git'), path.join(fixtures, 'repo-body-commits', '.git'));
await fs.renameSync(path.join(fixtures, 'repo-merge', 'git'), path.join(fixtures, 'repo-merge', '.git'));
});
afterAll(async () => {
// move .git to git
await fs.renameSync(path.join(fixtures, 'repo-ten-commits', '.git'), path.join(fixtures, 'repo-ten-commits', 'git'));
await fs.renameSync(path.join(fixtures, 'repo-body-commits', '.git'), path.join(fixtures, 'repo-body-commits', 'git'));
await fs.renameSync(path.join(fixtures, 'repo-merge', '.git'), path.join(fixtures, 'repo-merge', 'git'));
});
it('GET COMMIT RANGE | not a repositrory', async () => {
const cwd = process.cwd();
await process.chdir(homedir());
const commits = await getCommitRange({
path: homedir(),
});
expect(commits).toEqual([]);
await process.chdir(cwd);
});
it('GET COMMIT RANGE | get all commits INCLUDING from and to', async () => {
await process.chdir('test/fixtures/repo-ten-commits');
const cwd = process.cwd();
const commits = await getCommitRange({
path: cwd,
from: '15be93c31ad87c9ced03ba0b60fc2fb55c977c5c',
to: '6bca03f01b3b8ad152b7c2562ff92aa48a8d41a5',
});
expect(commits).toEqual([
'15be93c31ad87c9ced03ba0b60fc2fb55c977c5c',
'ee1db4e07af7a26061f569a3d3dc123007e001c7',
'90caf4f45547a02c585dfed6639e20288d15c346',
]);
await process.chdir('../../..');
});
it('GET COMMIT RANGE | get all commits EXCLUDING from and to', async () => {
await process.chdir('test/fixtures/repo-ten-commits');
const cwd = process.cwd();
const commits = await getCommitRange({
path: cwd,
from: '15be93c31ad87c9ced03ba0b60fc2fb55c977c5c',
to: '6bca03f01b3b8ad152b7c2562ff92aa48a8d41a5',
include: false,
});
expect(commits).toEqual([
'ee1db4e07af7a26061f569a3d3dc123007e001c7',
]);
await process.chdir('../../..');
});
it('GET COMMIT RANGE | test not absolute path', async () => {
const commits = await getCommitRange({
path: 'test/fixtures/repo-ten-commits',
from: '15be93c31ad87c9ced03ba0b60fc2fb55c977c5c',
to: '6bca03f01b3b8ad152b7c2562ff92aa48a8d41a5',
include: false,
});
expect(commits).toEqual([
'ee1db4e07af7a26061f569a3d3dc123007e001c7',
]);
});
it('GET COMMIT RANGE | give me all commits since the beginning', async () => {
const commits = await getCommitRange({
path: 'test/fixtures/repo-ten-commits',
});
expect(commits).toEqual([
'15be93c31ad87c9ced03ba0b60fc2fb55c977c5c',
'ee1db4e07af7a26061f569a3d3dc123007e001c7',
'90caf4f45547a02c585dfed6639e20288d15c346',
'6bca03f01b3b8ad152b7c2562ff92aa48a8d41a5',
'32b940b014322834966d79b109d2d7adec8e3ea3',
'd943b4112fa88059a23f15523a58a50a82a128b3',
'8e4211bc265acbbe1f194936154cb5cc108481ec',
'4892d8cf98a43d97f64c2168a1a44270d0f01299',
'd1309a2d49a60f9d67c0c04ce90c7adc7680fdc4',
'6a820773ef84c57b5c927e4ccf1b4c872601826c',
]);
});
it('GET COMMIT RANGE | give me all commits (short hash) since the beginning', async () => {
const commits = await getCommitRange({
path: 'test/fixtures/repo-ten-commits',
short: true,
});
expect(commits).toEqual([
'15be93c',
'ee1db4e',
'90caf4f',
'6bca03f',
'32b940b',
'd943b41',
'8e4211b',
'4892d8c',
'd1309a2',
'6a82077',
]);
});
it('GET COMMIT RANGE | return all commit messages', async () => {
const commits = await getCommitRange({
path: 'test/fixtures/repo-ten-commits',
type: 'text',
});
expect(commits).toEqual([
'Feat: thats the 10th commit',
'Style: thats the 9th commit',
'Feat: thats the 8th commit',
'CI: thats the 7th commit',
'Chore: thats the 6th commit',
'Chore: thats the fifth commit',
'Chore: thats the fourth commit',
'Chore: thats the third commit',
'Chore: thats the second commit',
'Initial commit',
]);
});
it('GET COMMIT RANGE | return all commit messages within a range', async () => {
const commits = await getCommitRange({
path: 'test/fixtures/repo-ten-commits',
type: 'text',
from: 'ee1db4e',
to: '4892d8c',
});
expect(commits).toEqual([
'Style: thats the 9th commit',
'Feat: thats the 8th commit',
'CI: thats the 7th commit',
'Chore: thats the 6th commit',
'Chore: thats the fifth commit',
'Chore: thats the fourth commit',
]);
});
it('GET COMMIT RANGE | return all commit messages within a range with longer text messages', async () => {
const commits = await getCommitRange({
path: 'test/fixtures/repo-body-commits',
type: 'text',
include: true,
});
expect(commits).toEqual([
'Chore: thats the fourth commit',
'Chore: thats the third commit\nWith\nmore\ntext',
`Chore: thats the second commit
With a body`,
'Initial commit',
]);
});
it('GET COMMIT RANGE | do NOT include merge commits', async () => {
const commits = await getCommitRange({
path: 'test/fixtures/repo-merge',
type: 'text',
include: true,
includeMerges: false,
});
expect(commits).toEqual([
'Third commit',
'Second commit',
'First commit',
]);
});
it('GET COMMIT RANGE | include merge commits', async () => {
const commits = await getCommitRange({
path: 'test/fixtures/repo-merge',
type: 'text',
include: true,
});
expect(commits).toEqual([
"Merge branch 'feat/check'",
'Third commit',
'Second commit',
'First commit',
]);
});