Files
openchamber/packages/electron/updater-check.test.mjs
T

48 lines
1.7 KiB
JavaScript
Raw Normal View History

import assert from 'node:assert/strict';
import test from 'node:test';
import { checkForDesktopUpdate } from './updater-check.mjs';
const compareVersions = (left, right) => left.localeCompare(right, undefined, { numeric: true });
test('signals failed checks without replacing an existing pending update', async () => {
const pendingUpdate = { version: '2.0.0', electronUpdate: { id: 'existing' } };
await assert.rejects(
checkForDesktopUpdate({
autoUpdater: { checkForUpdates: async () => { throw new Error('feed unavailable'); } },
currentVersion: '1.0.0',
pendingUpdate,
compareVersions,
}),
/Unable to check for updates: feed unavailable.*network connection/,
);
assert.deepEqual(pendingUpdate, { version: '2.0.0', electronUpdate: { id: 'existing' } });
});
test('treats missing update feed (404) as no update available', async () => {
const result = await checkForDesktopUpdate({
autoUpdater: {
checkForUpdates: async () => {
throw new Error('HttpError: 404 Not Found "https://github.com/.../latest-linux.yml"');
},
},
currentVersion: '1.15.0',
pendingUpdate: { version: '1.16.0' },
compareVersions,
});
assert.equal(result.available, false);
assert.equal(result.pendingUpdate, null);
assert.equal(result.nextVersion, '1.15.0');
});
test('authoritative no-update result clears pending update', async () => {
const result = await checkForDesktopUpdate({
autoUpdater: { checkForUpdates: async () => ({ updateInfo: { version: '1.0.0' } }) },
currentVersion: '1.0.0',
pendingUpdate: { version: '2.0.0' },
compareVersions,
});
assert.equal(result.available, false);
assert.equal(result.pendingUpdate, null);
});