summaryrefslogtreecommitdiffhomepage
path: root/test/helpers/IpcChain.js
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2018-02-21 10:45:11 +0100
committerAndrej Mihajlov <and@mullvad.net>2018-02-21 10:45:11 +0100
commitde737c54c413f96c35b4e9bc6280fc7d26e4fa83 (patch)
tree0cf470c59b4c7c8a6327e64610f68f5facd78d6d /test/helpers/IpcChain.js
parentae9c255b3ecdec341090c932db6cb261147a7382 (diff)
parent1214138633bcca19a1b96622400f3fbcf4044bd9 (diff)
downloadmullvadvpn-de737c54c413f96c35b4e9bc6280fc7d26e4fa83.tar.xz
mullvadvpn-de737c54c413f96c35b4e9bc6280fc7d26e4fa83.zip
Merge branch 'update-flow'
Diffstat (limited to 'test/helpers/IpcChain.js')
-rw-r--r--test/helpers/IpcChain.js27
1 files changed, 14 insertions, 13 deletions
diff --git a/test/helpers/IpcChain.js b/test/helpers/IpcChain.js
index a62626a6a6..4e3ddea79e 100644
--- a/test/helpers/IpcChain.js
+++ b/test/helpers/IpcChain.js
@@ -7,7 +7,7 @@ export class IpcChain {
_expectedCalls: Array<string>;
_recordedCalls: Array<string>;
_mockIpc: {};
- _done: (*) => void;
+ _done: (?Error) => void;
_aborted: boolean;
constructor(mockIpc: {}) {
@@ -17,28 +17,29 @@ export class IpcChain {
this._aborted = false;
}
- require(ipcCall: string): StepBuilder {
+ require<R>(ipcCall: string): StepBuilder<R> {
this._expectedCalls.push(ipcCall);
return new StepBuilder(ipcCall, this._addStep.bind(this));
}
- _addStep(step: StepBuilder) {
+ _addStep<R>(step: StepBuilder<R>) {
const me = this;
this._mockIpc[step.ipcCall] = function() {
return new Promise(r => me._stepPromiseCallback(step, r, arguments));
};
}
- _stepPromiseCallback(step, resolve, args) {
+ _stepPromiseCallback<R>(step: StepBuilder<R>, resolve: (?R) => void, args: Array<mixed>) {
if (this._aborted) {
return;
}
this._registerCall(step.ipcCall);
- if (step.inputValidation) {
+ const inputValidation = step.inputValidation;
+ if (inputValidation) {
const failedInputValidation = failFast(() => {
- step.inputValidation(...args);
+ inputValidation(...args);
}, this._done);
if (failedInputValidation) {
@@ -77,23 +78,23 @@ export class IpcChain {
}
}
-class StepBuilder {
+class StepBuilder<R> {
ipcCall: string;
- inputValidation: () => void;
- returnValue: *;
- _cb: (StepBuilder) => void;
+ inputValidation: ?() => void;
+ returnValue: ?R;
+ _cb: (StepBuilder<R>) => void;
- constructor(ipcCall: string, cb: (StepBuilder)=> void) {
+ constructor(ipcCall: string, cb: (StepBuilder<R>) => void) {
this.ipcCall = ipcCall;
this._cb = cb;
}
- withInputValidation(iv: () => void): StepBuilder {
+ withInputValidation(iv: () => void): this {
this.inputValidation = iv;
return this;
}
- withReturnValue(rv: *): StepBuilder {
+ withReturnValue(rv: R): this {
this.returnValue = rv;
return this;
}