27 行
791 B
TypeScript
27 行
791 B
TypeScript
|
|
import assert from 'node:assert/strict'
|
||
|
|
import test from 'node:test'
|
||
|
|
|
||
|
|
import { apiRequest, configureHttp } from '../src/http'
|
||
|
|
|
||
|
|
test('apiRequest aborts a stalled request at the shared timeout boundary', async () => {
|
||
|
|
const originalFetch = globalThis.fetch
|
||
|
|
configureHttp({ baseUrl: 'https://platform.example.test' })
|
||
|
|
globalThis.fetch = async (_input, init) =>
|
||
|
|
new Promise((_resolve, reject) => {
|
||
|
|
init?.signal?.addEventListener(
|
||
|
|
'abort',
|
||
|
|
() => reject(init.signal?.reason ?? new Error('aborted')),
|
||
|
|
{ once: true },
|
||
|
|
)
|
||
|
|
})
|
||
|
|
|
||
|
|
try {
|
||
|
|
await assert.rejects(
|
||
|
|
() => apiRequest('/api/v1/rn/release-set/check', { skipAuth: true, timeoutMs: 5 }),
|
||
|
|
/Request timed out after 5ms/,
|
||
|
|
)
|
||
|
|
} finally {
|
||
|
|
globalThis.fetch = originalFetch
|
||
|
|
}
|
||
|
|
})
|