forked from aws/agentcore-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.test.ts
More file actions
70 lines (59 loc) · 1.98 KB
/
cli.test.ts
File metadata and controls
70 lines (59 loc) · 1.98 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
import { createProgram } from '../cli.js';
import { PACKAGE_VERSION } from '../constants.js';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
describe('CLI version flag', () => {
let mockExit: ReturnType<typeof vi.spyOn>;
let mockStdoutWrite: ReturnType<typeof vi.spyOn>;
let stdoutOutput: string;
beforeEach(() => {
stdoutOutput = '';
mockExit = vi.spyOn(process, 'exit').mockImplementation(() => {
throw new Error('process.exit called');
});
mockStdoutWrite = vi.spyOn(process.stdout, 'write').mockImplementation((chunk: string | Uint8Array) => {
stdoutOutput += chunk.toString();
return true;
});
});
afterEach(() => {
mockExit.mockRestore();
mockStdoutWrite.mockRestore();
});
it('should output version with --version flag', async () => {
const program = createProgram();
program.configureOutput({
writeOut: (str: string) => {
stdoutOutput += str;
},
});
try {
await program.parseAsync(['node', 'agentcore', '--version']);
} catch {
// Expected: process.exit is called
}
expect(stdoutOutput).toContain(PACKAGE_VERSION);
expect(mockExit).toHaveBeenCalledWith(0);
});
it('should output version with -V flag', async () => {
const program = createProgram();
program.configureOutput({
writeOut: (str: string) => {
stdoutOutput += str;
},
});
try {
await program.parseAsync(['node', 'agentcore', '-V']);
} catch {
// Expected: process.exit is called
}
expect(stdoutOutput).toContain(PACKAGE_VERSION);
expect(mockExit).toHaveBeenCalledWith(0);
});
it('should have version option configured correctly', () => {
const program = createProgram();
const versionOption = program.options.find(opt => opt.long === '--version');
expect(versionOption).toBeDefined();
expect(versionOption?.short).toBe('-V');
expect(versionOption?.description).toBe('Output the current version');
});
});