|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | +import { |
| 3 | + resolveNextStableVersion, |
| 4 | + updateLockfileWorkspaceVersion, |
| 5 | +} from './bump-npm-package-versions' |
| 6 | + |
| 7 | +describe('resolveNextStableVersion', () => { |
| 8 | + it('increments the highest published stable patch and ignores prereleases', () => { |
| 9 | + expect( |
| 10 | + resolveNextStableVersion('2.1.2', [ |
| 11 | + '2.1.3-preview.10.1', |
| 12 | + '1.9.9', |
| 13 | + '2.1.2', |
| 14 | + '2.1.3-dev.11.1', |
| 15 | + '2.0.8', |
| 16 | + ]) |
| 17 | + ).toBe('2.1.3') |
| 18 | + }) |
| 19 | + |
| 20 | + it('preserves a higher unpublished manifest version', () => { |
| 21 | + expect(resolveNextStableVersion('3.0.0', ['2.1.2', '2.1.3-preview.10.1'])).toBe('3.0.0') |
| 22 | + }) |
| 23 | + |
| 24 | + it('advances from the registry when the manifest is stale', () => { |
| 25 | + expect(resolveNextStableVersion('1.5.0', ['2.0.0', '2.1.2'])).toBe('2.1.3') |
| 26 | + }) |
| 27 | + |
| 28 | + it('fails on a prerelease manifest or a registry without a stable version', () => { |
| 29 | + expect(() => resolveNextStableVersion('2.1.3-preview.1', ['2.1.2'])).toThrow( |
| 30 | + "Manifest version must be a stable X.Y.Z version, got '2.1.3-preview.1'" |
| 31 | + ) |
| 32 | + expect(() => resolveNextStableVersion('2.1.3', ['2.1.3-preview.1'])).toThrow( |
| 33 | + 'npm returned no published stable versions' |
| 34 | + ) |
| 35 | + }) |
| 36 | +}) |
| 37 | + |
| 38 | +describe('updateLockfileWorkspaceVersion', () => { |
| 39 | + const lockfile = `{ |
| 40 | + "workspaces": { |
| 41 | + "packages/sim-cli": { |
| 42 | + "name": "sim", |
| 43 | + "version": "2.1.2", |
| 44 | + }, |
| 45 | + "packages/sim-setup": { |
| 46 | + "name": "sim-setup", |
| 47 | + "version": "1.0.2", |
| 48 | + }, |
| 49 | + }, |
| 50 | +}` |
| 51 | + |
| 52 | + it('updates only the selected workspace', () => { |
| 53 | + const next = updateLockfileWorkspaceVersion( |
| 54 | + lockfile, |
| 55 | + 'packages/sim-cli', |
| 56 | + 'sim', |
| 57 | + '2.1.2', |
| 58 | + '2.1.3' |
| 59 | + ) |
| 60 | + |
| 61 | + expect(next).toContain('"version": "2.1.3"') |
| 62 | + expect(next).toContain('"version": "1.0.2"') |
| 63 | + expect(next).not.toContain('"version": "2.1.2"') |
| 64 | + }) |
| 65 | + |
| 66 | + it('fails when the lockfile disagrees with the manifest', () => { |
| 67 | + expect(() => |
| 68 | + updateLockfileWorkspaceVersion(lockfile, 'packages/sim-cli', 'sim', '2.1.1', '2.1.3') |
| 69 | + ).toThrow("bun.lock must contain exactly one sim@2.1.1 entry in 'packages/sim-cli'") |
| 70 | + }) |
| 71 | +}) |
0 commit comments