55 lines
2.9 KiB
JavaScript
55 lines
2.9 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const {
|
|
compareVersions,
|
|
evaluateUpdate,
|
|
getAutoGrid,
|
|
normalizeRelease,
|
|
selectReleaseAsset,
|
|
} = require('../static/webavp-utils.js');
|
|
|
|
assert.deepEqual(getAutoGrid(0), { cols: 1, rows: 1 });
|
|
assert.deepEqual(getAutoGrid(1), { cols: 1, rows: 1 });
|
|
assert.deepEqual(getAutoGrid(2), { cols: 2, rows: 1 });
|
|
assert.deepEqual(getAutoGrid(4), { cols: 2, rows: 2 });
|
|
assert.deepEqual(getAutoGrid(6), { cols: 3, rows: 2 });
|
|
assert.deepEqual(getAutoGrid(9), { cols: 3, rows: 3 });
|
|
assert.deepEqual(getAutoGrid(12), { cols: 4, rows: 3 });
|
|
assert.deepEqual(getAutoGrid(16), { cols: 4, rows: 4 });
|
|
assert.deepEqual(getAutoGrid(99), { cols: 4, rows: 4 });
|
|
|
|
assert.equal(compareVersions('v1.2.0', '1.1.9'), 1);
|
|
assert.equal(compareVersions('1.2.0', '1.2.0'), 0);
|
|
assert.equal(compareVersions('1.2.0-beta.1', '1.2.0'), -1);
|
|
assert.equal(compareVersions('1.2.0+linux.1', '1.2.0+build.9'), 0);
|
|
assert.equal(compareVersions('2.0', '1.99.99'), 1);
|
|
assert.throws(() => compareVersions('latest', '1.0.0'), /version/i);
|
|
|
|
const rawRelease = {
|
|
tag_name: 'v1.4.0',
|
|
html_url: 'https://git.pejicorp.com/peji/WebAVP/releases/tag/v1.4.0',
|
|
name: 'WebAVP 1.4.0',
|
|
assets: [
|
|
{ name: 'Alta Video Player-1.4.0-linux-x64.AppImage', browser_download_url: 'https://git.pejicorp.com/peji/WebAVP/releases/download/v1.4.0/linux.AppImage' },
|
|
{ name: 'Alta Video Player-1.4.0-linux-x64.deb', browser_download_url: 'https://git.pejicorp.com/peji/WebAVP/releases/download/v1.4.0/linux.deb' },
|
|
{ name: 'Alta Video Player-1.4.0-mac-arm64.dmg', browser_download_url: 'https://git.pejicorp.com/peji/WebAVP/releases/download/v1.4.0/mac-arm64.dmg' },
|
|
{ name: 'Alta Video Player-1.4.0-mac-x64.dmg', browser_download_url: 'https://git.pejicorp.com/peji/WebAVP/releases/download/v1.4.0/mac-x64.dmg' },
|
|
{ name: 'Alta Video Player-1.4.0-win-x64.exe', browser_download_url: 'https://git.pejicorp.com/peji/WebAVP/releases/download/v1.4.0/win.exe' },
|
|
],
|
|
};
|
|
const release = normalizeRelease(rawRelease);
|
|
assert.equal(release.version, '1.4.0');
|
|
assert.equal(selectReleaseAsset(release, 'linux', 'x64').name.endsWith('.AppImage'), true);
|
|
assert.equal(selectReleaseAsset(release, 'linux', 'arm64'), null);
|
|
assert.equal(selectReleaseAsset(release, 'darwin', 'arm64').name.endsWith('.dmg'), true);
|
|
assert.equal(selectReleaseAsset(release, 'win32', 'x64').name.endsWith('.exe'), true);
|
|
assert.equal(selectReleaseAsset(release, 'win32', 'arm64'), null);
|
|
assert.throws(() => normalizeRelease({ tag_name: 'v1.0.0', assets: [{ name: 'bad.exe', browser_download_url: 'https://evil.example/bad.exe' }] }), /asset/i);
|
|
|
|
assert.equal(evaluateUpdate(release, '1.4.0', 'linux', 'x64').status, 'current');
|
|
assert.equal(evaluateUpdate(release, '1.3.9', 'linux', 'x64').status, 'available');
|
|
assert.equal(evaluateUpdate(release, '1.3.9', 'linux', 'arm64').status, 'unavailable-platform');
|
|
|
|
console.log('[WebAVP] utility regression tests passed');
|