summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/.eslintrc13
-rw-r--r--test/auth.spec.js49
-rw-r--r--test/autologin.spec.js15
-rw-r--r--test/components/Account.spec.js3
-rw-r--r--test/components/AccountInput.spec.js2
-rw-r--r--test/components/Connect.spec.js3
-rw-r--r--test/components/HeaderBar.spec.js1
-rw-r--r--test/components/Login.spec.js10
-rw-r--r--test/components/Preferences.spec.js3
-rw-r--r--test/components/SelectLocation.spec.js1
-rw-r--r--test/components/Settings.spec.js3
-rw-r--r--test/components/Support.spec.js12
-rw-r--r--test/components/Switch.spec.js1
-rw-r--r--test/connect.spec.js1
-rw-r--r--test/helpers/IpcChain.js25
-rw-r--r--test/ipc.spec.js6
-rw-r--r--test/keyframe-animation.spec.js39
-rw-r--r--test/login.spec.js19
-rw-r--r--test/logout.spec.js12
-rw-r--r--test/mocks/ipc.js8
-rw-r--r--test/relay-settings-builder.spec.js1
-rw-r--r--test/setup/renderer.js7
-rw-r--r--test/transition-rule.spec.js2
23 files changed, 109 insertions, 127 deletions
diff --git a/test/.eslintrc b/test/.eslintrc
new file mode 100644
index 0000000000..00c8d44bb9
--- /dev/null
+++ b/test/.eslintrc
@@ -0,0 +1,13 @@
+{
+ "rules": {
+ "no-unused-expressions" : "off",
+ "react/no-render-return-value": "off"
+ },
+ "env": {
+ "mocha": true
+ },
+ "globals": {
+ "expect": true,
+ "spy": true
+ }
+} \ No newline at end of file
diff --git a/test/auth.spec.js b/test/auth.spec.js
index effc3473cb..e6b2c25486 100644
--- a/test/auth.spec.js
+++ b/test/auth.spec.js
@@ -1,56 +1,37 @@
// @flow
-import { expect } from 'chai';
-import {
- setupIpcAndStore,
- setupBackendAndStore,
- failFast,
- checkNextTick,
-} from './helpers/ipc-helpers';
+import { setupIpcAndStore, setupBackendAndStore } from './helpers/ipc-helpers';
import { IpcChain } from './helpers/IpcChain';
import { Backend } from '../app/lib/backend';
describe('authentication', () => {
it('authenticates before ipc call if unauthenticated', (done) => {
const { store, mockIpc } = setupIpcAndStore();
- const credentials = {
- sharedSecret: 'foo',
- connectionString: '',
- };
const chain = new IpcChain(mockIpc);
- chain
- .require('authenticate')
- .withInputValidation((secret) => {
- expect(secret).to.equal(credentials.sharedSecret);
- })
- .done();
-
- chain.require('connect').done();
-
chain.onSuccessOrFailure(done);
+ chain.expect('authenticate').withInputValidation((secret) => {
+ expect(secret).to.equal(credentials.sharedSecret);
+ });
+ chain.expect('connect');
+ const credentials = {
+ sharedSecret: '',
+ connectionString: '',
+ };
const backend = new Backend(store, credentials, mockIpc);
backend.connect();
});
- it('reauthenticates on reconnect', (done) => {
+ it('reauthenticates on reconnect', async () => {
const { mockIpc, backend } = setupBackendAndStore();
- let authCount = 0;
- mockIpc.authenticate = () => {
- authCount++;
- return Promise.resolve();
- };
-
+ mockIpc.authenticate = spy(mockIpc.authenticate);
mockIpc.killWebSocket();
- failFast(() => {
- expect(authCount).to.equal(0);
- }, done);
- backend.connect();
- checkNextTick(() => {
- expect(authCount).to.equal(1);
- }, done);
+ expect(mockIpc.authenticate).to.not.have.been.called();
+
+ await backend.connect();
+ expect(mockIpc.authenticate).to.have.been.called.once;
});
});
diff --git a/test/autologin.spec.js b/test/autologin.spec.js
index debacc6c60..60c5cc5bde 100644
--- a/test/autologin.spec.js
+++ b/test/autologin.spec.js
@@ -1,6 +1,5 @@
// @flow
-import { expect } from 'chai';
import { setupBackendAndStore, setupBackendAndMockStore, getLocation } from './helpers/ipc-helpers';
import { IpcChain } from './helpers/IpcChain';
@@ -11,17 +10,11 @@ describe('autologin', () => {
const randomAccountToken = '12345';
const chain = new IpcChain(mockIpc);
- chain
- .require('getAccount')
- .withReturnValue(randomAccountToken)
- .done();
+ chain.expect('getAccount').withReturnValue(randomAccountToken);
- chain
- .require('getAccountData')
- .withInputValidation((num) => {
- expect(num).to.equal(randomAccountToken);
- })
- .done();
+ chain.expect('getAccountData').withInputValidation((num) => {
+ expect(num).to.equal(randomAccountToken);
+ });
chain.onSuccessOrFailure(done);
diff --git a/test/components/Account.spec.js b/test/components/Account.spec.js
index 2476cc35e0..2c0979bb50 100644
--- a/test/components/Account.spec.js
+++ b/test/components/Account.spec.js
@@ -1,7 +1,6 @@
// @flow
-import { expect } from 'chai';
-import React from 'react';
+import * as React from 'react';
import { shallow } from 'enzyme';
import Account from '../../app/components/Account';
import type { AccountProps } from '../../app/components/Account';
diff --git a/test/components/AccountInput.spec.js b/test/components/AccountInput.spec.js
index eface9c8c6..2f6ead1b45 100644
--- a/test/components/AccountInput.spec.js
+++ b/test/components/AccountInput.spec.js
@@ -1,5 +1,5 @@
// @flow
-import { expect } from 'chai';
+
import { createKeyEvent } from '../helpers/dom-events';
import * as React from 'react';
import { shallow } from 'enzyme';
diff --git a/test/components/Connect.spec.js b/test/components/Connect.spec.js
index 64771248b6..d21a8eb510 100644
--- a/test/components/Connect.spec.js
+++ b/test/components/Connect.spec.js
@@ -1,7 +1,6 @@
// @flow
-import { expect } from 'chai';
-import React from 'react';
+import * as React from 'react';
import { shallow } from 'enzyme';
import Connect from '../../app/components/Connect';
diff --git a/test/components/HeaderBar.spec.js b/test/components/HeaderBar.spec.js
index b5fb6bb7b6..6fcbfb54d7 100644
--- a/test/components/HeaderBar.spec.js
+++ b/test/components/HeaderBar.spec.js
@@ -1,6 +1,5 @@
// @flow
-import { expect } from 'chai';
import React from 'react';
import { shallow } from 'enzyme';
import HeaderBar from '../../app/components/HeaderBar';
diff --git a/test/components/Login.spec.js b/test/components/Login.spec.js
index 1c75904717..90bb70f4b3 100644
--- a/test/components/Login.spec.js
+++ b/test/components/Login.spec.js
@@ -1,16 +1,14 @@
// @flow
-import { expect } from 'chai';
import * as React from 'react';
import { shallow } from 'enzyme';
-import sinon from 'sinon';
import Login from '../../app/components/Login';
import AccountInput from '../../app/components/AccountInput';
describe('components/Login', () => {
it('notifies on the first change after failure', () => {
- let onFirstChange = sinon.spy();
+ let onFirstChange = spy();
const props = {
account: Object.assign({}, defaultAccount, {
status: 'failed',
@@ -22,12 +20,10 @@ describe('components/Login', () => {
const accountInput = component.find(AccountInput);
accountInput.simulate('change', 'foo');
- expect(onFirstChange.calledOnce).to.be.true;
-
- onFirstChange.resetHistory();
+ expect(onFirstChange).to.have.been.called.once;
accountInput.simulate('change', 'bar');
- expect(onFirstChange.calledOnce).to.be.false;
+ expect(onFirstChange).to.have.been.called.once;
});
it('does not show the footer when logging in', () => {
diff --git a/test/components/Preferences.spec.js b/test/components/Preferences.spec.js
index 3b6976a1ec..280b24ccd7 100644
--- a/test/components/Preferences.spec.js
+++ b/test/components/Preferences.spec.js
@@ -1,7 +1,6 @@
// @flow
-import { expect } from 'chai';
-import React from 'react';
+import * as React from 'react';
import { shallow } from 'enzyme';
import Preferences from '../../app/components/Preferences';
diff --git a/test/components/SelectLocation.spec.js b/test/components/SelectLocation.spec.js
index 8310d52b97..c9a1f08864 100644
--- a/test/components/SelectLocation.spec.js
+++ b/test/components/SelectLocation.spec.js
@@ -1,6 +1,5 @@
// @flow
-import { expect } from 'chai';
import * as React from 'react';
import { shallow } from 'enzyme';
import SelectLocation from '../../app/components/SelectLocation';
diff --git a/test/components/Settings.spec.js b/test/components/Settings.spec.js
index 61ca47e3e4..f564902c2a 100644
--- a/test/components/Settings.spec.js
+++ b/test/components/Settings.spec.js
@@ -1,7 +1,6 @@
// @flow
-import { expect } from 'chai';
-import React from 'react';
+import * as React from 'react';
import Settings from '../../app/components/Settings';
import { shallow } from 'enzyme';
diff --git a/test/components/Support.spec.js b/test/components/Support.spec.js
index 653c376713..ce1efb2b75 100644
--- a/test/components/Support.spec.js
+++ b/test/components/Support.spec.js
@@ -1,10 +1,8 @@
// @flow
-import { expect } from 'chai';
-import React from 'react';
+import * as React from 'react';
import Support from '../../app/components/Support';
import { shallow } from 'enzyme';
-import sinon from 'sinon';
import type { SupportProps } from '../../app/components/Support';
describe('components/Support', () => {
@@ -63,7 +61,7 @@ describe('components/Support', () => {
});
it('should not collect report twice', (done) => {
- const collectCallback = sinon.spy(() => Promise.resolve('non-falsy'));
+ const collectCallback = spy(() => Promise.resolve('non-falsy'));
const props = makeProps({
onCollectLog: collectCallback,
});
@@ -77,7 +75,7 @@ describe('components/Support', () => {
setTimeout(() => {
try {
- expect(collectCallback.callCount).to.equal(1);
+ expect(collectCallback).to.have.been.called.once;
done();
} catch (e) {
done(e);
@@ -86,12 +84,12 @@ describe('components/Support', () => {
});
it('should collect report on submission', (done) => {
- const collectCallback = sinon.spy(() => Promise.resolve(''));
+ const collectCallback = spy(() => Promise.resolve(''));
const props = makeProps({
onCollectLog: collectCallback,
onSend: (_report) => {
try {
- expect(collectCallback.calledOnce).to.be.true;
+ expect(collectCallback).to.have.been.called.once;
done();
} catch (e) {
done(e);
diff --git a/test/components/Switch.spec.js b/test/components/Switch.spec.js
index e1242d74df..44794d9bba 100644
--- a/test/components/Switch.spec.js
+++ b/test/components/Switch.spec.js
@@ -1,6 +1,5 @@
// @flow
-import { expect } from 'chai';
import * as React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils, { Simulate } from 'react-dom/test-utils';
diff --git a/test/connect.spec.js b/test/connect.spec.js
index 0b5b33be53..f1621dbeb6 100644
--- a/test/connect.spec.js
+++ b/test/connect.spec.js
@@ -1,6 +1,5 @@
// @flow
-import { expect } from 'chai';
import connectionActions from '../app/redux/connection/actions';
import { setupBackendAndStore, checkNextTick } from './helpers/ipc-helpers';
diff --git a/test/helpers/IpcChain.js b/test/helpers/IpcChain.js
index 44a1c7b0d7..1505621cc0 100644
--- a/test/helpers/IpcChain.js
+++ b/test/helpers/IpcChain.js
@@ -1,6 +1,5 @@
// @flow
-import { expect } from 'chai';
import { check, failFast } from './ipc-helpers';
export class IpcChain {
@@ -17,15 +16,17 @@ export class IpcChain {
this._aborted = false;
}
- require<R>(ipcCall: string): StepBuilder<R> {
+ expect<R>(ipcCall: string): StepBuilder<R> {
+ const builder = new StepBuilder(ipcCall);
this._expectedCalls.push(ipcCall);
- return new StepBuilder(ipcCall, this._addStep.bind(this));
+ this._addStep(builder);
+
+ return builder;
}
_addStep<R>(step: StepBuilder<R>) {
- const me = this;
- this._mockIpc[step.ipcCall] = function() {
- return new Promise((r) => me._stepPromiseCallback(step, r, arguments));
+ this._mockIpc[step.ipcCall] = (...args: Array<mixed>) => {
+ return new Promise((r) => this._stepPromiseCallback(step, r, args));
};
}
@@ -80,16 +81,14 @@ export class IpcChain {
class StepBuilder<R> {
ipcCall: string;
- inputValidation: ?() => void;
+ inputValidation: ?(...args: Array<mixed>) => void;
returnValue: ?R;
- _cb: (StepBuilder<R>) => void;
- constructor(ipcCall: string, cb: (StepBuilder<R>) => void) {
+ constructor(ipcCall: string) {
this.ipcCall = ipcCall;
- this._cb = cb;
}
- withInputValidation(iv: () => void): this {
+ withInputValidation(iv: (...args: Array<mixed>) => void): this {
this.inputValidation = iv;
return this;
}
@@ -98,8 +97,4 @@ class StepBuilder<R> {
this.returnValue = rv;
return this;
}
-
- done() {
- this._cb(this);
- }
}
diff --git a/test/ipc.spec.js b/test/ipc.spec.js
index 43d6e9e2f4..1c8b19b5a6 100644
--- a/test/ipc.spec.js
+++ b/test/ipc.spec.js
@@ -2,8 +2,6 @@
import Ipc from '../app/lib/jsonrpc-ws-ipc';
import jsonrpc from 'jsonrpc-lite';
-import { expect } from 'chai';
-import assert from 'assert';
import type { JsonRpcMessage } from '../app/lib/jsonrpc-ws-ipc';
describe('The IPC server', () => {
@@ -45,7 +43,9 @@ describe('The IPC server', () => {
const decoy = ipc
.send('a decoy', [], 1)
- .then(() => assert(false, 'Should not be called'))
+ .then(() => {
+ throw new Error('Should not be called');
+ })
.catch((e) => {
if (e.name !== 'TimeOutError') {
throw e;
diff --git a/test/keyframe-animation.spec.js b/test/keyframe-animation.spec.js
index 5153719497..926bb79625 100644
--- a/test/keyframe-animation.spec.js
+++ b/test/keyframe-animation.spec.js
@@ -1,4 +1,5 @@
-import { expect } from 'chai';
+// @flow
+
import KeyframeAnimation from '../app/lib/keyframe-animation';
import { nativeImage } from 'electron';
@@ -15,7 +16,9 @@ describe('lib/keyframe-animation', function() {
it('should play sequence', (done) => {
let seq = [];
const animation = newAnimation();
- animation.onFrame = () => seq.push(animation._currentFrame);
+ animation.onFrame = () => {
+ seq.push(animation._currentFrame);
+ };
animation.onFinish = () => {
expect(seq).to.be.deep.equal([0, 1, 2, 3, 4]);
expect(animation._currentFrame).to.be.equal(4);
@@ -28,7 +31,9 @@ describe('lib/keyframe-animation', function() {
it('should play one frame', (done) => {
let seq = [];
const animation = newAnimation();
- animation.onFrame = () => seq.push(animation._currentFrame);
+ animation.onFrame = () => {
+ seq.push(animation._currentFrame);
+ };
animation.onFinish = () => {
expect(seq).to.be.deep.equal([3]);
expect(animation._currentFrame).to.be.equal(3);
@@ -41,7 +46,9 @@ describe('lib/keyframe-animation', function() {
it('should play sequence with custom frames', (done) => {
let seq = [];
const animation = newAnimation();
- animation.onFrame = () => seq.push(animation._currentFrame);
+ animation.onFrame = () => {
+ seq.push(animation._currentFrame);
+ };
animation.onFinish = () => {
expect(seq).to.be.deep.equal([2, 3, 4]);
expect(animation._currentFrame).to.be.equal(4);
@@ -57,7 +64,9 @@ describe('lib/keyframe-animation', function() {
it('should play sequence with custom frames in reverse', (done) => {
let seq = [];
const animation = newAnimation();
- animation.onFrame = () => seq.push(animation._currentFrame);
+ animation.onFrame = () => {
+ seq.push(animation._currentFrame);
+ };
animation.onFinish = () => {
expect(seq).to.be.deep.equal([4, 3, 2]);
expect(animation._currentFrame).to.be.equal(2);
@@ -74,7 +83,9 @@ describe('lib/keyframe-animation', function() {
it('should begin from current state starting below range', (done) => {
let seq = [];
const animation = newAnimation();
- animation.onFrame = () => seq.push(animation._currentFrame);
+ animation.onFrame = () => {
+ seq.push(animation._currentFrame);
+ };
animation.onFinish = () => {
expect(seq).to.be.deep.equal([0, 1, 2, 3, 4]);
expect(animation._currentFrame).to.be.equal(4);
@@ -94,7 +105,9 @@ describe('lib/keyframe-animation', function() {
it('should begin from current state starting below range reverse', (done) => {
let seq = [];
const animation = newAnimation();
- animation.onFrame = () => seq.push(animation._currentFrame);
+ animation.onFrame = () => {
+ seq.push(animation._currentFrame);
+ };
animation.onFinish = () => {
expect(seq).to.be.deep.equal([0, 1, 2, 3]);
expect(animation._currentFrame).to.be.equal(3);
@@ -115,7 +128,9 @@ describe('lib/keyframe-animation', function() {
it('should begin from current state starting above range', (done) => {
let seq = [];
const animation = newAnimation();
- animation.onFrame = () => seq.push(animation._currentFrame);
+ animation.onFrame = () => {
+ seq.push(animation._currentFrame);
+ };
animation.onFinish = () => {
expect(seq).to.be.deep.equal([4, 3, 2]);
expect(animation._currentFrame).to.be.equal(2);
@@ -135,7 +150,9 @@ describe('lib/keyframe-animation', function() {
it('should begin from current state starting above range reverse', (done) => {
let seq = [];
const animation = newAnimation();
- animation.onFrame = () => seq.push(animation._currentFrame);
+ animation.onFrame = () => {
+ seq.push(animation._currentFrame);
+ };
animation.onFinish = () => {
expect(seq).to.be.deep.equal([4, 3, 2, 1]);
expect(animation._currentFrame).to.be.equal(1);
@@ -156,7 +173,9 @@ describe('lib/keyframe-animation', function() {
it('should play sequence in reverse', (done) => {
let seq = [];
const animation = newAnimation();
- animation.onFrame = () => seq.push(animation._currentFrame);
+ animation.onFrame = () => {
+ seq.push(animation._currentFrame);
+ };
animation.onFinish = () => {
expect(seq).to.be.deep.equal([4, 3, 2, 1, 0]);
expect(animation._currentFrame).to.be.equal(0);
diff --git a/test/login.spec.js b/test/login.spec.js
index acb38db2eb..68db14494b 100644
--- a/test/login.spec.js
+++ b/test/login.spec.js
@@ -1,6 +1,5 @@
// @flow
-import { expect } from 'chai';
import {
setupBackendAndStore,
setupBackendAndMockStore,
@@ -17,19 +16,13 @@ describe('Logging in', () => {
const { store, mockIpc, backend } = setupBackendAndStore();
const chain = new IpcChain(mockIpc);
- chain
- .require('getAccountData')
- .withInputValidation((an) => {
- expect(an).to.equal('123');
- })
- .done();
+ chain.expect('getAccountData').withInputValidation((an) => {
+ expect(an).to.equal('123');
+ });
- chain
- .require('setAccount')
- .withInputValidation((an) => {
- expect(an).to.equal('123');
- })
- .done();
+ chain.expect('setAccount').withInputValidation((an) => {
+ expect(an).to.equal('123');
+ });
chain.onSuccessOrFailure(done);
diff --git a/test/logout.spec.js b/test/logout.spec.js
index c7ed45adb2..65bc3aba09 100644
--- a/test/logout.spec.js
+++ b/test/logout.spec.js
@@ -1,6 +1,5 @@
// @flow
-import { expect } from 'chai';
import {
setupBackendAndStore,
setupBackendAndMockStore,
@@ -16,13 +15,10 @@ describe('logging out', () => {
const { mockIpc, backend } = setupBackendAndStore();
const chain = new IpcChain(mockIpc);
- chain
- .require('setAccount')
- .withInputValidation((num) => {
- expect(num).to.be.null;
- })
- .done();
- chain.require('disconnect').done();
+ chain.expect('setAccount').withInputValidation((num) => {
+ expect(num).to.be.null;
+ });
+ chain.expect('disconnect');
chain.onSuccessOrFailure(done);
backend.logout();
diff --git a/test/mocks/ipc.js b/test/mocks/ipc.js
index cd8dc9fbac..590313ec13 100644
--- a/test/mocks/ipc.js
+++ b/test/mocks/ipc.js
@@ -78,8 +78,8 @@ export function newMockIpc() {
},
sendNewState: (state: BackendState) => {
- for (const l of stateListeners) {
- l(state);
+ for (const listener of stateListeners) {
+ listener(state);
}
},
@@ -94,8 +94,8 @@ export function newMockIpc() {
removeAccountFromHistory: (_accountToken) => Promise.resolve(),
killWebSocket: () => {
- for (const l of connectionCloseListeners) {
- l();
+ for (const listener of connectionCloseListeners) {
+ listener();
}
},
};
diff --git a/test/relay-settings-builder.spec.js b/test/relay-settings-builder.spec.js
index a2d69ceca6..ace01a978c 100644
--- a/test/relay-settings-builder.spec.js
+++ b/test/relay-settings-builder.spec.js
@@ -1,6 +1,5 @@
// @flow
-import { expect } from 'chai';
import RelaySettingsBuilder from '../app/lib/relay-settings-builder';
describe('Relay settings builder', () => {
diff --git a/test/setup/renderer.js b/test/setup/renderer.js
index f27568f58d..acfa87b7ed 100644
--- a/test/setup/renderer.js
+++ b/test/setup/renderer.js
@@ -1,6 +1,13 @@
const Enzyme = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');
+const chai = require('chai');
+const spies = require('chai-spies');
+
+chai.use(spies);
Enzyme.configure({
adapter: new Adapter(),
});
+
+global.expect = chai.expect;
+global.spy = chai.spy;
diff --git a/test/transition-rule.spec.js b/test/transition-rule.spec.js
index 00fffff01e..f36c44182e 100644
--- a/test/transition-rule.spec.js
+++ b/test/transition-rule.spec.js
@@ -1,5 +1,5 @@
// @flow
-import { expect } from 'chai';
+
import TransitionRule from '../app/lib/transition-rule';
describe('TransitionRule', () => {