fix(core): Improve streaming support and timeout handling; add browser streaming & timeout tests and README clarifications

This commit is contained in:
2025-08-19 01:36:44 +00:00
parent 35867d9148
commit 361d97f440
8 changed files with 181 additions and 11 deletions

View File

@@ -0,0 +1,41 @@
import { tap, expect } from '@git.zone/tstest/tapbundle';
import { SmartRequest } from '../ts/index.js';
tap.test('browser: should send Uint8Array using buffer() method', async () => {
const testData = new Uint8Array([72, 101, 108, 108, 111]); // "Hello" in ASCII
const smartRequest = SmartRequest.create()
.url('https://httpbin.org/post')
.buffer(testData, 'application/octet-stream')
.method('POST');
const response = await smartRequest.post();
const data = await response.json();
expect(data).toHaveProperty('data');
expect(data.headers['Content-Type']).toEqual('application/octet-stream');
});
tap.test('browser: should send web ReadableStream using stream() method', async () => {
// Create a web ReadableStream
const encoder = new TextEncoder();
const stream = new ReadableStream({
start(controller) {
controller.enqueue(encoder.encode('Test stream data'));
controller.close();
}
});
const smartRequest = SmartRequest.create()
.url('https://httpbin.org/post')
.stream(stream, 'text/plain')
.method('POST');
const response = await smartRequest.post();
const data = await response.json();
expect(data).toHaveProperty('data');
// httpbin should receive the streamed data
});
export default tap.start();