2021-05-12 06:35:00 +00:00
|
|
|
import { EventEmitter } from 'events';
|
2021-07-22 23:04:56 +00:00
|
|
|
import mkdirp from 'mkdirp';
|
2020-08-30 11:17:15 +00:00
|
|
|
import os from 'os';
|
|
|
|
import path from 'path';
|
2017-11-18 22:47:54 +00:00
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
const RANDOM_STRING = Math.random().toString().replace('.', '');
|
2017-06-30 03:30:22 +00:00
|
|
|
|
2017-11-17 12:10:37 +00:00
|
|
|
const remote = {
|
|
|
|
app: {
|
2018-06-25 17:42:50 +00:00
|
|
|
getPath(name) {
|
2020-08-30 11:17:15 +00:00
|
|
|
const dir = path.join(os.tmpdir(), `insomnia-tests-${RANDOM_STRING}`, name);
|
2017-11-17 12:10:37 +00:00
|
|
|
mkdirp.sync(dir);
|
|
|
|
return dir;
|
2017-11-18 22:47:54 +00:00
|
|
|
},
|
2021-05-12 06:35:00 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
getLocale() {
|
2017-11-18 22:47:54 +00:00
|
|
|
return 'en-US';
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2021-10-20 02:10:48 +00:00
|
|
|
|
|
|
|
exit: jest.fn(),
|
2017-11-18 22:47:54 +00:00
|
|
|
},
|
|
|
|
net: {
|
2021-05-12 06:35:00 +00:00
|
|
|
request() {
|
|
|
|
const req = new EventEmitter();
|
|
|
|
|
|
|
|
// @ts-expect-error -- TSCONVERSION appears to be genuine
|
2018-06-25 17:42:50 +00:00
|
|
|
req.end = function() {};
|
2021-05-12 06:35:00 +00:00
|
|
|
|
2017-11-18 22:47:54 +00:00
|
|
|
return req;
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2017-11-17 12:10:37 +00:00
|
|
|
},
|
|
|
|
BrowserWindow: {
|
2018-06-25 17:42:50 +00:00
|
|
|
getAllWindows() {
|
2017-11-17 12:10:37 +00:00
|
|
|
return [];
|
2017-11-18 22:47:54 +00:00
|
|
|
},
|
2021-05-12 06:35:00 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
getFocusedWindow() {
|
2017-11-18 22:47:54 +00:00
|
|
|
return {
|
2018-06-25 17:42:50 +00:00
|
|
|
getContentBounds() {
|
2021-05-12 06:35:00 +00:00
|
|
|
return {
|
|
|
|
width: 1900,
|
|
|
|
height: 1060,
|
|
|
|
};
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2017-11-18 22:47:54 +00:00
|
|
|
};
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2017-11-18 22:47:54 +00:00
|
|
|
},
|
|
|
|
screen: {
|
2018-06-25 17:42:50 +00:00
|
|
|
getPrimaryDisplay() {
|
2021-05-12 06:35:00 +00:00
|
|
|
return {
|
|
|
|
workAreaSize: {
|
|
|
|
width: 1920,
|
|
|
|
height: 1080,
|
|
|
|
},
|
|
|
|
};
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
|
|
|
},
|
2017-11-17 12:10:37 +00:00
|
|
|
};
|
|
|
|
|
2021-10-20 02:10:48 +00:00
|
|
|
const dialog = {
|
|
|
|
showErrorBox: jest.fn(),
|
|
|
|
};
|
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
const electron = {
|
2017-11-17 12:10:37 +00:00
|
|
|
...remote,
|
2021-05-12 06:35:00 +00:00
|
|
|
remote,
|
2021-10-20 02:10:48 +00:00
|
|
|
dialog,
|
2017-11-17 12:10:37 +00:00
|
|
|
ipcMain: {
|
2020-11-10 00:30:27 +00:00
|
|
|
on: jest.fn(),
|
2021-05-12 06:35:00 +00:00
|
|
|
|
2018-12-12 17:36:11 +00:00
|
|
|
once() {},
|
2016-11-23 23:42:10 +00:00
|
|
|
},
|
|
|
|
ipcRenderer: {
|
2020-11-11 22:44:03 +00:00
|
|
|
on: jest.fn(),
|
|
|
|
removeAllListeners: jest.fn(),
|
2021-05-12 06:35:00 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
once() {},
|
2021-05-12 06:35:00 +00:00
|
|
|
|
2020-11-25 19:18:42 +00:00
|
|
|
send: jest.fn(),
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2021-05-12 20:20:52 +00:00
|
|
|
shell: {
|
|
|
|
openExternal: jest.fn(),
|
|
|
|
},
|
2021-09-01 17:40:11 +00:00
|
|
|
clipboard: {
|
|
|
|
writeText: jest.fn(),
|
|
|
|
readText: jest.fn(),
|
|
|
|
clear: jest.fn(),
|
|
|
|
},
|
2017-03-03 01:44:07 +00:00
|
|
|
};
|
2021-05-12 06:35:00 +00:00
|
|
|
|
|
|
|
// WARNING: changing this to `export default` will break the mock and be incredibly hard to debug. Ask me how I know.
|
|
|
|
module.exports = electron;
|