// Exercise real archive adapters/page scripts with synthetic memory responses; no network, DB or build. const fs = require('node:fs'); const path = require('node:path'); const vm = require('node:vm'); const assert = require('node:assert/strict'); const ts = require('D:/Develop/HBuilderX/plugins/uniapp-uts-v1/node_modules/@dcloudio/uni-uts-v1/lib/typescript/lib/typescript.js'); const root = path.resolve(__dirname, '..'); const amountKeys = ['totalDebtBalance', 'monthlyLoanPayment', 'creditCardTotalLimit', 'creditCardUsedLimit']; class Json { constructor(values = {}) { for (const [key, value] of Object.entries(values)) this[key] = wrap(value); } getString(key) { return typeof this[key] === 'string' ? this[key] : null; } getNumber(key) { return typeof this[key] === 'number' ? this[key] : null; } getBoolean(key) { return typeof this[key] === 'boolean' ? this[key] : null; } getArray(key) { return Array.isArray(this[key]) ? this[key] : null; } } function wrap(value) { return Array.isArray(value) ? value.map(wrap) : value && typeof value === 'object' && !(value instanceof Json) ? new Json(value) : value; } const plain = value => JSON.parse(JSON.stringify(value)); function harness() { const modules = {}; const queue = []; const calls = []; const hooks = {}; const navigation = []; let session = new Json({ token: 'synthetic-archive-owner' }); const api = { getSession: () => session, async requestJson(route, method, params) { calls.push({ route, method, params: plain(params) }); const response = queue.shift(); assert.ok(response, 'response queued for ' + route); assert.equal(route, response.route); assert.equal(method, 'GET'); if (response.params !== undefined) assert.deepEqual(plain(params), response.params); if (response.error) throw response.error; return wrap(response.promise ? await response.promise : response.data); } }; function compile(source, filename, extras = {}) { const exports = {}; const prepared = source.replace(/const (labels|fieldNames): UTSJSONObject = (.*)/g, 'const $1: UTSJSONObject = new UTSJSONObject($2)'); const compiled = ts.transpileModule(prepared, { reportDiagnostics: true, compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 } }); assert.equal((compiled.diagnostics || []).filter(item => item.category === ts.DiagnosticCategory.Error).length, 0, filename + ' transpiles'); vm.runInNewContext(compiled.outputText, { exports, UTSJSONObject: Json, Error, Number, Date, Math, Promise, Array, require(name) { if (name.endsWith('.uvue')) return {}; if (name.endsWith('/api.uts') || name === './api.uts') return api; if (name.endsWith('/layout.uts')) return { usePageLayout: () => ({ pageStyle: () => '', contentStyle: () => '' }) }; return load(name.startsWith('@/') ? name.slice(2) : path.posix.normalize(path.posix.dirname(filename) + '/' + name)); }, setInterval: () => 1, clearInterval: () => {}, ...extras }, { filename }); return exports; } function load(filename) { if (!modules[filename]) modules[filename] = compile(fs.readFileSync(path.join(root, filename), 'utf8'), filename); return modules[filename]; } function page() { const filename = 'packages/finance/archive/archive.uvue'; const source = fs.readFileSync(path.join(root, filename), 'utf8').match(/