2017-02-26 19:58:48 -06:00
|
|
|
const path = require('path');
|
2017-03-23 18:19:59 -05:00
|
|
|
const EventEmitter = require('events');
|
|
|
|
|
|
|
|
let ipcEmitter = new EventEmitter();
|
2017-02-26 19:58:48 -06:00
|
|
|
|
2017-02-26 20:47:23 -06:00
|
|
|
// use config provided by test framework
|
2017-02-26 19:58:48 -06:00
|
|
|
function pathToConfigDir() {
|
2017-02-26 20:47:23 -06:00
|
|
|
return path.join(__dirname, '/../fixtures');
|
2017-02-26 19:58:48 -06:00
|
|
|
}
|
2017-03-23 18:19:59 -05:00
|
|
|
|
2017-05-13 13:23:44 -05:00
|
|
|
// electron app mock...
|
|
|
|
const app = {
|
|
|
|
getAppPath: pathToConfigDir,
|
|
|
|
getPath: function(type) {
|
|
|
|
if (type === 'exe') {
|
|
|
|
return path.join(pathToConfigDir(), '/Symphony.exe');
|
|
|
|
}
|
|
|
|
return pathToConfigDir();
|
|
|
|
},
|
|
|
|
on: function() {
|
|
|
|
// no-op
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-23 18:19:59 -05:00
|
|
|
// simple ipc mocks for render and main process ipc using
|
|
|
|
// nodes' EventEmitter
|
|
|
|
const ipcMain = {
|
|
|
|
on: function(event, cb) {
|
|
|
|
ipcEmitter.on(event, cb);
|
2017-05-13 13:23:44 -05:00
|
|
|
},
|
|
|
|
send: function (event, args) {
|
|
|
|
var senderEvent = {
|
|
|
|
sender: {
|
|
|
|
send: function (event, arg) {
|
|
|
|
ipcEmitter.emit(event, arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
ipcEmitter.emit(event, senderEvent, args);
|
|
|
|
},
|
|
|
|
};
|
2017-03-23 18:19:59 -05:00
|
|
|
|
|
|
|
const ipcRenderer = {
|
|
|
|
sendSync: function(event, args) {
|
|
|
|
let listeners = ipcEmitter.listeners(event);
|
|
|
|
if (listeners.length > 0) {
|
|
|
|
let listener = listeners[0];
|
2017-05-13 13:23:44 -05:00
|
|
|
var eventArg = {};
|
2017-03-23 18:19:59 -05:00
|
|
|
listener(eventArg, args);
|
|
|
|
return eventArg.returnValue;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
send: function(event, args) {
|
|
|
|
var senderEvent = {
|
|
|
|
sender: {
|
|
|
|
send: function(event, arg) {
|
|
|
|
ipcEmitter.emit(event, arg);
|
|
|
|
}
|
|
|
|
}
|
2017-05-13 13:23:44 -05:00
|
|
|
};
|
2017-03-23 18:19:59 -05:00
|
|
|
ipcEmitter.emit(event, senderEvent, args);
|
|
|
|
},
|
|
|
|
on: function(eventName, cb) {
|
|
|
|
ipcEmitter.on(eventName, cb);
|
|
|
|
},
|
|
|
|
removeListener: function(eventName, cb) {
|
|
|
|
ipcEmitter.removeListener(eventName, cb);
|
2017-02-26 20:47:23 -06:00
|
|
|
}
|
2017-05-13 13:23:44 -05:00
|
|
|
};
|
2017-02-26 19:58:48 -06:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
require: jest.genMockFunction(),
|
|
|
|
match: jest.genMockFunction(),
|
2017-04-26 11:46:15 -05:00
|
|
|
app: jest.genMockFunction(),
|
2017-03-23 18:19:59 -05:00
|
|
|
ipcMain: ipcMain,
|
|
|
|
ipcRenderer: ipcRenderer,
|
2017-02-26 19:58:48 -06:00
|
|
|
remote: jest.genMockFunction(),
|
|
|
|
dialog: jest.genMockFunction()
|
|
|
|
};
|