|
| 1 | +import { maxSatisfying as semverMaxSatisfying } from 'semver'; |
| 2 | +import { canaryBaseVersion } from './canary-version.js'; |
| 3 | +import 'jasmine'; |
| 4 | + |
| 5 | +/* What's on npm today: a placeholder, v20 releases, rc.1, canaries named after the rc series |
| 6 | + * (deprecated), and canaries named after 21.0.0. */ |
| 7 | +const publishedToday = [ |
| 8 | + '0.0.0', |
| 9 | + '20.0.0', |
| 10 | + '20.1.0', |
| 11 | + '21.0.0-rc.0', |
| 12 | + '21.0.0-rc.0-canary.fb6796b', |
| 13 | + '21.0.0-rc.1', |
| 14 | + '21.0.0-rc.1-canary.95b3de1', |
| 15 | + '21.0.0-canary.a2662fe', |
| 16 | + '21.0.0-canary.20260930011755.sha-59d44e7', |
| 17 | +]; |
| 18 | + |
| 19 | +const canaryNamedAfter = (base: string) => `${base}-canary.20261001000000.sha-abcdef0`; |
| 20 | + |
| 21 | +describe('canaryBaseVersion', () => { |
| 22 | + |
| 23 | + it('names the canary one patch above the release candidate', () => { |
| 24 | + expect(canaryBaseVersion('21.0.0', publishedToday)).toBe('21.0.1'); |
| 25 | + }); |
| 26 | + |
| 27 | + it('names the canary one patch above the release once it ships', () => { |
| 28 | + expect(canaryBaseVersion('21.0.0', [...publishedToday, '21.0.0'])).toBe('21.0.1'); |
| 29 | + expect(canaryBaseVersion('21.0.0', [...publishedToday, '21.0.0', '21.0.1'])).toBe('21.0.2'); |
| 30 | + }); |
| 31 | + |
| 32 | + it('names the canary above a minor or patch release candidate', () => { |
| 33 | + expect(canaryBaseVersion('21.0.0', [...publishedToday, '21.0.0', '21.1.0-rc.0'])).toBe('21.1.1'); |
| 34 | + expect(canaryBaseVersion('21.0.0', [...publishedToday, '21.0.0', '21.0.1-rc.0'])).toBe('21.0.2'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('does not count earlier canaries', () => { |
| 38 | + const published = [...publishedToday, canaryNamedAfter('21.0.1'), canaryNamedAfter('21.0.1')]; |
| 39 | + expect(canaryBaseVersion('21.0.0', published)).toBe('21.0.1'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('ignores releases from other majors', () => { |
| 43 | + expect(canaryBaseVersion('21.0.0', [...publishedToday, '21.0.0', '20.0.4'])).toBe('21.0.1'); |
| 44 | + expect(canaryBaseVersion('21.0.0', [...publishedToday, '21.0.0', '22.0.0-rc.0'])).toBe('21.0.1'); |
| 45 | + }); |
| 46 | + |
| 47 | + it('uses the package.json version when nothing in its major is published yet', () => { |
| 48 | + expect(canaryBaseVersion('22.0.0-rc.0', publishedToday)).toBe('22.0.0'); |
| 49 | + expect(canaryBaseVersion('22.0.0-rc.0', [...publishedToday, '22.0.0-rc.0'])).toBe('22.0.1'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('throws when the package.json version has no version number in it', () => { |
| 53 | + expect(() => canaryBaseVersion('abc', publishedToday)).toThrowError(TypeError); |
| 54 | + }); |
| 55 | + |
| 56 | + it('gives a canary that its own caret range selects, and that release ranges never select', () => { |
| 57 | + const states = [ |
| 58 | + publishedToday, |
| 59 | + [...publishedToday, '21.0.0'], |
| 60 | + [...publishedToday, '21.0.0', '21.0.1'], |
| 61 | + [...publishedToday, '21.0.0', '21.1.0-rc.0'], |
| 62 | + [...publishedToday, '21.0.0', '21.0.1-rc.0'], |
| 63 | + ]; |
| 64 | + for (const published of states) { |
| 65 | + const canary = canaryNamedAfter(canaryBaseVersion('21.0.0', published)); |
| 66 | + const versions = [...published, canary]; |
| 67 | + expect(semverMaxSatisfying(versions, `^${canary}`)).toBe(canary); |
| 68 | + for (const range of ['^21.0.0', '~21.0.0', '^21.0.0-rc.1', '^20.0.0']) { |
| 69 | + expect(semverMaxSatisfying(versions, range)).not.toBe(canary); |
| 70 | + } |
| 71 | + } |
| 72 | + }); |
| 73 | + |
| 74 | +}); |
0 commit comments