mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 18:22:25 +00:00
39 lines
1.4 KiB
JavaScript
39 lines
1.4 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
CCTV_FRAME_FETCH_TIMEOUT_MS,
|
|
fetchCctvImageFromUpstream,
|
|
} from '../../vite.config.js';
|
|
|
|
test('CCTV upstream frame fetch supplies a bounded abort signal', async () => {
|
|
let observedSignal = null;
|
|
const startedAt = Date.now();
|
|
const result = await fetchCctvImageFromUpstream('https://example.com/frame.jpg', {
|
|
timeoutMs: 20,
|
|
fetchImpl: (_url, options) => new Promise((_resolve, reject) => {
|
|
observedSignal = options.signal;
|
|
options.signal.addEventListener('abort', () => reject(options.signal.reason), { once: true });
|
|
}),
|
|
});
|
|
|
|
assert.equal(result, null);
|
|
assert.ok(observedSignal instanceof AbortSignal);
|
|
assert.equal(observedSignal.aborted, true);
|
|
assert.ok(Date.now() - startedAt < 500, 'test timeout should settle promptly');
|
|
assert.ok(CCTV_FRAME_FETCH_TIMEOUT_MS < 10_000, 'production timeout must beat the active refresh cadence');
|
|
});
|
|
|
|
test('CCTV upstream frame fetch returns a valid image response', async () => {
|
|
const result = await fetchCctvImageFromUpstream('https://example.com/frame.jpg', {
|
|
timeoutMs: 100,
|
|
fetchImpl: async () => new Response(Uint8Array.from([1, 2, 3]), {
|
|
status: 200,
|
|
headers: { 'Content-Type': 'image/jpeg' },
|
|
}),
|
|
});
|
|
|
|
assert.equal(result?.ok, true);
|
|
assert.equal(result?.contentType, 'image/jpeg');
|
|
assert.deepEqual(result?.body, Buffer.from([1, 2, 3]));
|
|
});
|