Updater from public releases, English UI by default with Russian selectable, cancelable capture, English technical messages, language-independent smoke hooks
This commit is contained in:
1 parent
ba4c7ec2af
commit
1142c9f60d
53 files changed
+4005
-549
No files matched your search
@@ -0,0 +1,120 @@
|
||||
// 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 { spawn } from 'node:child_process';
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import { createRequire } from 'node:module';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const repo = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const noDisplay = process.platform === 'linux' && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY;
|
||||
|
||||
async function runHarness() {
|
||||
const tmp = mkdtempSync(path.join(os.tmpdir(), 'teamspeach-update-'));
|
||||
try {
|
||||
const appDir = path.join(tmp, 'app');
|
||||
const cache = path.join(tmp, 'cache');
|
||||
for (const d of [appDir, cache]) mkdirSync(d, { recursive: true });
|
||||
// The running version comes from this package.json (app.getVersion()).
|
||||
writeFileSync(path.join(appDir, 'package.json'), JSON.stringify({ name: 'teamspeach-update-harness', version: '0.1.2-rc.1', main: 'main.js' }));
|
||||
writeFileSync(path.join(appDir, 'main.js'), `require(${JSON.stringify(path.join(repo, 'test', 'fixtures', 'update-harness.cjs'))});\n`);
|
||||
const oldAppImage = path.join(tmp, 'TeamsPeach-0.1.2-rc.1.AppImage');
|
||||
writeFileSync(oldAppImage, 'old');
|
||||
const args = [appDir];
|
||||
if (process.platform === 'linux') args.push('--no-sandbox');
|
||||
const env = {
|
||||
...process.env,
|
||||
UPDATE_HARNESS_REPO: repo,
|
||||
UPDATE_HARNESS_TMP: tmp,
|
||||
// electron-updater's download cache lives under these; keep it inside the temp dir.
|
||||
LOCALAPPDATA: cache,
|
||||
XDG_CACHE_HOME: cache,
|
||||
APPIMAGE: oldAppImage,
|
||||
ELECTRON_ENABLE_LOGGING: '',
|
||||
};
|
||||
delete env.ELECTRON_RUN_AS_NODE;
|
||||
const child = spawn(require('electron'), args, { env, stdio: ['ignore', 'pipe', 'pipe'] });
|
||||
let out = '';
|
||||
let err = '';
|
||||
child.stdout.on('data', (d) => (out += d));
|
||||
child.stderr.on('data', (d) => (err += d));
|
||||
const timer = setTimeout(() => child.kill(), 120000);
|
||||
const code = await new Promise((r) => child.on('exit', r));
|
||||
clearTimeout(timer);
|
||||
const line = out.split('\n').find((l) => l.startsWith('UPDATE_HARNESS_RESULT '));
|
||||
if (!line) throw new Error(`harness failed (exit ${code}):\n${out}\n${err.slice(-4000)}`);
|
||||
return JSON.parse(line.slice('UPDATE_HARNESS_RESULT '.length));
|
||||
} finally {
|
||||
rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
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 runHarness();
|
||||
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('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);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user