|
| 1 | +import type { ResolvedDependencyInfo } from '#types/context' |
1 | 2 | import { describe, expect, it } from 'vitest' |
2 | 3 | import { formatUpgradeVersion } from '../../src/utils/version' |
3 | 4 |
|
4 | 5 | describe('formatUpgradeVersion', () => { |
5 | | - it('should preserve ^ prefix', () => { |
6 | | - expect(formatUpgradeVersion({ protocol: 'npm', resolvedName: 'foo', rawName: 'foo', resolvedSpec: '^1.0.0', rawSpec: '^1.0.0' }, '2.0.0')).toBe('^2.0.0') |
7 | | - }) |
8 | | - |
9 | | - it('should preserve ~ prefix', () => { |
10 | | - expect(formatUpgradeVersion({ protocol: 'npm', resolvedName: 'foo', rawName: 'foo', resolvedSpec: '~1.0.0', rawSpec: '~1.0.0' }, '1.1.0')).toBe('~1.1.0') |
11 | | - }) |
12 | | - |
13 | | - it('should handle pinned version', () => { |
14 | | - expect(formatUpgradeVersion({ protocol: 'npm', resolvedName: 'foo', rawName: 'foo', resolvedSpec: '1.0.0', rawSpec: '1.0.0' }, '2.0.0')).toBe('2.0.0') |
15 | | - }) |
16 | | - |
17 | | - it('should preserve >= prefix', () => { |
18 | | - expect(formatUpgradeVersion({ protocol: 'npm', resolvedName: 'foo', rawName: 'foo', resolvedSpec: '>=1.0.0', rawSpec: '>=1.0.0' }, '2.0.0')).toBe('>=2.0.0') |
19 | | - }) |
20 | | - |
21 | | - it('should return * for wildcard', () => { |
22 | | - expect(formatUpgradeVersion({ protocol: 'npm', resolvedName: 'foo', rawName: 'foo', resolvedSpec: '*', rawSpec: '*' }, '2.0.0')).toBe('*') |
23 | | - }) |
24 | | - |
25 | | - it('should return * for empty semver', () => { |
26 | | - expect(formatUpgradeVersion({ protocol: 'npm', resolvedName: 'foo', rawName: 'foo', resolvedSpec: '', rawSpec: '' }, '2.0.0')).toBe('*') |
27 | | - }) |
28 | | - |
29 | | - it('should handle x-range major wildcard', () => { |
30 | | - expect(formatUpgradeVersion({ protocol: 'npm', resolvedName: 'foo', rawName: 'foo', resolvedSpec: 'x', rawSpec: 'x' }, '2.0.0')).toBe('*') |
31 | | - }) |
32 | | - |
33 | | - it('should handle x-range minor wildcard as ^', () => { |
34 | | - expect(formatUpgradeVersion({ protocol: 'npm', resolvedName: 'foo', rawName: 'foo', resolvedSpec: '1.x', rawSpec: '1.x' }, '2.0.0')).toBe('^2.0.0') |
35 | | - }) |
36 | | - |
37 | | - it('should handle x-range patch wildcard as ~', () => { |
38 | | - expect(formatUpgradeVersion({ protocol: 'npm', resolvedName: 'foo', rawName: 'foo', resolvedSpec: '1.0.x', rawSpec: '1.0.x' }, '1.1.0')).toBe('~1.1.0') |
39 | | - }) |
40 | | - |
41 | | - it('should include protocol in result', () => { |
42 | | - expect(formatUpgradeVersion({ protocol: 'npm', resolvedName: 'foo', rawName: 'foo', resolvedSpec: '^1.0.0', rawSpec: 'npm:^1.0.0' }, '2.0.0')).toBe('npm:^2.0.0') |
43 | | - }) |
44 | | - |
45 | | - it('should handle pinned version with protocol', () => { |
46 | | - expect(formatUpgradeVersion({ protocol: 'npm', resolvedName: 'foo', rawName: 'foo', resolvedSpec: '1.0.0', rawSpec: 'npm:1.0.0' }, '2.0.0')).toBe('npm:2.0.0') |
47 | | - }) |
48 | | - |
49 | | - it('should preserve protocol for wildcard', () => { |
50 | | - expect(formatUpgradeVersion({ protocol: 'npm', resolvedName: 'foo', rawName: 'foo', resolvedSpec: '*', rawSpec: 'npm:*' }, '2.0.0')).toBe('npm:*') |
51 | | - }) |
52 | | - |
53 | | - it('should preserve alias name in formatted version', () => { |
54 | | - expect(formatUpgradeVersion({ protocol: 'npm', resolvedName: 'lodash', rawName: 'my-lodash', resolvedSpec: '~3.0.0', rawSpec: 'npm:lodash@~3.0.0' }, '4.0.0')).toBe('npm:lodash@~4.0.0') |
| 6 | + it.each([ |
| 7 | + [['^1.0.0'], '2.0.0', '^2.0.0'], |
| 8 | + [['~1.0.0'], '1.1.0', '~1.1.0'], |
| 9 | + [['1.0.0'], '2.0.0', '2.0.0'], |
| 10 | + [['1.x'], '2.0.0', '^2.0.0'], |
| 11 | + [['1.0.x'], '1.1.0', '~1.1.0'], |
| 12 | + [['>=1.0.0'], '2.0.0', '>=2.0.0'], |
| 13 | + [['*'], '2.0.0', '*'], |
| 14 | + [[''], '2.0.0', '*'], |
| 15 | + [['x'], '2.0.0', '*'], |
| 16 | + [['^1.0.0', 'npm:foo@^1.0.0'], '2.0.0', '^2.0.0'], |
| 17 | + [['1.0.0', 'npm:foo@1.0.0'], '2.0.0', '2.0.0'], |
| 18 | + [['*', 'npm:foo@*'], '2.0.0', '*'], |
| 19 | + [['^1.0.0', 'npm:foo@^1.0.0', 'my-foo'], '2.0.0', 'npm:foo@^2.0.0'], |
| 20 | + ])('should preserve $0', ([resolvedSpec, rawSpec = resolvedSpec, rawName = 'foo', protocol = 'npm'], target, expected) => { |
| 21 | + expect( |
| 22 | + formatUpgradeVersion({ protocol, rawName, rawSpec, resolvedName: 'foo', resolvedSpec } as ResolvedDependencyInfo, target), |
| 23 | + ).toBe(expected) |
55 | 24 | }) |
56 | 25 | }) |
0 commit comments