diff --git a/__mocks__/electron.tsx b/__mocks__/electron.tsx index 05628cac2..ee2e4bbe6 100644 --- a/__mocks__/electron.tsx +++ b/__mocks__/electron.tsx @@ -20,4 +20,5 @@ module.exports = { }, getCurrentWindow: () => ({isFocused: () => true}), }, + ipcRenderer: {}, }; diff --git a/src/dispatcher/__tests__/plugins.electron.js b/src/dispatcher/__tests__/plugins.node.js similarity index 83% rename from src/dispatcher/__tests__/plugins.electron.js rename to src/dispatcher/__tests__/plugins.node.js index 570eace2b..14b3a813d 100644 --- a/src/dispatcher/__tests__/plugins.electron.js +++ b/src/dispatcher/__tests__/plugins.node.js @@ -14,7 +14,7 @@ import dispatcher, { requirePlugin, } from '../plugins.tsx'; import path from 'path'; -import {remote} from 'electron'; +import {ipcRenderer, remote} from 'electron'; import {FlipperPlugin} from 'flipper'; import reducers from '../../reducers/index.tsx'; import {init as initLogger} from '../../fb-stubs/Logger.tsx'; @@ -31,24 +31,20 @@ test('dispatcher dispatches REGISTER_PLUGINS', () => { expect(actions.map(a => a.type)).toContain('REGISTER_PLUGINS'); }); -test('getDynamicPlugins returns empty array', () => { - // $FlowFixMe process.env not defined in electron API spec - remote.process.env.PLUGINS = null; +test('getDynamicPlugins returns empty array on errors', () => { + ipcRenderer.sendSync = jest.fn(); + ipcRenderer.sendSync.mockImplementation(() => { + console.log('aaa'); + throw new Error('ooops'); + }); const res = getDynamicPlugins(); expect(res).toEqual([]); }); -test('getDynamicPlugins returns empty array for invalid JSON', () => { - // $FlowFixMe process.env not defined in electron API spec - remote.process.env.PLUGINS = 'invalid JOSN }}[]'; - const res = getDynamicPlugins(); - expect(res).toEqual([]); -}); - -test('getDynamicPlugins from env', () => { +test('getDynamicPlugins from main process via ipc', () => { const plugins = [{name: 'test'}]; - // $FlowFixMe process.env not defined in electron API spec - remote.process.env.PLUGINS = JSON.stringify(plugins); + ipcRenderer.sendSync = jest.fn(); + ipcRenderer.sendSync.mockReturnValue(plugins); const res = getDynamicPlugins(); expect(res).toEqual(plugins); }); diff --git a/src/dispatcher/plugins.tsx b/src/dispatcher/plugins.tsx index d2155579c..c96979f18 100644 --- a/src/dispatcher/plugins.tsx +++ b/src/dispatcher/plugins.tsx @@ -21,7 +21,7 @@ import { addDisabledPlugins, addFailedPlugins, } from '../reducers/plugins'; -import {remote} from 'electron'; +import {ipcRenderer} from 'electron'; import GK from '../fb-stubs/GK'; import {FlipperBasePlugin} from '../plugin'; import {setupMenuBar} from '../MenuBar'; @@ -110,9 +110,7 @@ function getBundledPlugins(): Array { export function getDynamicPlugins() { let dynamicPlugins: Array = []; try { - dynamicPlugins = JSON.parse( - (remote && remote.process.env.PLUGINS) || process.env.PLUGINS || '[]', - ); + dynamicPlugins = ipcRenderer.sendSync('get-dynamic-plugins'); } catch (e) { console.error(e); } diff --git a/static/index.js b/static/index.js index 11632628a..5853994f9 100644 --- a/static/index.js +++ b/static/index.js @@ -111,7 +111,9 @@ compilePlugins( pluginPaths, path.join(flipperDir, 'plugins'), ).then(dynamicPlugins => { - process.env.PLUGINS = JSON.stringify(dynamicPlugins); + ipcMain.on('get-dynamic-plugins', event => { + event.returnValue = dynamicPlugins; + }); pluginsCompiled = true; tryCreateWindow(); });