mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
2f52f6b13b
* 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
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { describe, expect, test } from 'bun:test';
|
|
import axios from 'axios';
|
|
|
|
const env = (fetch: typeof globalThis.fetch) => ({
|
|
fetch,
|
|
Request,
|
|
Response,
|
|
});
|
|
|
|
describe('progress', () => {
|
|
test('onDownloadProgress fires with loaded > 0 for streaming fetch response', async () => {
|
|
const samples: number[] = [];
|
|
|
|
const fetch = async () => {
|
|
const stream = new ReadableStream({
|
|
start(controller) {
|
|
controller.enqueue(new TextEncoder().encode('ab'));
|
|
controller.enqueue(new TextEncoder().encode('cd'));
|
|
controller.close();
|
|
},
|
|
});
|
|
|
|
return new Response(stream, {
|
|
status: 200,
|
|
headers: {
|
|
'Content-Type': 'text/plain',
|
|
'Content-Length': '4',
|
|
},
|
|
});
|
|
};
|
|
|
|
const response = await axios.get('https://example.com/download', {
|
|
adapter: 'fetch',
|
|
responseType: 'text',
|
|
onDownloadProgress: ({ loaded }: { loaded: number }) => {
|
|
samples.push(loaded);
|
|
},
|
|
env: env(fetch),
|
|
});
|
|
|
|
expect(response.data).toBe('abcd');
|
|
expect(samples.length).toBeGreaterThan(0);
|
|
expect(samples.some((loaded) => loaded > 0)).toBe(true);
|
|
});
|
|
});
|