Skip to content
This repository was archived by the owner on May 17, 2019. It is now read-only.

Commit 696c702

Browse files
authoredMay 4, 2018
Improve Flow coverage (#104)
1 parent dc8854f commit 696c702

13 files changed

+1094
-189
lines changed
 

‎flow-typed/globals.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
// @flow
1+
/** Copyright (c) 2018 Uber Technologies, Inc.
2+
*
3+
* This source code is licensed under the MIT license found in the
4+
* LICENSE file in the root directory of this source tree.
5+
*
6+
* @flow
7+
*/
28

39
declare var __NODE__: boolean;
410
declare var __BROWSER__: boolean;
11+
12+
declare var __REDUX_DEVTOOLS_EXTENSION__: Function;

‎flow-typed/npm/redux_v3.x.x.js

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// flow-typed signature: cca4916b0213065533df8335c3285a4a
2+
// flow-typed version: cab04034e7/redux_v3.x.x/flow_>=v0.55.x
3+
4+
/* eslint-disable */
5+
6+
declare module 'redux' {
7+
/*
8+
9+
S = State
10+
A = Action
11+
D = Dispatch
12+
13+
*/
14+
15+
declare export type DispatchAPI<A> = (action: A) => A;
16+
declare export type Dispatch<A: {type: $Subtype<string>}> = DispatchAPI<A>;
17+
18+
declare export type MiddlewareAPI<S, A, D = Dispatch<A>> = {
19+
dispatch: D,
20+
getState(): S,
21+
};
22+
23+
declare export type Store<S, A, D = Dispatch<A>> = {
24+
// rewrite MiddlewareAPI members in order to get nicer error messages (intersections produce long messages)
25+
dispatch: D,
26+
getState(): S,
27+
subscribe(listener: () => void): () => void,
28+
replaceReducer(nextReducer: Reducer<S, A>): void,
29+
};
30+
31+
declare export type Reducer<S, A> = (state: S | void, action: A) => S;
32+
33+
declare export type CombinedReducer<S, A> = (
34+
state: ($Shape<S> & {}) | void,
35+
action: A
36+
) => S;
37+
38+
declare export type Middleware<S, A, D = Dispatch<A>> = (
39+
api: MiddlewareAPI<S, A, D>
40+
) => (next: D) => D;
41+
42+
declare export type StoreCreator<S, A, D = Dispatch<A>> = {
43+
(reducer: Reducer<S, A>, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>,
44+
(
45+
reducer: Reducer<S, A>,
46+
preloadedState: S,
47+
enhancer?: StoreEnhancer<S, A, D>
48+
): Store<S, A, D>,
49+
};
50+
51+
declare export type StoreEnhancer<S, A, D = Dispatch<A>> = (
52+
next: StoreCreator<S, A, D>
53+
) => StoreCreator<S, A, D>;
54+
55+
declare export function createStore<S, A, D>(
56+
reducer: Reducer<S, A>,
57+
enhancer?: StoreEnhancer<S, A, D>
58+
): Store<S, A, D>;
59+
declare export function createStore<S, A, D>(
60+
reducer: Reducer<S, A>,
61+
preloadedState?: S,
62+
enhancer?: StoreEnhancer<S, A, D>
63+
): Store<S, A, D>;
64+
65+
declare export function applyMiddleware<S, A, D>(
66+
...middlewares: Array<Middleware<S, A, D>>
67+
): StoreEnhancer<S, A, D>;
68+
69+
declare export type ActionCreator<A, B> = (...args: Array<B>) => A;
70+
declare export type ActionCreators<K, A> = {[key: K]: ActionCreator<A, any>};
71+
72+
declare export function bindActionCreators<
73+
A,
74+
C: ActionCreator<A, any>,
75+
D: DispatchAPI<A>
76+
>(
77+
actionCreator: C,
78+
dispatch: D
79+
): C;
80+
declare export function bindActionCreators<
81+
A,
82+
K,
83+
C: ActionCreators<K, A>,
84+
D: DispatchAPI<A>
85+
>(
86+
actionCreators: C,
87+
dispatch: D
88+
): C;
89+
90+
declare export function combineReducers<O: Object, A>(
91+
reducers: O
92+
): CombinedReducer<$ObjMap<O, <S>(r: Reducer<S, any>) => S>, A>;
93+
94+
declare export var compose: $Compose;
95+
}

‎flow-typed/tape-cup_v4.x.x.js

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/* eslint-disable */
2+
3+
declare type tape$TestOpts = {
4+
skip: boolean,
5+
timeout?: number,
6+
} | {
7+
skip?: boolean,
8+
timeout: number,
9+
};
10+
11+
declare type tape$TestCb = (t: tape$Context) => mixed;
12+
declare type tape$TestFn = (a: string | tape$TestOpts | tape$TestCb, b?: tape$TestOpts | tape$TestCb, c?: tape$TestCb) => void;
13+
14+
declare interface tape$Context {
15+
fail(msg?: string): void,
16+
pass(msg?: string): void,
17+
18+
error(err: mixed, msg?: string): void,
19+
ifError(err: mixed, msg?: string): void,
20+
ifErr(err: mixed, msg?: string): void,
21+
iferror(err: mixed, msg?: string): void,
22+
23+
ok(value: mixed, msg?: string): void,
24+
true(value: mixed, msg?: string): void,
25+
assert(value: mixed, msg?: string): void,
26+
27+
notOk(value: mixed, msg?: string): void,
28+
false(value: mixed, msg?: string): void,
29+
notok(value: mixed, msg?: string): void,
30+
31+
// equal + aliases
32+
equal(actual: mixed, expected: mixed, msg?: string): void,
33+
equals(actual: mixed, expected: mixed, msg?: string): void,
34+
isEqual(actual: mixed, expected: mixed, msg?: string): void,
35+
is(actual: mixed, expected: mixed, msg?: string): void,
36+
strictEqual(actual: mixed, expected: mixed, msg?: string): void,
37+
strictEquals(actual: mixed, expected: mixed, msg?: string): void,
38+
39+
// notEqual + aliases
40+
notEqual(actual: mixed, expected: mixed, msg?: string): void,
41+
notEquals(actual: mixed, expected: mixed, msg?: string): void,
42+
notStrictEqual(actual: mixed, expected: mixed, msg?: string): void,
43+
notStrictEquals(actual: mixed, expected: mixed, msg?: string): void,
44+
isNotEqual(actual: mixed, expected: mixed, msg?: string): void,
45+
isNot(actual: mixed, expected: mixed, msg?: string): void,
46+
not(actual: mixed, expected: mixed, msg?: string): void,
47+
doesNotEqual(actual: mixed, expected: mixed, msg?: string): void,
48+
isInequal(actual: mixed, expected: mixed, msg?: string): void,
49+
50+
// deepEqual + aliases
51+
deepEqual(actual: mixed, expected: mixed, msg?: string): void,
52+
deepEquals(actual: mixed, expected: mixed, msg?: string): void,
53+
isEquivalent(actual: mixed, expected: mixed, msg?: string): void,
54+
same(actual: mixed, expected: mixed, msg?: string): void,
55+
56+
// notDeepEqual
57+
notDeepEqual(actual: mixed, expected: mixed, msg?: string): void,
58+
notEquivalent(actual: mixed, expected: mixed, msg?: string): void,
59+
notDeeply(actual: mixed, expected: mixed, msg?: string): void,
60+
notSame(actual: mixed, expected: mixed, msg?: string): void,
61+
isNotDeepEqual(actual: mixed, expected: mixed, msg?: string): void,
62+
isNotDeeply(actual: mixed, expected: mixed, msg?: string): void,
63+
isNotEquivalent(actual: mixed, expected: mixed, msg?: string): void,
64+
isInequivalent(actual: mixed, expected: mixed, msg?: string): void,
65+
66+
// deepLooseEqual
67+
deepLooseEqual(actual: mixed, expected: mixed, msg?: string): void,
68+
looseEqual(actual: mixed, expected: mixed, msg?: string): void,
69+
looseEquals(actual: mixed, expected: mixed, msg?: string): void,
70+
71+
// notDeepLooseEqual
72+
notDeepLooseEqual(actual: mixed, expected: mixed, msg?: string): void,
73+
notLooseEqual(actual: mixed, expected: mixed, msg?: string): void,
74+
notLooseEquals(actual: mixed, expected: mixed, msg?: string): void,
75+
76+
throws(fn: Function, expected?: RegExp | Function, msg?: string): void,
77+
doesNotThrow(fn: Function, expected?: RegExp | Function, msg?: string): void,
78+
79+
timeoutAfter(ms: number): void,
80+
81+
skip(msg?: string): void,
82+
plan(n: number): void,
83+
onFinish(fn: Function): void,
84+
end(): void,
85+
comment(msg: string): void,
86+
test: tape$TestFn,
87+
}
88+
89+
declare module 'tape-cup' {
90+
declare type TestHarness = Tape;
91+
declare type StreamOpts = {
92+
objectMode?: boolean,
93+
};
94+
95+
declare type Tape = {
96+
(a: string | tape$TestOpts | tape$TestCb, b?: tape$TestCb | tape$TestOpts, c?: tape$TestCb, ...rest: Array<void>): void,
97+
test: tape$TestFn,
98+
skip: (name: string, cb?: tape$TestCb) => void,
99+
createHarness: () => TestHarness,
100+
createStream: (opts?: StreamOpts) => stream$Readable,
101+
only: (a: string | tape$TestOpts | tape$TestCb, b?: tape$TestCb | tape$TestOpts, c?: tape$TestCb, ...rest: Array<void>) => void,
102+
};
103+
104+
declare module.exports: Tape;
105+
}

‎package.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@
2424
"devDependencies": {
2525
"@babel/preset-react": "7.0.0-beta.40",
2626
"@types/redux": "3.6.31",
27-
"babel-eslint": "8.2.2",
27+
"babel-eslint": "^8.2.3",
2828
"create-universal-package": "3.4.1",
2929
"enzyme": "3.3.0",
3030
"enzyme-adapter-react-16": "1.1.1",
31-
"eslint": "4.18.1",
32-
"eslint-config-fusion": "^1.0.0",
31+
"eslint": "^4.19.1",
32+
"eslint-config-fusion": "^1.0.1",
3333
"eslint-plugin-cup": "1.0.0",
34-
"eslint-plugin-flowtype": "2.46.1",
35-
"eslint-plugin-import": "^2.8.0",
34+
"eslint-plugin-flowtype": "^2.46.3",
35+
"eslint-plugin-import": "^2.11.0",
3636
"eslint-plugin-prettier": "2.6.0",
3737
"eslint-plugin-react": "7.7.0",
38-
"flow-bin": "0.66.0",
39-
"fusion-core": "^1.0.0",
40-
"fusion-tokens": "^1.0.1",
41-
"nyc": "11.4.1",
42-
"prettier": "1.11.1",
43-
"react": "16.2.0",
44-
"react-dom": "16.2.0",
38+
"flow-bin": "^0.71.0",
39+
"fusion-core": "^1.2.6",
40+
"fusion-tokens": "^1.0.3",
41+
"nyc": "^11.7.1",
42+
"prettier": "^1.12.1",
43+
"react": "^16.3.2",
44+
"react-dom": "^16.3.2",
4545
"react-redux": "5.0.7",
46-
"redux": "3.7.2",
46+
"redux": "^4.0.0",
4747
"tape-cup": "4.7.1",
4848
"unitest": "2.1.1"
4949
},

‎src/__tests__/index.browser.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
*
33
* This source code is licensed under the MIT license found in the
44
* LICENSE file in the root directory of this source tree.
5+
*
6+
* @flow
57
*/
68

79
/* eslint-env browser */
@@ -10,6 +12,9 @@ import Enzyme, {mount} from 'enzyme';
1012
import {connect} from 'react-redux';
1113
import Adapter from 'enzyme-adapter-react-16';
1214
import React from 'react';
15+
16+
import type {Context} from 'fusion-core';
17+
1318
import GetReduxPlugin from '../browser.js';
1419

1520
Enzyme.configure({adapter: new Adapter()});
@@ -22,7 +27,8 @@ tape('browser with no preloadedState and no __REDUX_STATE__ element', t => {
2227
test: action.payload || 1,
2328
};
2429
};
25-
const {store} = Redux.provides({reducer}).from();
30+
const provider = Redux.provides({reducer});
31+
const {store} = provider && provider.from();
2632
t.deepLooseEqual(store.getState(), {test: 1});
2733
store.dispatch({type: 'CHANGE', payload: 2});
2834
t.equals(store.getState().test, 2, 'state receives dispatch');
@@ -53,7 +59,7 @@ tape('browser with no preloadedState and a __REDUX_STATE__ element', t => {
5359
reduxState.setAttribute('type', 'application/json');
5460
reduxState.setAttribute('id', '__REDUX_STATE__');
5561
reduxState.textContent = JSON.stringify({hello: 'world'});
56-
document.body.appendChild(reduxState);
62+
document.body && document.body.appendChild(reduxState);
5763
const reducer = (state, action) => {
5864
return {
5965
...state,
@@ -64,7 +70,7 @@ tape('browser with no preloadedState and a __REDUX_STATE__ element', t => {
6470
t.deepLooseEqual(store.getState(), {test: 1, hello: 'world'});
6571
store.dispatch({type: 'CHANGE', payload: 2});
6672
t.deepLooseEqual(store.getState(), {test: 2, hello: 'world'});
67-
document.body.removeChild(reduxState);
73+
document.body && document.body.removeChild(reduxState);
6874
t.end();
6975
});
7076

@@ -77,7 +83,7 @@ tape('browser with preloadedState and a __REDUX_STATE__ element', t => {
7783
hello: 'unused',
7884
unused: 'not used',
7985
});
80-
document.body.appendChild(reduxState);
86+
document.body && document.body.appendChild(reduxState);
8187
const reducer = (state, action) => {
8288
return {
8389
...state,
@@ -91,7 +97,7 @@ tape('browser with preloadedState and a __REDUX_STATE__ element', t => {
9197
t.deepLooseEqual(store.getState(), {test: 1, hello: 'world'});
9298
store.dispatch({type: 'CHANGE', payload: 2});
9399
t.deepLooseEqual(store.getState(), {test: 2, hello: 'world'});
94-
document.body.removeChild(reduxState);
100+
document.body && document.body.removeChild(reduxState);
95101
t.end();
96102
});
97103

@@ -111,11 +117,17 @@ tape('browser with enhancer', t => {
111117
return (...args) => {
112118
t.equal(args[0], reducer);
113119
const store = createStore(...args);
120+
// $FlowFixMe
114121
t.equal(store.ctx, mockCtx, '[Enhancer] ctx provided by ctxEnhancer');
115122
return store;
116123
};
117124
};
118-
const {store} = Redux.provides({reducer, enhancer}).from(mockCtx);
125+
const {store} = Redux.provides({reducer, enhancer}).from(
126+
((mockCtx: any): Context)
127+
);
128+
if (!store.ctx) {
129+
return;
130+
}
119131
t.equal(store.ctx, mockCtx, '[Final store] ctx provided by ctxEnhancer');
120132
t.deepLooseEqual(store.getState(), {test: 1});
121133
store.dispatch({type: 'CHANGE', payload: 2});
@@ -201,7 +213,8 @@ tape('browser middleware', async t => {
201213
const ctx = {element};
202214
const Plugin = Redux.provides({reducer});
203215
try {
204-
await Redux.middleware(null, Plugin)(ctx, () => Promise.resolve());
216+
await (Redux.middleware &&
217+
Redux.middleware(null, Plugin)((ctx: any), () => Promise.resolve()));
205218
} catch (e) {
206219
t.ifError(e);
207220
}

0 commit comments

Comments
 (0)
This repository has been archived.