Skip to content

Commit f56c0d6

Browse files
added unit tests
1 parent e3b453f commit f56c0d6

File tree

7 files changed

+447
-90
lines changed

7 files changed

+447
-90
lines changed

src/ui/__tests__/version.test.ts

Lines changed: 0 additions & 83 deletions
This file was deleted.
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { getUnknownArgs } from '../getUnknownArgs';
3+
4+
describe('getUnknownArgs', () => {
5+
const validFlags = [
6+
'-h',
7+
'--help',
8+
'-i',
9+
'--info',
10+
'-v',
11+
'--version',
12+
'-l',
13+
'--license',
14+
'-s',
15+
'--skip',
16+
];
17+
18+
it('should return empty array when all args are valid flags', () => {
19+
const args = ['--help', '--version', '-h'];
20+
const result = getUnknownArgs(args, validFlags);
21+
22+
expect(result).toEqual([]);
23+
});
24+
25+
it('should return unknown args when invalid flags are present', () => {
26+
const args = ['--help', '--unknown', '--version'];
27+
const result = getUnknownArgs(args, validFlags);
28+
29+
expect(result).toEqual(['--unknown']);
30+
});
31+
32+
it('should return multiple unknown args', () => {
33+
const args = ['--help', '--unknown1', '--unknown2', '--version'];
34+
const result = getUnknownArgs(args, validFlags);
35+
36+
expect(result).toEqual(['--unknown1', '--unknown2']);
37+
});
38+
39+
it('should return empty array when args array is empty', () => {
40+
const args: string[] = [];
41+
const result = getUnknownArgs(args, validFlags);
42+
43+
expect(result).toEqual([]);
44+
});
45+
46+
it('should return all args when validFlags array is empty', () => {
47+
const args = ['--help', '--version'];
48+
const result = getUnknownArgs(args, []);
49+
50+
expect(result).toEqual(['--help', '--version']);
51+
});
52+
53+
it('should exclude args that come after -s flag', () => {
54+
const args = ['--help', '-s', 'package-to-skip', '--version'];
55+
const result = getUnknownArgs(args, validFlags);
56+
57+
expect(result).toEqual([]);
58+
});
59+
60+
it('should exclude args that come after --skip flag', () => {
61+
const args = ['--help', '--skip', 'package-to-skip', '--version'];
62+
const result = getUnknownArgs(args, validFlags);
63+
64+
expect(result).toEqual([]);
65+
});
66+
67+
it('should exclude multiple args that come after skip flag', () => {
68+
const args = ['--help', '--skip', 'package1', 'package2', '--version'];
69+
const result = getUnknownArgs(args, validFlags);
70+
71+
expect(result).toEqual([]);
72+
});
73+
74+
it('should include unknown args that come before skip flag', () => {
75+
const args = ['--unknown', '--skip', 'package-to-skip', '--version'];
76+
const result = getUnknownArgs(args, validFlags);
77+
78+
expect(result).toEqual(['--unknown']);
79+
});
80+
81+
it('should include unknown args that come after skip flag but are not immediately after', () => {
82+
const args = ['--skip', 'package-to-skip', '--version', '--unknown'];
83+
const result = getUnknownArgs(args, validFlags);
84+
85+
expect(result).toEqual(['--unknown']);
86+
});
87+
88+
it('should handle skip flag at the beginning', () => {
89+
const args = ['-s', 'package-to-skip', '--help', '--version'];
90+
const result = getUnknownArgs(args, validFlags);
91+
92+
expect(result).toEqual([]);
93+
});
94+
95+
it('should handle skip flag at the end', () => {
96+
const args = ['--help', '--version', '-s', 'package-to-skip'];
97+
const result = getUnknownArgs(args, validFlags);
98+
99+
expect(result).toEqual([]);
100+
});
101+
102+
it('should handle multiple skip flags', () => {
103+
const args = [
104+
'--help',
105+
'-s',
106+
'package1',
107+
'--skip',
108+
'package2',
109+
'--version',
110+
];
111+
const result = getUnknownArgs(args, validFlags);
112+
113+
expect(result).toEqual([]);
114+
});
115+
116+
it('should handle skip flag with no following args', () => {
117+
const args = ['--help', '--skip', '--version'];
118+
const result = getUnknownArgs(args, validFlags);
119+
120+
expect(result).toEqual([]);
121+
});
122+
123+
it('should handle skip flag as the last argument', () => {
124+
const args = ['--help', '--version', '--skip'];
125+
const result = getUnknownArgs(args, validFlags);
126+
127+
expect(result).toEqual([]);
128+
});
129+
130+
it('should handle mixed valid and invalid flags with skip logic', () => {
131+
const args = [
132+
'--unknown1',
133+
'--help',
134+
'--skip',
135+
'package-to-skip',
136+
'--unknown2',
137+
'--version',
138+
];
139+
const result = getUnknownArgs(args, validFlags);
140+
141+
expect(result).toEqual(['--unknown1']);
142+
});
143+
144+
it('should handle short flags correctly', () => {
145+
const args = ['-h', '-x', '-v', '-y'];
146+
const result = getUnknownArgs(args, validFlags);
147+
148+
expect(result).toEqual(['-x', '-y']);
149+
});
150+
151+
it('should be case sensitive', () => {
152+
const args = ['--HELP', '--Version', '--unknown'];
153+
const result = getUnknownArgs(args, validFlags);
154+
155+
expect(result).toEqual(['--HELP', '--Version', '--unknown']);
156+
});
157+
158+
it('should handle duplicate valid flags', () => {
159+
const args = ['--help', '--help', '--version'];
160+
const result = getUnknownArgs(args, validFlags);
161+
162+
expect(result).toEqual([]);
163+
});
164+
165+
it('should handle duplicate unknown flags', () => {
166+
const args = ['--help', '--unknown', '--unknown', '--version'];
167+
const result = getUnknownArgs(args, validFlags);
168+
169+
expect(result).toEqual(['--unknown', '--unknown']);
170+
});
171+
172+
it('should handle complex scenario with multiple skip flags and unknown args', () => {
173+
const args = [
174+
'--unknown1',
175+
'--help',
176+
'-s',
177+
'package1',
178+
'--unknown2',
179+
'--skip',
180+
'package2',
181+
'--version',
182+
'--unknown3',
183+
];
184+
const result = getUnknownArgs(args, validFlags);
185+
186+
expect(result).toEqual(['--unknown1', '--unknown3']);
187+
});
188+
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2+
import { getUpdateType } from '../getUpdateType';
3+
4+
describe('getUpdateType', () => {
5+
let warnSpy: ReturnType<typeof vi.spyOn>;
6+
7+
beforeEach(() => {
8+
warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
9+
});
10+
11+
afterEach(() => {
12+
warnSpy.mockRestore();
13+
});
14+
15+
it('should return major for major version updates', () => {
16+
expect(getUpdateType('1.2.3', '2.0.0')).toBe('major');
17+
expect(getUpdateType('1.2.3', '2.1.0')).toBe('major');
18+
});
19+
20+
it('should return minor for minor version updates', () => {
21+
expect(getUpdateType('1.2.3', '1.3.0')).toBe('minor');
22+
expect(getUpdateType('1.2.3', '1.3.5')).toBe('minor');
23+
});
24+
25+
it('should return patch for patch version updates', () => {
26+
expect(getUpdateType('1.2.3', '1.2.4')).toBe('patch');
27+
expect(getUpdateType('1.2.3', '1.2.10')).toBe('patch');
28+
});
29+
30+
it('should return patch for same versions', () => {
31+
expect(getUpdateType('1.2.3', '1.2.3')).toBe('patch');
32+
});
33+
34+
it('should handle version ranges', () => {
35+
expect(getUpdateType('^1.2.3', '2.0.0')).toBe('major');
36+
expect(getUpdateType('~1.2.3', '1.3.0')).toBe('minor');
37+
});
38+
39+
it('should handle invalid version formats', () => {
40+
expect(getUpdateType('invalid', '1.2.3')).toBe('patch');
41+
expect(getUpdateType('1.2.3', 'invalid')).toBe('patch');
42+
});
43+
});

0 commit comments

Comments
 (0)