diff options
Diffstat (limited to 'test/helpers')
| -rw-r--r-- | test/helpers/IpcChain.js | 19 | ||||
| -rw-r--r-- | test/helpers/ipc-helpers.js | 26 |
2 files changed, 39 insertions, 6 deletions
diff --git a/test/helpers/IpcChain.js b/test/helpers/IpcChain.js index a7916e1e9f..a62626a6a6 100644 --- a/test/helpers/IpcChain.js +++ b/test/helpers/IpcChain.js @@ -8,11 +8,13 @@ export class IpcChain { _recordedCalls: Array<string>; _mockIpc: {}; _done: (*) => void; + _aborted: boolean; constructor(mockIpc: {}) { this._expectedCalls = []; this._recordedCalls = []; this._mockIpc = mockIpc; + this._aborted = false; } require(ipcCall: string): StepBuilder { @@ -28,10 +30,21 @@ export class IpcChain { } _stepPromiseCallback(step, resolve, args) { + if (this._aborted) { + return; + } + this._registerCall(step.ipcCall); if (step.inputValidation) { - failFast(() => step.inputValidation(...args), this._done); + const failedInputValidation = failFast(() => { + step.inputValidation(...args); + }, this._done); + + if (failedInputValidation) { + this._abort(); + return; + } } if (this._isLastCall()) { @@ -41,6 +54,10 @@ export class IpcChain { resolve(step.returnValue); } + _abort() { + this._aborted = true; + } + _isLastCall(): boolean { return this._recordedCalls.length === this._expectedCalls.length; } diff --git a/test/helpers/ipc-helpers.js b/test/helpers/ipc-helpers.js index 5e4b2941d6..e2a578973b 100644 --- a/test/helpers/ipc-helpers.js +++ b/test/helpers/ipc-helpers.js @@ -9,14 +9,24 @@ import { mockState, mockStore } from '../mocks/redux'; type DoneCallback = (?mixed) => void; type Check = () => void; -export function setupBackendAndStore() { - +export function setupIpcAndStore() { const memoryHistory = createMemoryHistory(); const store = configureStore(null, memoryHistory); const mockIpc = newMockIpc(); - const backend = new Backend(store, mockIpc); + return { store, mockIpc }; +} + +export function setupBackendAndStore() { + + const { store, mockIpc } = setupIpcAndStore(); + + const credentials = { + sharedSecret: '', + connectionString: '', + }; + const backend = new Backend(store, credentials, mockIpc); return { store, mockIpc, backend }; } @@ -24,7 +34,11 @@ export function setupBackendAndStore() { export function setupBackendAndMockStore() { const store = mockStore(mockState()); const mockIpc = newMockIpc(); - const backend = new Backend(store, mockIpc); + const credentials = { + sharedSecret: '', + connectionString: '', + }; + const backend = new Backend(store, credentials, mockIpc); return { store, mockIpc, backend }; } @@ -54,11 +68,13 @@ export function checkNextTick(fn: Check, done: DoneCallback) { // In async tests where we want to test a chain of IPC messages // we can only invoke `done` for the last message. This function // is for the intermediate messages. -export function failFast(fn: Check, done: DoneCallback) { +export function failFast(fn: Check, done: DoneCallback): boolean { try { fn(); + return false; } catch(e) { done(e); + return true; } } export function failFastNextTick(fn: Check, done: DoneCallback) { |
