You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/utils/index.test.js
+76Lines changed: 76 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,21 @@
1
1
import{exec}from'child_process'
2
+
import{readFile}from'fs'
2
3
import{
3
4
commitRelease,
4
5
generateLine,
6
+
generateReleased,
5
7
getCommitDetails,
6
8
getCommits,
9
+
getLatestTag,
7
10
updateVersion
8
11
}from'./index'
9
12
10
13
jest.mock('child_process',()=>({
11
14
exec: jest.fn()
12
15
}))
16
+
jest.mock('fs',()=>({
17
+
readFile: jest.fn()
18
+
}))
13
19
14
20
describe('utils',()=>{
15
21
beforeEach(()=>jest.resetAllMocks())
@@ -33,6 +39,26 @@ describe('utils', () => {
33
39
})
34
40
})
35
41
42
+
describe('getLatestTag',()=>{
43
+
it('should return null if there is no tag',async()=>{
44
+
exec.mockImplementation((_,cb)=>cb(null))
45
+
constlatestTag=awaitgetLatestTag()
46
+
47
+
expect(latestTag).toBe(null)
48
+
expect(exec).toBeCalledTimes(1)
49
+
expect(exec).toBeCalledWith('git tag | tail -n 1',expect.any(Function))
50
+
})
51
+
52
+
it('should return latest tag',async()=>{
53
+
exec.mockImplementation((_,cb)=>cb(null,'2.2.2'))
54
+
constlatestTag=awaitgetLatestTag()
55
+
56
+
expect(latestTag).toBe('2.2.2')
57
+
expect(exec).toBeCalledTimes(1)
58
+
expect(exec).toBeCalledWith('git tag | tail -n 1',expect.any(Function))
59
+
})
60
+
})
61
+
36
62
describe('getCommits',()=>{
37
63
it('should reject if receives an error',async()=>{
38
64
consterror='error'
@@ -62,6 +88,28 @@ describe('utils', () => {
62
88
)
63
89
expect(commits).toEqual(mockedOutput)
64
90
})
91
+
92
+
it('should return commits since tag',async()=>{
93
+
constmockedInput=
94
+
'bffc2f9e8da1c7ac133689bc9cd14494f3be08e3 refactor: extract line generating logic to function and promisify exec\naa805ce71ee103965ce3db46d4f6ed2658efd08d feat: add option to write to local CHANGELOG file\nf2191200bf7b6e5eec3d61fcef9eb756e0129cfb chore(release): 0.1.0\nb2f5901922505efbfb6dd684252e8df0cdffeeb2 fix: support other conventions\n4e02179cae1234d7083036024080a3f25fcb52c2 feat: add execute release feature'
95
+
constmockedOutput=[
96
+
'bffc2f9e8da1c7ac133689bc9cd14494f3be08e3 refactor: extract line generating logic to function and promisify exec',
97
+
'aa805ce71ee103965ce3db46d4f6ed2658efd08d feat: add option to write to local CHANGELOG file',
0 commit comments