Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/request / dist / testHelpers / MockRequest.js
Size: Mime:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const stream_1 = require("stream");
class MockIncomingMessage extends stream_1.Transform {
    constructor(options = {}) {
        super();
        this._writableState.objectMode = true;
        this._readableState.objectMode = false;
        // Copy unreserved options
        const reservedOptions = ['method', 'url', 'headers', 'rawHeaders'];
        Object.keys(options).forEach(key => {
            if (reservedOptions.includes(key) === false) {
                this[key] = options[key];
            }
        });
        this.method = options.method || 'GET';
        this.url = options.url || '';
        // Set header names
        this.headers = {};
        this.rawHeaders = [];
        if (options.headers) {
            Object.keys(options.headers).forEach(key => {
                let val = options.headers[key];
                if (val !== undefined) {
                    if (typeof val !== 'string') {
                        // I think this is trying to convert it to a string? @@fork
                        val += '';
                    }
                    this.headers[key.toLowerCase()] = val;
                    this.rawHeaders.push(key);
                    this.rawHeaders.push(val);
                }
            });
        }
        // Auto-end when no body
        if (this.method === 'GET' ||
            this.method === 'HEAD' ||
            this.method === 'DELETE') {
            this.end();
        }
    }
    _transform(chunk, encoding, next) {
        if (this._failError) {
            return this.emit('error', this._failError);
        }
        if (typeof chunk !== 'string' && !Buffer.isBuffer(chunk)) {
            chunk = JSON.stringify(chunk);
        }
        this.push(chunk);
        next();
    }
    // Causes the request to emit an error when the body is read.
    _fail(error) {
        this._failError = error;
    }
}
exports.MockIncomingMessage = MockIncomingMessage;
//# sourceMappingURL=MockRequest.js.map