- 插件包改为 .xuqm.zip 事务制品,manifest/bundle/资源/SHA-256 统一校验 - 原生层拆分为桥接编排、插件包暂存、底层存储三个单一职责类 - 状态查询改为纯读取,不再误触发安装;新增 NATIVE_BASELINE_INCOMPATIBLE 拒绝 - SemVer 解析拆分为独立原生类并补原生测试 - XWebView 收口唯一内核,错误态统一中文层与重试 - common 增加请求头/运行时契约收口与 http 测试
49 行
2.0 KiB
JavaScript
49 行
2.0 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import { mkdtempSync, rmSync } from 'node:fs'
|
|
import { createRequire } from 'node:module'
|
|
import { tmpdir } from 'node:os'
|
|
import path from 'node:path'
|
|
import test from 'node:test'
|
|
|
|
const require = createRequire(import.meta.url)
|
|
const { createModuleSerializer } = require('../metro')
|
|
|
|
function context(cacheFile, moduleId, moduleType, moduleIndex, reset = false) {
|
|
return {
|
|
XUQM_MODULE_CACHE_FILE: cacheFile,
|
|
XUQM_MODULE_ID: moduleId,
|
|
XUQM_MODULE_INDEX: String(moduleIndex),
|
|
XUQM_MODULE_TYPE: moduleType,
|
|
XUQM_RESET_MODULE_CACHE: reset ? 'true' : 'false',
|
|
}
|
|
}
|
|
|
|
test('Metro module ranges share startup/common and isolate every app or buz', () => {
|
|
const directory = mkdtempSync(path.join(tmpdir(), 'xuqm-metro-'))
|
|
const cacheFile = path.join(directory, 'ids.json')
|
|
try {
|
|
const startup = createModuleSerializer(context(cacheFile, 'startup', 'startup', 0, true))
|
|
const startupFactory = startup.createModuleIdFactory()
|
|
assert.equal(startupFactory('/runtime/prelude.js'), 0)
|
|
|
|
const common = createModuleSerializer(context(cacheFile, 'common', 'common', 1))
|
|
assert.equal(common.processModuleFilter({ path: '/runtime/prelude.js' }), false)
|
|
const commonFactory = common.createModuleIdFactory()
|
|
assert.equal(commonFactory('/runtime/prelude.js'), 0)
|
|
assert.equal(commonFactory('/shared/common.ts'), 1)
|
|
assert.equal(
|
|
common.processModuleFilter({ path: '/shared/common.ts' }),
|
|
true,
|
|
'common 本轮新分配的模块必须保留在当前 bundle 中',
|
|
)
|
|
|
|
const app = createModuleSerializer(context(cacheFile, 'app', 'app', 2))
|
|
const buz = createModuleSerializer(context(cacheFile, 'buz-a', 'buz', 3))
|
|
assert.equal(app.processModuleFilter({ path: '/shared/common.ts' }), false)
|
|
assert.equal(app.createModuleIdFactory()('/app/entry.ts'), 30_000_000)
|
|
assert.equal(buz.createModuleIdFactory()('/buz/entry.ts'), 40_000_000)
|
|
} finally {
|
|
rmSync(directory, { force: true, recursive: true })
|
|
}
|
|
})
|