diff --git a/app/lib/lnd/config.js b/app/lib/lnd/config.js index bfd0b4e5..e61329fb 100644 --- a/app/lib/lnd/config.js +++ b/app/lib/lnd/config.js @@ -141,7 +141,9 @@ class LndConfig { }, binaryPath: { enumerable: true, - value: binaryPath + get() { + return binaryPath() + } }, dataDir: { enumerable: true, @@ -152,13 +154,13 @@ class LndConfig { configPath: { enumerable: true, get() { - return join(appRootPath, 'resources', 'lnd.conf') + return join(appRootPath(), 'resources', 'lnd.conf') } }, rpcProtoPath: { enumerable: true, get() { - return join(appRootPath, 'resources', 'rpc.proto') + return join(appRootPath(), 'resources', 'rpc.proto') } }, diff --git a/app/lib/lnd/util.js b/app/lib/lnd/util.js index 0656abdd..08cc2244 100644 --- a/app/lib/lnd/util.js +++ b/app/lib/lnd/util.js @@ -33,8 +33,9 @@ const dnsLookup = promisify(dns.lookup) * And no, we can't just set our working directory to somewhere inside the asar. The OS can't handle that. * @return {String} Path to the lnd binary. */ -export const appRootPath = - app.getAppPath().indexOf('default_app.asar') < 0 ? normalize(`${app.getAppPath()}/..`) : '' +export const appRootPath = () => { + return app.getAppPath().indexOf('default_app.asar') < 0 ? normalize(`${app.getAppPath()}/..`) : '' +} /** * Get the OS specific lnd binary name. @@ -46,9 +47,11 @@ export const binaryName = platform() === 'win32' ? 'lnd.exe' : 'lnd' * Get the OS specific path to the lnd binary. * @return {String} Path to the lnd binary. */ -export const binaryPath = isDev - ? join(dirname(require.resolve('lnd-binary/package.json')), 'vendor', binaryName) - : join(appRootPath, 'bin', binaryName) +export const binaryPath = () => { + return isDev + ? join(dirname(require.resolve('lnd-binary/package.json')), 'vendor', binaryName) + : join(appRootPath(), 'bin', binaryName) +} // ------------------------------------ // Helpers diff --git a/test/e2e/e2e.spec.js b/test/e2e/e2e.spec.js index 0760032c..e8769781 100644 --- a/test/e2e/e2e.spec.js +++ b/test/e2e/e2e.spec.js @@ -2,6 +2,8 @@ import { Application } from 'spectron' import electronPath from 'electron' import path from 'path' +jest.unmock('electron') + jasmine.DEFAULT_TIMEOUT_INTERVAL = 15000 const delay = time => new Promise(resolve => setTimeout(resolve, time)) diff --git a/test/unit/__mocks__/electron.js b/test/unit/__mocks__/electron.js new file mode 100644 index 00000000..e4cb4e68 --- /dev/null +++ b/test/unit/__mocks__/electron.js @@ -0,0 +1,13 @@ +const { normalize } = require('path') + +module.exports = { + require: jest.fn(), + match: jest.fn(), + app: { + getPath: name => normalize(`/tmp/zap-test/${name}`), + getAppPath: () => normalize('/tmp/zap-test') + }, + remote: jest.fn(), + dialog: jest.fn(), + BrowserWindow: jest.fn() +} diff --git a/test/unit/lnd/lnd-config.spec.js b/test/unit/lnd/lnd-config.spec.js index 80ca746a..4767f20b 100644 --- a/test/unit/lnd/lnd-config.spec.js +++ b/test/unit/lnd/lnd-config.spec.js @@ -4,46 +4,25 @@ import { join, normalize } from 'path' import Store from 'electron-store' import LndConfig from 'lib/lnd/config' -jest.mock('grpc') - -jest.mock('electron', () => { - const { normalize } = require('path') - - return { - app: { - getPath: name => normalize(`/tmp/zap-test/${name}`), - getAppPath: () => normalize('/tmp/zap-test') - } - } -}) - +jest.mock('electron-store') jest.mock('lib/lnd/util', () => { - const { normalize } = require('path') - return { ...jest.requireActual('lib/lnd/util'), - appRootPath: normalize('/tmp/zap-test/app/root'), binaryName: 'binaryName', - binaryPath: 'binaryPath' + binaryPath: () => 'binaryPath' } }) -Store.prototype.set = jest.fn() - describe('LndConfig', function() { const checkForStaticProperties = () => { it('should have "binaryPath" set to the value returned by lib/lnd/util', () => { expect(this.lndConfig.binaryPath).toEqual('binaryPath') }) it('should have "configPath" set to "resources/lnd.conf" relative to app root from lib/lnd/util"', () => { - expect(this.lndConfig.configPath).toEqual( - normalize('/tmp/zap-test/app/root/resources/lnd.conf') - ) + expect(this.lndConfig.configPath).toEqual(normalize('/tmp/resources/lnd.conf')) }) it('should have "rpcProtoPath" set to "resources/rcp.proto" relative to app root from lib/lnd/util"', () => { - expect(this.lndConfig.rpcProtoPath).toEqual( - normalize('/tmp/zap-test/app/root/resources/rpc.proto') - ) + expect(this.lndConfig.rpcProtoPath).toEqual(normalize('/tmp/resources/rpc.proto')) }) } diff --git a/test/unit/lnd/neutrino.spec.js b/test/unit/lnd/neutrino.spec.js index c89c3489..012e1f13 100644 --- a/test/unit/lnd/neutrino.spec.js +++ b/test/unit/lnd/neutrino.spec.js @@ -1,15 +1,6 @@ import Neutrino from 'lib/lnd/neutrino' -jest.mock('electron', () => { - const { normalize } = require('path') - - return { - app: { - getPath: name => normalize(`/tmp/zap-test/${name}`), - getAppPath: () => normalize('/tmp/zap-test') - } - } -}) +jest.mock('electron-store') describe('Neutrino', function() { describe('Constructor', () => {