Skip to content

Commit 362cc90

Browse files
committed
test: add comprehensive tests for formatVersionChange method
- Add 15 test cases covering all constraint prefix scenarios: - Caret (^), tilde (~), >=, <, <= constraint prefixes - Versions without constraint prefixes - Edge cases like empty versions and complex identifiers - Real-world examples from the reported issue (zip/unzip packages) - Tests verify proper constraint preservation (^6.0 → ^6.0.0) - Covers npm range constraints and pre-release versions - All 37 tests in pr-generator.test.ts now pass
1 parent 14de83e commit 362cc90

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

test/pr-generator.test.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,4 +409,102 @@ describe('PullRequestGenerator', () => {
409409
expect(generator.generateTitle(updateWithoutMetadata)).toBeDefined()
410410
})
411411
})
412+
413+
describe('formatVersionChange', () => {
414+
// Access the private method for testing
415+
const formatVersionChange = (generator as any).formatVersionChange.bind(generator)
416+
417+
describe('constraint prefixes', () => {
418+
it('should preserve caret constraint prefix', () => {
419+
const result = formatVersionChange('^3.0', '3.0.0')
420+
expect(result).toBe('`^3.0` → `^3.0.0`')
421+
})
422+
423+
it('should preserve tilde constraint prefix', () => {
424+
const result = formatVersionChange('~2.1', '2.1.5')
425+
expect(result).toBe('`~2.1` → `~2.1.5`')
426+
})
427+
428+
it('should preserve greater than or equal constraint prefix', () => {
429+
const result = formatVersionChange('>=1.5.0', '1.6.0')
430+
expect(result).toBe('`>=1.5.0` → `>=1.6.0`')
431+
})
432+
433+
it('should preserve less than constraint prefix', () => {
434+
const result = formatVersionChange('<2.0.0', '1.9.0')
435+
expect(result).toBe('`<2.0.0` → `<1.9.0`')
436+
})
437+
438+
it('should preserve multiple character constraint prefix', () => {
439+
const result = formatVersionChange('<=4.2.1', '4.1.0')
440+
expect(result).toBe('`<=4.2.1` → `<=4.1.0`')
441+
})
442+
443+
it('should handle complex constraint with version prefix', () => {
444+
const result = formatVersionChange('^v1.2.3', 'v1.2.4')
445+
expect(result).toBe('`^v1.2.3` → `^v1.2.4`')
446+
})
447+
})
448+
449+
describe('no constraint prefix', () => {
450+
it('should handle versions without constraint prefix', () => {
451+
const result = formatVersionChange('1.0.0', '1.0.1')
452+
expect(result).toBe('`1.0.0` → `1.0.1`')
453+
})
454+
455+
it('should handle semantic versions without prefix', () => {
456+
const result = formatVersionChange('2.15.4', '2.16.0')
457+
expect(result).toBe('`2.15.4` → `2.16.0`')
458+
})
459+
460+
it('should handle version with v prefix but no constraint', () => {
461+
const result = formatVersionChange('v3.1.0', 'v3.2.0')
462+
expect(result).toBe('`v3.1.0` → `v3.2.0`')
463+
})
464+
})
465+
466+
describe('edge cases', () => {
467+
it('should handle empty versions gracefully', () => {
468+
const result = formatVersionChange('', '')
469+
expect(result).toBe('`` → ``')
470+
})
471+
472+
it('should handle mixed constraint formats', () => {
473+
const result = formatVersionChange('^6.0', '6.0.0')
474+
expect(result).toBe('`^6.0` → `^6.0.0`')
475+
})
476+
477+
it('should handle pre-release versions with constraints', () => {
478+
const result = formatVersionChange('^1.0.0-alpha', '1.0.0-beta')
479+
expect(result).toBe('`^1.0.0-alpha` → `^1.0.0-beta`')
480+
})
481+
482+
it('should handle complex version identifiers', () => {
483+
const result = formatVersionChange('~2.1.0-rc.1', '2.1.0-rc.2')
484+
expect(result).toBe('`~2.1.0-rc.1` → `~2.1.0-rc.2`')
485+
})
486+
487+
it('should handle npm range constraints', () => {
488+
const result = formatVersionChange('^18.0.0 || ^19.0.0', '19.1.0')
489+
expect(result).toBe('`^18.0.0 || ^19.0.0` → `^19.1.0`')
490+
})
491+
})
492+
493+
describe('real-world examples from issue', () => {
494+
it('should correctly format zip package constraint update', () => {
495+
const result = formatVersionChange('^3.0', '3.0.0')
496+
expect(result).toBe('`^3.0` → `^3.0.0`')
497+
})
498+
499+
it('should correctly format unzip package constraint update', () => {
500+
const result = formatVersionChange('^6.0', '6.0.0')
501+
expect(result).toBe('`^6.0` → `^6.0.0`')
502+
})
503+
504+
it('should handle info-zip.org packages correctly', () => {
505+
const result = formatVersionChange('^6.0', '6.0.0')
506+
expect(result).toBe('`^6.0` → `^6.0.0`')
507+
})
508+
})
509+
})
412510
})

0 commit comments

Comments
 (0)