31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
const assert = require('node:assert/strict');
|
|||
|
|
const fs = require('node:fs');
|
||
|
|
const vm = require('node:vm');
|
||
|
|
const source = fs.readFileSync('miniapp/app.js', 'utf8');
|
||
|
|
|
||
|
|
function launch(token, path) {
|
||
|
|
const calls = [];
|
||
|
|
let app;
|
||
|
|
vm.runInNewContext(source, {
|
||
|
|
require: () => ({
|
||
|
|
bootstrap: () => calls.push('user-bootstrap'),
|
||
|
|
appStore: { init: () => { calls.push('config'); return Promise.resolve(); } },
|
||
|
|
}),
|
||
|
|
App: (definition) => { app = definition; },
|
||
|
|
wx: {
|
||
|
|
getStorageSync: () => token,
|
||
|
|
reLaunch: ({ url }) => calls.push(url),
|
||
|
|
},
|
||
|
|
});
|
||
|
|
app.onLaunch({ path });
|
||
|
|
return calls;
|
||
|
|
}
|
||
|
|
|
||
|
|
assert.deepEqual(launch('', 'pages/index/index'), ['user-bootstrap']);
|
||
|
|
assert.deepEqual(launch('staff-session', 'pages/index/index'), ['config', '/pages/matchmaker-workbench/matchmaker-workbench']);
|
||
|
|
for (const path of ['login', 'workbench', 'service-detail']) {
|
||
|
|
assert.deepEqual(launch('', `pages/matchmaker-${path}/matchmaker-${path}`), ['config']);
|
||
|
|
}
|
||
|
|
assert.deepEqual(launch('', 'pages/matchmaker-progress/matchmaker-progress'), ['user-bootstrap']);
|
||
|
|
console.log('PASS: user startup, staff session, staff deep links and user service route');
|