-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdoctor.test.ts
More file actions
72 lines (61 loc) · 1.93 KB
/
doctor.test.ts
File metadata and controls
72 lines (61 loc) · 1.93 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
import { jest } from '@jest/globals';
import { execa } from 'execa';
// Mock execa
jest.mock('execa');
const mockedExeca = execa as jest.MockedFunction<typeof execa>;
describe('doctor command', () => {
beforeEach(() => {
jest.clearAllMocks();
// Mock process.version
Object.defineProperty(process, 'version', {
value: 'v20.0.0',
writable: true,
});
});
it('should pass all checks when requirements are met', async () => {
// Mock successful corepack and gh commands
mockedExeca.mockResolvedValue({
stdout: 'gh version 2.0.0',
stderr: '',
exitCode: 0,
} as any);
const { runDoctor } = await import('../doctor.js');
await expect(runDoctor(false)).resolves.not.toThrow();
});
it('should detect when Node.js version is too old', async () => {
Object.defineProperty(process, 'version', {
value: 'v18.0.0',
writable: true,
});
const { runDoctor } = await import('../doctor.js');
await expect(runDoctor(false)).resolves.not.toThrow();
});
it('should detect when corepack is not enabled', async () => {
mockedExeca.mockImplementation((command: string) => {
if (command === 'corepack') {
throw new Error('Command not found');
}
return Promise.resolve({
stdout: 'gh version 2.0.0',
stderr: '',
exitCode: 0,
} as any);
});
const { runDoctor } = await import('../doctor.js');
await expect(runDoctor(false)).resolves.not.toThrow();
});
it('should detect when GitHub CLI is not installed', async () => {
mockedExeca.mockImplementation((command: string) => {
if (command === 'gh') {
throw new Error('Command not found');
}
return Promise.resolve({
stdout: '0.28.0',
stderr: '',
exitCode: 0,
} as any);
});
const { runDoctor } = await import('../doctor.js');
await expect(runDoctor(false)).resolves.not.toThrow();
});
});