import test from 'node:test' import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import { parse, compileScript, compileTemplate, compileStyle } from 'vue/compiler-sfc' import { assertReceivingWarehouse } from '../src/api/receiving-adapter.js' import { MODULES } from '../src/data/overseas-workbench.js' const apiSource = readFileSync(new URL('../src/api/workbench.js', import.meta.url), 'utf8') const homeSource = readFileSync(new URL('../src/pages/home/home.vue', import.meta.url), 'utf8') const profile = { id: 'OP', warehouseId: 'WH', warehouseCode: 'WH-CODE', warehouseName: '测试仓' } const emptySources = () => ({ assertReceivingWarehouse, listReceivingCandidates: async () => [], listWarehouseTransferCandidates: async () => [], listReturnCountTasks: async () => ({ records: [], total: 0 }), listPackingPlans: async () => [], listDispatchTasks: async () => [], listOutboundTasks: async () => [], listCargoDiscardTasks: async () => [], listRelabelCandidates: async () => [] }) function api(overrides = {}) { const dependencies = { ...emptySources(), ...overrides } return new Function(...Object.keys(dependencies), apiSource.replace(/^import .*$/gm, '').replace(/^export /gm, '') + '\nreturn { loadWorkbenchCounts, workbenchBadge, WORKBENCH_COUNT_KEYS }')(...Object.values(dependencies)) } function home(loadWorkbenchCounts) { const session = { currentUser: { ...profile }, apiBase: 'LOCAL' } const scopes = [] const dependencies = { PortalHeader: {}, MODULES, session, requireSession: () => true, applyWarehouseProfile: value => value, getCurrentWarehouseProfile: async () => session.currentUser, loadWorkbenchCounts, workbenchBadge: api().workbenchBadge, restoreWarehouseWork: scope => scopes.push(scope), warehouseWork: { warehouseTransfer: { currentNo: 'T2' } } } const page = new Function(...Object.keys(dependencies), homeSource.match(/