2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00
Files
axios/tests/smoke/bun/tests/timeout.smoke.test.ts
T
Jay 2f52f6b13b feat: add checks to support deno and bun (#10652)
* feat: added smoke tests for deno

* feat: added bun smoke tests

* chore: added workflows for deno and bun

* chore: swap workflow implementation

* chore: apply ai suggestion

* chore: test alt install of bun deps

* chore: deno install

* chore: map bun file install

* chore: try a different approach for bun

* chore: unpack and then install for bun

* chore: remove un-needed step

* chore: try with tgx again for bun

* chore: alternative zip approach

* ci: full ci added back
2026-04-05 14:37:16 +02:00

51 lines
1.3 KiB
TypeScript

import { describe, expect, test } from 'bun:test';
import axios from 'axios';
const env = (fetch: typeof globalThis.fetch) => ({
fetch,
Request,
Response,
});
const createAbortedError = () => {
const error = new Error('The operation was aborted') as Error & { code?: string; name: string };
error.name = 'AbortError';
error.code = 'ECONNABORTED';
return error;
};
describe('timeout', () => {
test('timeout: 50 with never-resolving fetch mock rejects with ECONNABORTED', async () => {
const fetch = (input: unknown, init?: RequestInit) =>
new Promise<Response>((_resolve, reject) => {
const signal = init?.signal || (input instanceof Request ? input.signal : undefined);
if (signal) {
if (signal.aborted) {
reject(createAbortedError());
return;
}
signal.addEventListener(
'abort',
() => {
reject(createAbortedError());
},
{ once: true }
);
}
});
const err = await axios
.get('https://example.com/timeout', {
adapter: 'fetch',
timeout: 50,
env: env(fetch),
})
.catch((e: any) => e);
expect(axios.isAxiosError(err)).toBe(true);
expect(err.code).toBe('ECONNABORTED');
});
});