57 lines
3.0 KiB
JavaScript
57 lines
3.0 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import { readFile } from 'node:fs/promises'
|
|
import test from 'node:test'
|
|
|
|
const read = (path) => readFile(new URL(path, import.meta.url), 'utf8')
|
|
|
|
test('App-Plus checks the independent update channel after launch', async () => {
|
|
const [app, updater, env] = await Promise.all([
|
|
read('../App.vue'),
|
|
read('../utils/app-update.js'),
|
|
read('../.env.example')
|
|
])
|
|
|
|
assert.match(app, /#ifdef APP-PLUS[\s\S]*?checkForAppUpdate\(\)/)
|
|
assert.match(env, /VITE_PDA_UPDATE_URL=https:\/\//)
|
|
assert.match(updater, /plus\.runtime\.getProperty/)
|
|
assert.match(updater, /appid:[\s\S]*?platform: 'android'[\s\S]*?appVersion:[\s\S]*?appVersionCode:[\s\S]*?wgtVersion:/)
|
|
})
|
|
|
|
test('online update supports mandatory APK and wgt installation flows', async () => {
|
|
const updater = await read('../utils/app-update.js')
|
|
|
|
assert.match(updater, /\['apk', 'wgt'\]\.includes\(packageType\)/)
|
|
assert.match(updater, /update\.versionCode > runtime\.appVersionCode/)
|
|
assert.match(updater, /compareVersions\(update\.versionName, runtime\.wgtVersion\) > 0/)
|
|
assert.match(updater, /更新包必须使用 HTTPS 地址/)
|
|
assert.match(updater, /showCancel: !update\.mandatory/)
|
|
assert.match(updater, /uni\.downloadFile\([\s\S]*?onProgressUpdate/)
|
|
assert.match(updater, /plus\.runtime\.install/)
|
|
assert.match(updater, /packageType === 'wgt'[\s\S]*?plus\.runtime\.restart/)
|
|
assert.match(updater, /if \(retry\) await runUpdate\(update\)/)
|
|
})
|
|
|
|
test('update manifest rejects a different AppID and incompatible WGT base', async () => {
|
|
const updater = await read('../utils/app-update.js')
|
|
const body = updater.match(/function normalizeUpdate\(payload, runtime\) \{[\s\S]*?\n\}/)?.[0]
|
|
assert.ok(body)
|
|
const normalize = new Function(`${body}; return normalizeUpdate`)()
|
|
const runtime = { appid: 'domestic-app', appVersionCode: 3 }
|
|
const manifest = { update: true, appid: 'domestic-app', packageType: 'wgt', downloadUrl: 'https://example.com/app.wgt', versionName: '1.0.4', minAppVersionCode: 3 }
|
|
assert.equal(normalize(manifest, runtime).minAppVersionCode, 3)
|
|
assert.throws(() => normalize({ ...manifest, appid: 'overseas-app' }, runtime), /不匹配/)
|
|
assert.throws(() => normalize({ ...manifest, minAppVersionCode: 4 }, runtime), /新版 APK/)
|
|
assert.throws(() => normalize({ ...manifest, minAppVersionCode: undefined }, runtime), /新版 APK/)
|
|
})
|
|
|
|
test('profile exposes manual App update checking and the runtime version', async () => {
|
|
const profile = await read('../pages/profile/profile.vue')
|
|
|
|
assert.match(profile, /应用版本[\s\S]*?\{\{ appVersion \}\}/)
|
|
assert.match(profile, /profile-list[\s\S]*?应用版本[\s\S]*?profile-row-action" @tap="checkUpdate"[\s\S]*?检查更新[\s\S]*?profile-row-action" @tap="showSettings"[\s\S]*?系统设置/)
|
|
assert.doesNotMatch(profile, /class="profile-action"/)
|
|
assert.match(profile, /plus\.runtime\.version/)
|
|
assert.match(profile, /checkForAppUpdate\(\{ manual: true \}\)/)
|
|
assert.match(profile, /#ifndef APP-PLUS[\s\S]*?请在 PDA App 中检查更新/)
|
|
})
|