XuqmGroup-RNSDK/packages/update/scripts/xuqm-config.test.mjs
XuqmGroup 507ce3d2ee feat(update): release-set 事务制品与原生层职责拆分
- 插件包改为 .xuqm.zip 事务制品,manifest/bundle/资源/SHA-256 统一校验
- 原生层拆分为桥接编排、插件包暂存、底层存储三个单一职责类
- 状态查询改为纯读取,不再误触发安装;新增 NATIVE_BASELINE_INCOMPATIBLE 拒绝
- SemVer 解析拆分为独立原生类并补原生测试
- XWebView 收口唯一内核,错误态统一中文层与重试
- common 增加请求头/运行时契约收口与 http 测试
2026-07-20 19:31:43 +08:00

116 行
3.4 KiB
JavaScript

import assert from 'node:assert/strict'
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import path from 'node:path'
import test from 'node:test'
import { resolveVersionedModules, validateConfig } from './xuqm-config.mjs'
function fixture() {
const root = mkdtempSync(path.join(tmpdir(), 'xuqm-config-'))
writeFileSync(path.join(root, 'package.json'), JSON.stringify({ version: '7.2.14' }))
writeFileSync(path.join(root, 'common.ts'), '')
writeFileSync(path.join(root, 'app.ts'), '')
writeFileSync(path.join(root, 'metro.config.js'), 'module.exports = {}\n')
return root
}
test('plugins start at the configured plugin version independently from the app version', () => {
const root = fixture()
try {
const config = {
appId: 'example',
mainModuleName: 'Example',
pluginVersion: '1.0.0',
appVersionRange: '>=7.2.14 <8.0.0',
metroConfig: './metro.config.js',
modules: [
{ id: 'common', type: 'common', entry: './common.ts' },
{ id: 'app', type: 'app', entry: './app.ts' },
],
}
assert.deepEqual(validateConfig(config, root), [])
const resolved = resolveVersionedModules(config, root)
assert.equal(resolved.appVersion, '7.2.14')
assert.equal(resolved.modules[0].moduleVersion, '1.0.0')
assert.equal(resolved.modules[1].moduleVersion, '1.0.0')
assert.equal(resolved.modules[1].commonVersionRange, '>=1.0.0 <2.0.0')
assert.equal(resolved.modules[1].minNativeApiLevel, 2)
} finally {
rmSync(root, { recursive: true, force: true })
}
})
test('an explicitly independently released module keeps its own version', () => {
const root = fixture()
try {
const resolved = resolveVersionedModules(
{
pluginVersion: '1.0.0',
appVersionRange: '>=8.0.0 <9.0.0',
modules: [
{ id: 'common', type: 'common', moduleVersion: '3.0.0' },
{ id: 'feature', type: 'buz', moduleVersion: '4.1.0' },
],
},
root,
'8.0.0',
)
assert.equal(resolved.appVersion, '8.0.0')
assert.equal(resolved.modules[0].moduleVersion, '3.0.0')
assert.equal(resolved.modules[1].moduleVersion, '4.1.0')
assert.equal(resolved.modules[1].commonVersionRange, '>=3.0.0 <4.0.0')
} finally {
rmSync(root, { recursive: true, force: true })
}
})
test('only common can own existing shared source roots', () => {
const root = fixture()
try {
mkdirSync(path.join(root, 'src', 'common'), { recursive: true })
const base = {
appId: 'example',
mainModuleName: 'Example',
pluginVersion: '1.0.0',
appVersionRange: '>=1.0.0 <2.0.0',
metroConfig: './metro.config.js',
}
assert.deepEqual(
validateConfig(
{
...base,
modules: [
{
id: 'common',
type: 'common',
entry: './common.ts',
ownershipRoots: ['./src/common'],
},
],
},
root,
),
[],
)
assert.match(
validateConfig(
{
...base,
modules: [
{
id: 'app',
type: 'app',
entry: './app.ts',
ownershipRoots: ['./src/common'],
},
],
},
root,
).join('\n'),
/only supported by the common module/,
)
} finally {
rmSync(root, { recursive: true, force: true })
}
})