-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathresolveRef.test.ts
100 lines (73 loc) · 2.71 KB
/
resolveRef.test.ts
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
import { resolveRef } from 'git-essentials'
import { NotFoundError } from 'git-essentials/errors'
import { makeFsFixture, FsFixtureData } from './helpers/makeFsFixture'
import { expectToFailWithTypeAsync } from './helpers/assertionHelper'
import resolveRefFsFixtureData from './fixtures/fs/resolveRef.json'
describe('resolveRef', () => {
it('1e40fdfba1cf17f3c9f9f3d6b392b1865e5147b9', async () => {
// arrange
const { fs, dir } = await makeFsFixture(resolveRefFsFixtureData as FsFixtureData)
// act
const ref = await resolveRef({ fs, dir, ref: '1e40fdfba1cf17f3c9f9f3d6b392b1865e5147b9' })
// assert
expect(ref).toBe('1e40fdfba1cf17f3c9f9f3d6b392b1865e5147b9')
})
it('test-branch', async () => {
// arrange
const { fs, dir } = await makeFsFixture(resolveRefFsFixtureData as FsFixtureData)
// act
const ref = await resolveRef({ fs, dir, ref: 'origin/test-branch' })
// assert
expect(ref).toBe('e10ebb90d03eaacca84de1af0a59b444232da99e')
})
it('config', async () => {
// arrange
const { fs, dir } = await makeFsFixture(resolveRefFsFixtureData as FsFixtureData)
// act
const ref = await resolveRef({ fs, dir, ref: 'config' })
// assert
expect(ref).toBe('e10ebb90d03eaacca84de1af0a59b444232da99e')
})
it('test-tag', async () => {
// arrange
const { fs, dir } = await makeFsFixture(resolveRefFsFixtureData as FsFixtureData)
// act
const ref = await resolveRef({ fs, dir, ref: 'test-tag' })
// assert
expect(ref).toBe('1e40fdfba1cf17f3c9f9f3d6b392b1865e5147b9')
})
it('HEAD', async () => {
// arrange
const { fs, dir } = await makeFsFixture(resolveRefFsFixtureData as FsFixtureData)
// act
const ref = await resolveRef({ fs, dir, ref: 'HEAD' })
// assert
expect(ref).toBe('033417ae18b174f078f2f44232cb7a374f4c60ce')
})
it('HEAD depth', async () => {
// arrange
const { fs, dir } = await makeFsFixture(resolveRefFsFixtureData as FsFixtureData)
// act
const ref = await resolveRef({ fs, dir, ref: 'HEAD', depth: 2 })
// assert
expect(ref).toBe('refs/heads/main')
})
it('packed-refs', async () => {
// arrange
const { fs, dir } = await makeFsFixture(resolveRefFsFixtureData as FsFixtureData)
// act
const ref = await resolveRef({ fs, dir, ref: 'v0.0.1' })
// assert
expect(ref).toBe('1a2149e96a9767b281a8f10fd014835322da2d14')
})
it('non-existant refs', async () => {
// arrange
const { fs, dir } = await makeFsFixture(resolveRefFsFixtureData as FsFixtureData)
// act
const action = async () => {
await resolveRef({ fs, dir, ref: 'this-is-not-a-ref' })
}
// assert
await expectToFailWithTypeAsync(action, NotFoundError)
})
})