mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
35 lines
953 B
JavaScript
35 lines
953 B
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { createBundledCableSource } from './bundledSource.js';
|
|
|
|
test('a failed bundled response releases its body', async () => {
|
|
let released = 0;
|
|
const source = createBundledCableSource({
|
|
fetchImpl: async () => ({
|
|
ok: false,
|
|
status: 503,
|
|
body: {
|
|
cancel: async () => {
|
|
released++;
|
|
},
|
|
},
|
|
}),
|
|
});
|
|
await assert.rejects(source.fetch(), /HTTP 503/);
|
|
assert.equal(released, 2);
|
|
});
|
|
|
|
test('cancellation during JSON parsing cannot return a late snapshot', async () => {
|
|
const controller = new AbortController();
|
|
const source = createBundledCableSource({
|
|
fetchImpl: async () => ({
|
|
ok: true,
|
|
async json() {
|
|
controller.abort();
|
|
return { type: 'FeatureCollection', features: [] };
|
|
},
|
|
}),
|
|
});
|
|
await assert.rejects(source.fetch(controller.signal), { name: 'AbortError' });
|
|
});
|