-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathinit-script-version-adb.test.ts
More file actions
87 lines (78 loc) · 3.26 KB
/
init-script-version-adb.test.ts
File metadata and controls
87 lines (78 loc) · 3.26 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
import { log } from '@clack/prompts'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { getVersion } from '../src/utils/get-version'
import { initScriptVersionAdb } from '../src/utils/init-script-version-adb'
import { validateVersion } from '../src/utils/validate-version'
vi.mock('../src/utils/get-version')
vi.mock('../src/utils/validate-version')
vi.mock('@clack/prompts', () => ({
log: {
warn: vi.fn(),
},
}))
describe('initScriptVersionAdb', () => {
beforeEach(() => {
vi.resetAllMocks()
})
afterEach(() => {
vi.clearAllMocks()
})
it('should return early if no required version is provided', async () => {
await initScriptVersionAdb()
expect(getVersion).not.toHaveBeenCalled()
expect(validateVersion).not.toHaveBeenCalled()
expect(log.warn).not.toHaveBeenCalled()
})
it('should log warning if adb version is not found', async () => {
const required = '1.0.0'
vi.mocked(getVersion).mockReturnValue(undefined)
vi.mocked(validateVersion).mockReturnValue({ valid: false, version: undefined })
await initScriptVersionAdb(required)
expect(getVersion).toHaveBeenCalledWith('adb')
expect(validateVersion).toHaveBeenCalledWith({ required, version: undefined })
expect(log.warn).toHaveBeenCalledWith(expect.stringContaining('Could not find adb version. Please install adb.'))
})
it('should log warning if adb version does not satisfy the requirement', async () => {
const required = '1.0.0'
const version = '0.9.0'
vi.mocked(getVersion).mockReturnValue(version)
vi.mocked(validateVersion).mockReturnValue({ valid: false, version })
await initScriptVersionAdb(required)
expect(getVersion).toHaveBeenCalledWith('adb')
expect(validateVersion).toHaveBeenCalledWith({ required, version })
expect(log.warn).toHaveBeenCalledWith(
expect.stringContaining(`Found adb version ${version}. Expected adb version ${required}.`),
)
})
it('should not log warning if adb version satisfies the requirement', async () => {
const required = '1.0.0'
const version = '1.0.0'
vi.mocked(getVersion).mockReturnValue(version)
vi.mocked(validateVersion).mockReturnValue({ valid: true, version })
await initScriptVersionAdb(required)
expect(getVersion).toHaveBeenCalledWith('adb')
expect(validateVersion).toHaveBeenCalledWith({ required, version })
expect(log.warn).not.toHaveBeenCalled()
})
it('should log verbose message if verbose is true', async () => {
const required = '1.0.0'
const version = '1.0.0'
vi.mocked(getVersion).mockReturnValue(version)
vi.mocked(validateVersion).mockReturnValue({ valid: true, version })
await initScriptVersionAdb(required, true)
expect(getVersion).toHaveBeenCalledWith('adb')
expect(validateVersion).toHaveBeenCalledWith({ required, version })
expect(log.warn).toHaveBeenCalledWith(
`initScriptVersionAdb: required: ${required}, version: ${version}, valid: true`,
)
})
it('should log error if an exception occurs', async () => {
const required = '1.0.0'
const error = new Error('Test error')
vi.mocked(getVersion).mockImplementation(() => {
throw error
})
await initScriptVersionAdb(required)
expect(log.warn).toHaveBeenCalledWith(`Error ${error}`)
})
})