insomnia/packages/insomnia-app/app/__mocks__/electron.js

60 lines
1.0 KiB
JavaScript
Raw Normal View History

import mkdirp from 'mkdirp';
import events from 'events';
import os from 'os';
import path from 'path';
2018-06-25 17:42:50 +00:00
const RANDOM_STRING = Math.random()
.toString()
.replace('.', '');
const remote = {
app: {
2018-06-25 17:42:50 +00:00
getPath(name) {
const dir = path.join(os.tmpdir(), `insomnia-tests-${RANDOM_STRING}`, name);
mkdirp.sync(dir);
return dir;
},
2018-06-25 17:42:50 +00:00
getLocale() {
return 'en-US';
},
},
net: {
2018-06-25 17:42:50 +00:00
request(url) {
const req = new events.EventEmitter();
2018-06-25 17:42:50 +00:00
req.end = function() {};
return req;
},
},
BrowserWindow: {
2018-06-25 17:42:50 +00:00
getAllWindows() {
return [];
},
2018-06-25 17:42:50 +00:00
getFocusedWindow() {
return {
2018-06-25 17:42:50 +00:00
getContentBounds() {
return { width: 1900, height: 1060 };
},
};
},
},
screen: {
2018-06-25 17:42:50 +00:00
getPrimaryDisplay() {
return { workAreaSize: { width: 1920, height: 1080 } };
},
},
};
module.exports = {
...remote,
remote: remote,
ipcMain: {
2018-06-25 17:42:50 +00:00
on() {},
once() {},
2016-11-23 23:42:10 +00:00
},
ipcRenderer: {
2018-06-25 17:42:50 +00:00
on() {},
once() {},
send() {},
},
};