mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-uniapp.git
synced 2026-08-06 02:47:25 +08:00
fix: 修复 App 端 MQTT 运行时兼容问题
- 锁定 MQTT 版本为 5.15.1 - 为 AbortController、AbortSignal 和 navigator.language 添加兼容补丁 - 新增 MQTT App 运行时测试
This commit is contained in:
49
scripts/test-mqtt-app-runtime.js
Normal file
49
scripts/test-mqtt-app-runtime.js
Normal file
@@ -0,0 +1,49 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const vm = require('vm')
|
||||
|
||||
const bundle = fs.readFileSync(
|
||||
path.join(path.dirname(require.resolve('mqtt/package.json')), 'dist/mqtt.js'),
|
||||
'utf8'
|
||||
)
|
||||
|
||||
const context = vm.createContext({
|
||||
console,
|
||||
setTimeout,
|
||||
clearTimeout,
|
||||
setInterval,
|
||||
clearInterval,
|
||||
queueMicrotask,
|
||||
TextEncoder,
|
||||
TextDecoder,
|
||||
URL,
|
||||
})
|
||||
|
||||
vm.runInContext(bundle, context, { timeout: 10000 })
|
||||
|
||||
if (typeof context.AbortController !== 'function') {
|
||||
throw new Error('MQTT bundle did not install AbortController fallback')
|
||||
}
|
||||
if (typeof context.AbortSignal !== 'function') {
|
||||
throw new Error('MQTT bundle did not install AbortSignal fallback')
|
||||
}
|
||||
|
||||
const controller = new context.AbortController()
|
||||
let abortEvents = 0
|
||||
controller.signal.addEventListener('abort', () => {
|
||||
abortEvents += 1
|
||||
}, { once: true })
|
||||
controller.abort('test-reason')
|
||||
controller.abort('ignored-reason')
|
||||
|
||||
if (!controller.signal.aborted) {
|
||||
throw new Error('AbortSignal was not marked aborted')
|
||||
}
|
||||
if (controller.signal.reason !== 'test-reason') {
|
||||
throw new Error('AbortSignal reason was not preserved')
|
||||
}
|
||||
if (abortEvents !== 1) {
|
||||
throw new Error(`Expected one abort event, got ${abortEvents}`)
|
||||
}
|
||||
|
||||
console.log('MQTT App runtime fallback test passed')
|
||||
Reference in New Issue
Block a user