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

81 lines
1.4 KiB
TypeScript
Raw Normal View History

import mkdirp from 'mkdirp';
import { EventEmitter } from 'events';
import os from 'os';
import path from 'path';
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: {
request() {
const req = new EventEmitter();
// @ts-expect-error -- TSCONVERSION appears to be genuine
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,
},
};
},
},
};
const electron = {
...remote,
remote,
ipcMain: {
on: jest.fn(),
once() {},
2016-11-23 23:42:10 +00:00
},
ipcRenderer: {
2020-11-11 22:44:03 +00:00
on: jest.fn(),
removeAllListeners: jest.fn(),
2018-06-25 17:42:50 +00:00
once() {},
send: jest.fn(),
},
shell: {
openExternal: jest.fn(),
},
};
// WARNING: changing this to `export default` will break the mock and be incredibly hard to debug. Ask me how I know.
module.exports = electron;