-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathformData-with-BufferStream.test.ts
More file actions
43 lines (39 loc) · 1.44 KB
/
formData-with-BufferStream.test.ts
File metadata and controls
43 lines (39 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { strict as assert } from 'node:assert';
import { createReadStream } from 'node:fs';
import { basename } from 'node:path';
import { describe, it, beforeAll, afterAll } from 'vitest';
import { HttpClient, WebFormData } from '../src/index.js';
import { startServer } from './fixtures/server.js';
import { BufferStream } from './fixtures/BufferStream.js';
describe('formData-with-BufferStream.test.ts', () => {
let close: any;
let _url: string;
beforeAll(async () => {
const { closeServer, url } = await startServer();
close = closeServer;
_url = url;
});
afterAll(async () => {
await close();
});
it('should post with BufferStream', async () => {
const fileStream = createReadStream(__filename);
const bufferStream = new BufferStream();
fileStream.pipe(bufferStream);
const formData = new WebFormData();
const fileName = basename(__filename);
formData.append('fileBufferStream', bufferStream, fileName);
formData.append('foo', 'bar');
const httpClient = new HttpClient();
const response = await httpClient.request(`${_url}multipart`, {
method: 'POST',
content: formData,
headers: formData.getHeaders(),
dataType: 'json',
});
assert.equal(response.status, 200);
// console.log(response.data);
assert.equal(response.data.files.fileBufferStream.filename, 'formData-with-BufferStream.test.ts');
assert.deepEqual(response.data.form, { foo: 'bar' });
});
});