41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import fs from 'node:fs'
|
|
|
|
const toModuleUrl = (source) =>
|
|
`data:text/javascript;base64,${Buffer.from(source).toString('base64')}`
|
|
|
|
const routesSource = fs.readFileSync('utils/navigation/routes.js', 'utf8')
|
|
const gatewaySource = fs.readFileSync('utils/navigation/gateway.js', 'utf8')
|
|
.replace('"./routes.js"', JSON.stringify(toModuleUrl(routesSource)))
|
|
|
|
let currentPage = { route: 'pages/profile/home' }
|
|
const relaunchCalls = []
|
|
globalThis.getCurrentPages = () => [currentPage]
|
|
globalThis.uni = {
|
|
reLaunch(options) {
|
|
relaunchCalls.push(options)
|
|
},
|
|
}
|
|
|
|
const { goRoot, recoverToAuthRoot } = await import(toModuleUrl(gatewaySource))
|
|
|
|
const ordinaryNavigation = goRoot('G01')
|
|
const sessionRecovery = recoverToAuthRoot()
|
|
|
|
assert.equal(relaunchCalls.length, 1, '登录恢复应等待已有转场完成')
|
|
assert.equal(relaunchCalls[0].url, '/pages/genealogy/my-genealogies')
|
|
|
|
currentPage = { route: 'pages/genealogy/my-genealogies' }
|
|
relaunchCalls[0].success()
|
|
await ordinaryNavigation
|
|
await Promise.resolve()
|
|
|
|
assert.equal(relaunchCalls.length, 2, '已有转场完成后必须继续登录恢复')
|
|
assert.equal(relaunchCalls[1].url, '/pages/auth/sign-in')
|
|
|
|
currentPage = { route: 'pages/auth/sign-in' }
|
|
relaunchCalls[1].success()
|
|
assert.equal(await sessionRecovery, true)
|
|
|
|
console.log('NAVIGATION RECOVERY CHECK PASS')
|