inversify-express-utils
Version:
Some utilities for the development of express applications with Inversify
37 lines • 1.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const node_stream_1 = require("node:stream");
const globals_1 = require("@jest/globals");
const streamContent_1 = require("../../content/streamContent");
(0, globals_1.describe)('StreamContent', () => {
(0, globals_1.it)('should have text/plain as the set media type', () => {
const stream = new node_stream_1.Readable();
const content = new streamContent_1.StreamContent(stream, 'text/plain');
(0, globals_1.expect)(content.headers['content-type']).toEqual('text/plain');
});
(0, globals_1.it)('should be able to pipe stream which was given to it', async () => {
const stream = new node_stream_1.Readable({
read() {
this.push(Buffer.from('test'));
this.push(null);
},
});
const readable = await new streamContent_1.StreamContent(stream, 'text/plain').readAsync();
const chunks = [];
let buffer = null;
return new Promise((resolve) => {
readable.on('end', () => {
buffer = Buffer.concat(chunks);
(0, globals_1.expect)(buffer.toString()).toEqual('test');
resolve();
});
const writableStream = new node_stream_1.Writable({
write(chunk) {
chunks.push(chunk);
},
});
readable.pipe(writableStream);
});
});
});
//# sourceMappingURL=streamContent.test.js.map