Files
BetterDesk/web-nodejs/tests/productVersion.test.js
Knienartowicz be17b3077e fix(updates): harden Go binary rebuild version and backup path
Prefer console-local VERSION/package.json for ldflags so a stale root-owned
/opt/VERSION cannot pin rebuilt binaries to an old semver. Fall back binary
backups to a writable data dir when /opt/rustdesk denies bak writes (EACCES).

Thanks: INSOLVE (Honorary); Marco Jakobs (@jacotec); MyNameisStitch (@MyNameisStitch); Redspin (@playerumpknow)
2026-09-18 10:18:35 +02:00

67 lines
2.5 KiB
JavaScript

'use strict';
const fs = require('fs');
const os = require('os');
const path = require('path');
const { readProductVersion } = require('../lib/productVersion');
describe('productVersion', () => {
let tmpRoot;
beforeEach(() => {
tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'bd-version-'));
});
afterEach(() => {
fs.rmSync(tmpRoot, { recursive: true, force: true });
});
test('reads semver from repo-root VERSION', () => {
fs.writeFileSync(path.join(tmpRoot, 'VERSION'), '4.1.2\n');
expect(readProductVersion({ rootDir: tmpRoot })).toBe('4.1.2');
});
test('falls back to package.json when VERSION is missing', () => {
const consoleDir = path.join(tmpRoot, 'web-nodejs');
fs.mkdirSync(consoleDir, { recursive: true });
fs.writeFileSync(
path.join(consoleDir, 'package.json'),
JSON.stringify({ version: '3.9.8' })
);
expect(readProductVersion({ rootDir: tmpRoot, consoleDir })).toBe('3.9.8');
});
test('prefers VERSION over package.json', () => {
const consoleDir = path.join(tmpRoot, 'web-nodejs');
fs.mkdirSync(consoleDir, { recursive: true });
fs.writeFileSync(path.join(tmpRoot, 'VERSION'), '2.0.1\n');
fs.writeFileSync(
path.join(consoleDir, 'package.json'),
JSON.stringify({ version: '9.9.9' })
);
expect(readProductVersion({ rootDir: tmpRoot, consoleDir })).toBe('2.0.1');
});
test('reads VERSION from console dir when repo root VERSION is missing', () => {
const consoleDir = path.join(tmpRoot, 'console');
fs.mkdirSync(consoleDir, { recursive: true });
fs.writeFileSync(path.join(consoleDir, 'VERSION'), '3.3.0\n');
fs.writeFileSync(
path.join(consoleDir, 'package.json'),
JSON.stringify({ version: '3.2.0' })
);
expect(readProductVersion({ rootDir: tmpRoot, consoleDir })).toBe('3.3.0');
});
test('prefers console package.json when consoleDir is the flat install root', () => {
const consoleDir = path.join(tmpRoot, 'BetterDeskConsole');
fs.mkdirSync(consoleDir, { recursive: true });
fs.writeFileSync(path.join(tmpRoot, 'VERSION'), '3.3.1\n');
fs.writeFileSync(
path.join(consoleDir, 'package.json'),
JSON.stringify({ version: '3.5.108' })
);
expect(readProductVersion({ rootDir: consoleDir, consoleDir })).toBe('3.5.108');
});
});