- 插件包改为 .xuqm.zip 事务制品,manifest/bundle/资源/SHA-256 统一校验 - 原生层拆分为桥接编排、插件包暂存、底层存储三个单一职责类 - 状态查询改为纯读取,不再误触发安装;新增 NATIVE_BASELINE_INCOMPATIBLE 拒绝 - SemVer 解析拆分为独立原生类并补原生测试 - XWebView 收口唯一内核,错误态统一中文层与重试 - common 增加请求头/运行时契约收口与 http 测试
63 行
2.0 KiB
TypeScript
63 行
2.0 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
|
|
import { apiRequest } from '../src/http'
|
|
import { _initializeFromResolvedConfig, awaitInitialization } from '../src/sdk'
|
|
|
|
test('awaitInitialization observes in-flight work and retries a transient config request failure', async () => {
|
|
const originalFetch = globalThis.fetch
|
|
let requestCount = 0
|
|
const requestedUrls: string[] = []
|
|
globalThis.fetch = async input => {
|
|
requestCount += 1
|
|
requestedUrls.push(String(input))
|
|
if (requestCount === 1) {
|
|
throw new TypeError('Network request failed')
|
|
}
|
|
if (requestCount === 3) {
|
|
return new Response(JSON.stringify({ data: { available: true } }), {
|
|
headers: { 'content-type': 'application/json' },
|
|
status: 200,
|
|
})
|
|
}
|
|
return new Response(
|
|
JSON.stringify({
|
|
data: {
|
|
apiUrl: 'https://api.example.test',
|
|
},
|
|
}),
|
|
{
|
|
headers: { 'content-type': 'application/json' },
|
|
status: 200,
|
|
},
|
|
)
|
|
}
|
|
|
|
try {
|
|
const autoInitialization = _initializeFromResolvedConfig(
|
|
{
|
|
appKey: 'test-app',
|
|
appName: '测试应用',
|
|
serverUrl: 'https://dev.xuqinmin.com',
|
|
signingKey: 'secret',
|
|
},
|
|
{ debug: true },
|
|
)
|
|
await assert.rejects(() => awaitInitialization(), /Network request failed/)
|
|
await assert.rejects(() => autoInitialization, /Network request failed/)
|
|
|
|
// 配置内容由 common 保存,扩展包再次等待时可以自行重试,无需宿主传递配置。
|
|
await assert.doesNotReject(() => awaitInitialization())
|
|
assert.equal(requestCount, 2)
|
|
|
|
const result = await apiRequest<{ available: boolean }>('/api/v1/rn/release-set/check', {
|
|
skipAuth: true,
|
|
})
|
|
assert.deepEqual(result, { available: true })
|
|
assert.equal(requestedUrls[2], 'https://dev.xuqinmin.com/api/v1/rn/release-set/check')
|
|
assert.equal(requestedUrls[2]?.includes('api.example.test'), false)
|
|
} finally {
|
|
globalThis.fetch = originalFetch
|
|
}
|
|
})
|