32 lines
1.3 KiB
JavaScript
32 lines
1.3 KiB
JavaScript
|
|
const assert = require('node:assert/strict');
|
||
|
|
const fs = require('node:fs');
|
||
|
|
const path = require('node:path');
|
||
|
|
const vm = require('node:vm');
|
||
|
|
const template = fs.readFileSync(path.join(__dirname, '../templates/app/control/index.html'), 'utf8');
|
||
|
|
const code = template.slice(template.indexOf('function buildZoneStateTag('),
|
||
|
|
template.indexOf('function buildZoneRunBtn('));
|
||
|
|
let info, active = true;
|
||
|
|
const context = {
|
||
|
|
zoneIsActiveInPipeline: () => active,
|
||
|
|
getStreamStatusInfo: () => info,
|
||
|
|
getStreamHealth: () => info.stream_health,
|
||
|
|
streamHealthLabel: health => health,
|
||
|
|
_t: (_, fallback) => fallback,
|
||
|
|
};
|
||
|
|
vm.createContext(context);
|
||
|
|
vm.runInContext(code, context);
|
||
|
|
const tag = () => context.buildZoneStateTag({stream_id: 87});
|
||
|
|
info = {running: true, stream_health: 'ok', analysis_health: 'starting', analysis_fps: 0};
|
||
|
|
assert.match(tag(), /启动中/);
|
||
|
|
info.analysis_health = 'error';
|
||
|
|
assert.match(tag(), /推理异常/);
|
||
|
|
info.analysis_health = 'running';
|
||
|
|
info.analysis_fps = 0.017;
|
||
|
|
assert.match(tag(), /分析中/);
|
||
|
|
info.running = false;
|
||
|
|
info.stream_health = 'disconnected';
|
||
|
|
assert.match(tag(), /disconnected/);
|
||
|
|
active = false;
|
||
|
|
assert.match(tag(), /已停止/);
|
||
|
|
console.log('PASS: starting, inference error, low-FPS success, disconnected, stopped');
|