metro/react-packager/__mocks__/net.js

36 lines
858 B
JavaScript
Raw Normal View History

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
2015-01-30 01:10:49 +00:00
var EventEmitter = require('events').EventEmitter;
var servers = {};
exports.createServer = function(listener) {
var server = {
_listener: listener,
socket: new EventEmitter(),
listen: function(path) {
listener(this.socket);
servers[path] = this;
}
};
server.socket.setEncoding = function() {};
server.socket.write = function(data) {
this.emit('data', data);
};
return server;
};
exports.connect = function(options) {
var server = servers[options.path || options.port];
return server.socket;
};