Repository navigation
Expand file tree
/
Copy pathcli.test.js
More file actions
80 lines (69 loc) · 1.76 KB
/
Copy pathcli.test.js
File metadata and controls
80 lines (69 loc) · 1.76 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
import { describe, it, expect, vi, beforeEach } from 'vitest'
import meow from 'meow'
// Mock the gitPushPR module
vi.mock('./index.js', () => ({
default: vi.fn()
}))
// Mock meow
vi.mock('meow', () => ({
default: vi.fn(() => ({
flags: {
remote: 'origin',
allowAll: false,
silent: false,
force: false,
verify: true
}
}))
}))
// Ensure process.exit is mocked to prevent accidental exits during CLI import
let exitSpy
beforeEach(() => {
exitSpy = vi.spyOn(process, 'exit').mockImplementation((code) => {
throw new Error(`process.exit unexpectedly called with "${code}"`)
})
})
afterEach(() => {
exitSpy.mockRestore()
})
describe('CLI', () => {
beforeEach(() => {
vi.resetModules()
vi.clearAllMocks()
})
it('should pass flags from meow to gitPushPR', async () => {
// Import CLI which will immediately call gitPushPR
const gitPushPR = (await import('./index.js')).default
await import('./cli.js')
// Verify gitPushPR was called with the flags from meow
expect(gitPushPR).toHaveBeenCalledWith({
remote: 'origin',
allowAll: false,
silent: false,
force: false,
verify: true
})
})
it('should pass custom flags to gitPushPR', async () => {
// Mock meow to return custom flags
meow.mockReturnValueOnce({
flags: {
remote: 'upstream',
allowAll: true,
silent: true,
force: true,
verify: false
}
})
const gitPushPR = (await import('./index.js')).default
await import('./cli.js')
// Verify gitPushPR was called with the custom flags
expect(gitPushPR).toHaveBeenCalledWith({
remote: 'upstream',
allowAll: true,
silent: true,
force: true,
verify: false
})
})
})