2015-06-24 14:56:32 +02:00
|
|
|
var chai = require('chai');
|
|
|
|
var assert = chai.assert;
|
|
|
|
|
|
|
|
var FakeIpcRequest = function () {
|
2017-02-28 16:02:08 +01:00
|
|
|
var _this = this;
|
2015-06-24 14:56:32 +02:00
|
|
|
this._handle = {fd: {}};
|
2017-02-28 16:02:08 +01:00
|
|
|
this.listenerList = [];
|
2015-06-24 14:56:32 +02:00
|
|
|
|
2017-02-28 16:02:08 +01:00
|
|
|
return this;
|
2015-06-24 14:56:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
FakeIpcRequest.prototype.connect = function (path) {
|
|
|
|
assert.notEqual(path, undefined);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2017-02-28 16:02:08 +01:00
|
|
|
|
|
|
|
FakeIpcRequest.prototype.on = function (name, callback) {
|
2015-06-24 14:56:32 +02:00
|
|
|
if(name === 'data'){
|
2017-02-28 16:02:08 +01:00
|
|
|
this.listenerList.push(callback);
|
2015-06-24 14:56:32 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-28 16:02:08 +01:00
|
|
|
|
2015-06-24 21:50:27 +02:00
|
|
|
FakeIpcRequest.prototype.writeSync = function (payload) {
|
|
|
|
assert.equal(typeof payload, 'string');
|
|
|
|
return payload;
|
|
|
|
};
|
|
|
|
|
2015-06-24 14:56:32 +02:00
|
|
|
FakeIpcRequest.prototype.write = function (payload) {
|
|
|
|
assert.equal(typeof payload, 'string');
|
|
|
|
|
2017-02-28 16:02:08 +01:00
|
|
|
this.listenerList.forEach(function(cb){
|
2015-06-24 14:56:32 +02:00
|
|
|
setTimeout(function(){
|
|
|
|
cb(payload);
|
|
|
|
}, 100);
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-10-12 14:23:16 +08:00
|
|
|
module.exports = FakeIpcRequest;
|
2015-06-24 14:56:32 +02:00
|
|
|
|