diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2018-06-19 14:35:18 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-06-20 15:36:17 +0200 |
| commit | 46672191cb3ee17b82f4af412bd00c75e138eaf9 (patch) | |
| tree | a354207aab5af7a270ae2a8e80d5cecccf68d0c2 | |
| parent | 46125ddac41dd0b5915940a5e9cf0e9b547c56d9 (diff) | |
| download | mullvadvpn-46672191cb3ee17b82f4af412bd00c75e138eaf9.tar.xz mullvadvpn-46672191cb3ee17b82f4af412bd00c75e138eaf9.zip | |
Make expect and spy global for all tests
| -rw-r--r-- | .eslintrc | 2 | ||||
| -rw-r--r-- | flow-libs/tests.js.flow | 5 | ||||
| -rw-r--r-- | test/.eslintrc | 9 | ||||
| -rw-r--r-- | test/auth.spec.js | 1 | ||||
| -rw-r--r-- | test/autologin.spec.js | 1 | ||||
| -rw-r--r-- | test/components/Account.spec.js | 3 | ||||
| -rw-r--r-- | test/components/AccountInput.spec.js | 2 | ||||
| -rw-r--r-- | test/components/Connect.spec.js | 3 | ||||
| -rw-r--r-- | test/components/HeaderBar.spec.js | 1 | ||||
| -rw-r--r-- | test/components/Login.spec.js | 1 | ||||
| -rw-r--r-- | test/components/Preferences.spec.js | 3 | ||||
| -rw-r--r-- | test/components/SelectLocation.spec.js | 1 | ||||
| -rw-r--r-- | test/components/Settings.spec.js | 3 | ||||
| -rw-r--r-- | test/components/Support.spec.js | 3 | ||||
| -rw-r--r-- | test/components/Switch.spec.js | 1 | ||||
| -rw-r--r-- | test/connect.spec.js | 1 | ||||
| -rw-r--r-- | test/helpers/IpcChain.js | 1 | ||||
| -rw-r--r-- | test/ipc.spec.js | 6 | ||||
| -rw-r--r-- | test/keyframe-animation.spec.js | 39 | ||||
| -rw-r--r-- | test/login.spec.js | 1 | ||||
| -rw-r--r-- | test/logout.spec.js | 1 | ||||
| -rw-r--r-- | test/relay-settings-builder.spec.js | 1 | ||||
| -rw-r--r-- | test/setup/renderer.js | 3 | ||||
| -rw-r--r-- | test/transition-rule.spec.js | 2 |
24 files changed, 57 insertions, 37 deletions
@@ -36,6 +36,6 @@ "es6": true, "node": true, "browser": true, - "mocha": true + "mocha": false } } diff --git a/flow-libs/tests.js.flow b/flow-libs/tests.js.flow index b1daeefa4c..aecc8239fa 100644 --- a/flow-libs/tests.js.flow +++ b/flow-libs/tests.js.flow @@ -1,3 +1,5 @@ +import chai from 'chai'; + // We use electron-mocha which has a child dependency on mocha. // However flow-typed does not automatically pull annotations for mocha. // These stubs remedy the absence of those. @@ -5,3 +7,6 @@ declare function describe(string, Function): void; declare function it(string, (done: Function) => any): Promise<any> | void; declare function afterEach((done: Function) => void): Promise<any> | void; declare function beforeEach((done: Function) => void): Promise<any> | void; + +declare var expect: $PropertyType<chai, 'expect'>; +declare var spy: any;
\ No newline at end of file diff --git a/test/.eslintrc b/test/.eslintrc new file mode 100644 index 0000000000..8f377410fc --- /dev/null +++ b/test/.eslintrc @@ -0,0 +1,9 @@ +{ + "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 c4330b4559..e6b2c25486 100644 --- a/test/auth.spec.js +++ b/test/auth.spec.js @@ -1,6 +1,5 @@ // @flow -import { expect, spy } from 'chai'; import { setupIpcAndStore, setupBackendAndStore } from './helpers/ipc-helpers'; import { IpcChain } from './helpers/IpcChain'; import { Backend } from '../app/lib/backend'; diff --git a/test/autologin.spec.js b/test/autologin.spec.js index 06a6ec7eb3..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'; 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 04f3cbdd92..90bb70f4b3 100644 --- a/test/components/Login.spec.js +++ b/test/components/Login.spec.js @@ -1,6 +1,5 @@ // @flow -import { expect, spy } from 'chai'; import * as React from 'react'; import { shallow } from 'enzyme'; 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 c06ac0b1d8..ce1efb2b75 100644 --- a/test/components/Support.spec.js +++ b/test/components/Support.spec.js @@ -1,7 +1,6 @@ // @flow -import { expect, spy } from 'chai'; -import React from 'react'; +import * as React from 'react'; import Support from '../../app/components/Support'; import { shallow } from 'enzyme'; import type { SupportProps } from '../../app/components/Support'; 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 efd80d39de..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 { 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 8c99111343..68db14494b 100644 --- a/test/login.spec.js +++ b/test/login.spec.js @@ -1,6 +1,5 @@ // @flow -import { expect } from 'chai'; import { setupBackendAndStore, setupBackendAndMockStore, diff --git a/test/logout.spec.js b/test/logout.spec.js index 4b0edaa0ca..65bc3aba09 100644 --- a/test/logout.spec.js +++ b/test/logout.spec.js @@ -1,6 +1,5 @@ // @flow -import { expect } from 'chai'; import { setupBackendAndStore, setupBackendAndMockStore, 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 42b8d7e163..acfa87b7ed 100644 --- a/test/setup/renderer.js +++ b/test/setup/renderer.js @@ -8,3 +8,6 @@ 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', () => { |
