From 15b95eb434e39772de7040cb60445e35248e0892 Mon Sep 17 00:00:00 2001 From: Sebastian G Date: Tue, 1 Sep 2026 09:09:45 +0200 Subject: [PATCH] test: derive update-check versions from __APP_VERSION__ instead of hardcoding The semver comparison tests hardcoded v1.2.11-relative versions, so they broke when package.json bumped to 1.2.14. Derive test versions from the running __APP_VERSION__ so the suite stays correct across version bumps. --- frontend/src/lib/update.test.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/frontend/src/lib/update.test.js b/frontend/src/lib/update.test.js index feff942..60a2fa9 100644 --- a/frontend/src/lib/update.test.js +++ b/frontend/src/lib/update.test.js @@ -178,29 +178,42 @@ describe('semver comparison (via checkForUpdate behavior)', () => { })) } - // __APP_VERSION__ is "1.2.11" — test that patch, minor, and major bumps are detected + // Versions are derived from the running __APP_VERSION__ so the suite never breaks + // when package.json bumps. bump(2, +1) raises the patch; bump(0, +1) raises the major. + const [MAJ, MIN, PATCH] = __APP_VERSION__.split('.').map(Number) + const bump = (idx, by) => { + const parts = [MAJ, MIN, PATCH] + parts[idx] += by + return 'v' + parts.join('.') + } + it('detects a patch bump as an update', async () => { - mockRelease('v1.2.12') + mockRelease(bump(2, 1)) expect((await checkForUpdate()).hasUpdate).toBe(true) }) it('detects a minor bump as an update', async () => { - mockRelease('v1.3.0') + mockRelease(bump(1, 1)) expect((await checkForUpdate()).hasUpdate).toBe(true) }) it('detects a major bump as an update', async () => { - mockRelease('v2.0.0') + mockRelease(bump(0, 1)) expect((await checkForUpdate()).hasUpdate).toBe(true) }) it('does not flag an older patch as an update', async () => { - mockRelease('v1.2.10') + // One patch below current (current patch is always >= our test floor) + mockRelease('v' + [MAJ, MIN, Math.max(0, PATCH - 1)].join('.')) + // Only meaningful when we could actually go lower; when patch is 0 this equals current, + // which correctly reports no update either way. expect((await checkForUpdate()).hasUpdate).toBe(false) }) it('does not flag an older minor as an update', async () => { - mockRelease('v1.1.99') + // A version guaranteed lower than any 1.x+ release: same major, minor 0, patch 0, + // minus one on the minor when possible. + mockRelease('v' + [MAJ, Math.max(0, MIN - 1), 0].join('.')) expect((await checkForUpdate()).hasUpdate).toBe(false) }) })