// Behaviour of the update service with the real electron-updater inside Electron (see // test/fixtures/update-harness.cjs). Needs a display on Linux (CI runs it under xvfb-run). import test from 'node:test'; import assert from 'node:assert/strict'; import { runUpdateHarness } from './fixtures/run-update-harness.mjs'; const noDisplay = process.platform === 'linux' && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY; test('update service + electron-updater behaviour against an emulated Gitea release server', { skip: noDisplay && 'no display (run under xvfb-run)', timeout: 180000 }, async (t) => { const r = await runUpdateHarness({ version: '0.1.2-rc.1' }); for (const [name, v] of Object.entries(r)) if (v && v.thrown) assert.fail(`${name}: ${v.thrown}`); assert.equal(r.version, '0.1.2-rc.1'); await t.test('newest eligible release is found, downloaded and sha512-verified; drafts untouched; no credentials', () => { assert.equal(r.happy.phase, 'downloaded'); assert.equal(r.happy.available, '0.1.2-rc.2'); assert.equal(r.happy.cachedShaMatches, true); assert.equal(r.happy.draftFetched, false); assert.equal(r.happy.anyAuth, false); }); await t.test('in a call: background download waits, install needs explicit confirmation', () => { assert.equal(r.sessionGate.deferred, 'deferred'); assert.equal(r.sessionGate.packageRequestedWhileDeferred, false); assert.equal(r.sessionGate.downloaded, 'downloaded'); assert.deepEqual(r.sessionGate.install, { ok: false, code: 'session-active' }); assert.equal(r.sessionGate.stillDownloaded, 'downloaded'); }); await t.test('corrupt package: checksum error, nothing installable', () => { assert.equal(r.checksum.phase, 'error'); assert.equal(r.checksum.error.code, 'checksum'); assert.equal(r.checksum.install.code, 'not-ready'); }); await t.test('feed pointing at the other architecture is skipped in favour of an older complete release', () => { assert.equal(r.wrongArch.phase, 'downloaded'); assert.equal(r.wrongArch.available, '0.1.2-rc.2'); assert.deepEqual(r.wrongArch.newerWithoutBuild.map((x) => [x.version, x.code]), [['0.1.3', 'feed-mismatch']]); }); await t.test('feed listed but not downloadable: skipped, reported, up to date otherwise', () => { assert.equal(r.missingFeedFile.phase, 'up-to-date'); assert.deepEqual(r.missingFeedFile.newerWithoutBuild.map((x) => [x.version, x.code]), [['0.1.3', 'incomplete-release']]); }); await t.test('feed timeout is an error; its late answer cannot change the next offer or download', () => { assert.equal(r.timeoutThenLateResult.timedOut.phase, 'error'); assert.equal(r.timeoutThenLateResult.timedOut.error.code, 'timeout'); assert.equal(r.timeoutThenLateResult.timedOut.lastCheckedAt, null); assert.equal(r.timeoutThenLateResult.second.phase, 'downloaded'); assert.equal(r.timeoutThenLateResult.second.available, '0.1.2-rc.2'); assert.equal(r.timeoutThenLateResult.afterLate.phase, 'downloaded'); assert.equal(r.timeoutThenLateResult.afterLate.available, '0.1.2-rc.2'); assert.deepEqual(r.timeoutThenLateResult.install, { ok: false, code: 'session-active' }); }); await t.test('release server unreachable: error, never "up to date"', () => { assert.equal(r.networkDown.phase, 'error'); assert.equal(r.networkDown.error.code, 'network'); assert.equal(r.networkDown.lastCheckedAt, null); }); await t.test('stable channel ignores previews and says which one exists', () => { assert.equal(r.stableChannel.phase, 'up-to-date'); assert.equal(r.stableChannel.newerPreview, '0.1.3'); }); await t.test('custom profile: NSIS never installs (Explorer relaunch would drop the profile); AppImage keeps its env', () => { const c = r.customProfile; assert.equal(c.available, '0.1.2-rc.2'); if (c.target === 'nsis') { assert.equal(c.mode, 'manual'); assert.equal(c.manualReason, 'custom-profile'); assert.equal(c.phase, 'available'); assert.equal(c.afterManualDownload, 'available'); assert.equal(c.packageRequested, false); assert.deepEqual(c.install, { ok: false, code: 'custom-profile' }); assert.deepEqual(c.installCalls, []); assert.equal(c.quits, 0); } else { assert.equal(c.mode, 'auto'); assert.equal(c.manualReason, null); assert.equal(c.phase, 'downloaded'); assert.deepEqual(c.install, { ok: true }); assert.deepEqual(c.installCalls, [[true, false]]); assert.deepEqual(c.relaunches, [{ execPathIsAppImage: true }]); } }); await t.test('same version, older versions and older prereleases are not even fetched', () => { assert.equal(r.sameAndOlder.phase, 'up-to-date'); assert.equal(r.sameAndOlder.feedRequests, 0); }); });