fakeNet.js 691 Bytes
import events from 'events';

class FakeSocket extends events.EventEmitter {
    constructor() {
        super();
        this.data = {};
    }

    connect(port, host, callback) {
        callback();
    }

    write(data) {
        this.addEmit('data', data);
    }

    setTimeout(time, callback) {
        callback();
    }

    addEmit(ev, data) {
        let that = this;
        process.nextTick(function() {
            that.emit(ev, data);
        });
    }
    destroy() {
        let that = this;
        process.nextTick(function() {
            that.addEmit('close', that.data);
        });
    }
}

export default {
    Socket: FakeSocket
};