Skip to content

Commit

Permalink
test: add flow-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
stepankuzmin committed Oct 19, 2017
1 parent aa4509e commit 348cbcb
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 18 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ jobs:
- run: yarn lint
- run: yarn typecheck
- run: yarn test
- run: yarn coverage
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# testing
/coverage
/flow-coverage

# misc
.env
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"lint": "eslint src test",
"typecheck": "flow check src",
"test": "jest",
"coverage": "flow-coverage-report -i 'src/**/*.js' -t html",
"build": "webpack -p --config webpack.config.js",
"docs": "documentation build src/index.js -g --markdown-toc false -f md -o docs/props.md",
"styleguide": "styleguidist server",
Expand Down Expand Up @@ -59,6 +60,7 @@
"eslint-plugin-jsx-a11y": "6.0.2",
"eslint-plugin-react": "7.4.0",
"flow-bin": "0.57.3",
"flow-coverage-report": "0.3.0",
"gh-pages": "1.0.0",
"immutable": "4.0.0-rc.8",
"jest": "21.2.1",
Expand Down
15 changes: 7 additions & 8 deletions src/components/MapGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class MapGL extends PureComponent<Props, State> {
}

const mapStyle = isImmutable(this.props.mapStyle)
? ((this.props.mapStyle: any): MapStyle).toJS()
? (this.props.mapStyle: MapStyle).toJS()
: this.props.mapStyle;

const map = new mapboxgl.Map({
Expand All @@ -120,7 +120,6 @@ class MapGL extends PureComponent<Props, State> {
}

this._map = map;
window.map = map;
this._updateMapViewport(this.props);
}

Expand All @@ -146,8 +145,8 @@ class MapGL extends PureComponent<Props, State> {
const newMapStyle = newProps.mapStyle;
const prevMapStyle = prevProps.mapStyle;

if (isImmutable(newMapStyle) && !((newMapStyle: any): MapStyle).equals(prevMapStyle)) {
this._map.setStyle(((newMapStyle: any): MapStyle).toJS());
if (isImmutable(newMapStyle) && !(newMapStyle: MapStyle).equals(prevMapStyle)) {
this._map.setStyle((newMapStyle: MapStyle).toJS());
} else if (newMapStyle !== prevMapStyle) {
this._map.setStyle(newMapStyle);
}
Expand All @@ -160,8 +159,8 @@ class MapGL extends PureComponent<Props, State> {
* @param {Props} newProps
*/
_updateMapViewport(newProps: Props): void {
const map = this._map;
const center = map.getCenter();
const map: mapboxgl.Map = this._map;
const center: mapboxgl.LngLat = map.getCenter();

const viewportChanged =
newProps.latitude !== center.lat ||
Expand All @@ -187,13 +186,13 @@ class MapGL extends PureComponent<Props, State> {
* @param {(mapboxgl.MapMouseEvent | mapboxgl.MapTouchEvent)} event
*/
_onViewportChange(event: mapboxgl.MapMouseEvent | mapboxgl.MapTouchEvent): void {
const map = event.target;
const map: mapboxgl.Map = event.target;
const { lng, lat } = map.getCenter();
const zoom = map.getZoom();
const pitch = map.getPitch();
const bearing = map.getBearing();

const viewport = {
const viewport: Viewport = {
latitude: lat,
longitude: lng,
zoom,
Expand Down
2 changes: 1 addition & 1 deletion src/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Map } from 'immutable';
const empty = new Map();
const diff = (newMap: Map<*, *> = empty, prevMap: Map<*, *> = empty) => {
const keys = new Set([...newMap.keys(), ...prevMap.keys()]);
return Array.from(keys).reduce((acc, key) => {
return Array.from(keys).reduce((acc, key: string) => {
const value = newMap.get(key);
if (prevMap.get(key) !== value) {
acc.push([key, value]);
Expand Down
8 changes: 7 additions & 1 deletion test/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import MapGL from '../src';

Enzyme.configure({ adapter: new Adapter() });

const mockOn = jest.fn();
const mockOn = jest.fn((_, fn) => fn());
const mockOnce = jest.fn((_, fn) => fn());
const mockFlyTo = jest.fn();
const mockGetCanvas = jest.fn();
Expand Down Expand Up @@ -39,3 +39,9 @@ test('MapGL#onLoad', () => {
mount(<MapGL latitude={0} longitude={0} zoom={0} onLoad={onLoad} />);
expect(onLoad).toHaveBeenCalled();
});

// test('MapGL#onViewportChange', () => {
// const onViewportChange = jest.fn();
// mount(<MapGL latitude={0} longitude={0} zoom={0} onViewportChange={onViewportChange} />);
// expect(onViewportChange).toHaveBeenCalled();
// });
130 changes: 122 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ array-unique@^0.3.2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428"

array.prototype.find@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/array.prototype.find/-/array.prototype.find-2.0.0.tgz#56a9ab1edde2a7701ed6d9166acec338919d8430"
dependencies:
define-properties "^1.1.2"
es-abstract "^1.5.0"

arrify@^1.0.0, arrify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d"
Expand Down Expand Up @@ -1170,6 +1177,13 @@ babel-register@^6.26.0:
mkdirp "^0.5.1"
source-map-support "^0.4.15"

babel-runtime@6.11.6:
version "6.11.6"
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.11.6.tgz#6db707fef2d49c49bfa3cb64efdb436b518b8222"
dependencies:
core-js "^2.4.0"
regenerator-runtime "^0.9.5"

babel-runtime@^6.18.0, babel-runtime@^6.2.0, babel-runtime@^6.22.0, babel-runtime@^6.26.0, babel-runtime@^6.9.2:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe"
Expand Down Expand Up @@ -1948,14 +1962,14 @@ colors@0.5.x:
version "0.5.1"
resolved "https://registry.yarnpkg.com/colors/-/colors-0.5.1.tgz#7d0023eaeb154e8ee9fce75dcb923d0ed1667774"

colors@^1.0.3, colors@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.1.2.tgz#168a4701756b6a7f51a12ce0c97bfa28c084ed63"

colors@~0.6.0-1:
version "0.6.2"
resolved "https://registry.yarnpkg.com/colors/-/colors-0.6.2.tgz#2423fe6678ac0c5dae8852e5d0e5be08c997abcc"

colors@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.1.2.tgz#168a4701756b6a7f51a12ce0c97bfa28c084ed63"

combined-stream@^1.0.5, combined-stream@~1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.5.tgz#938370a57b4a51dea2c77c15d5c5fdf895164009"
Expand Down Expand Up @@ -2890,6 +2904,10 @@ earcut@^2.0.3:
version "2.1.1"
resolved "https://registry.yarnpkg.com/earcut/-/earcut-2.1.1.tgz#157634e5f3ebb42224e475016e86a5b6ce556b45"

eastasianwidth@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/eastasianwidth/-/eastasianwidth-0.1.1.tgz#44d656de9da415694467335365fb3147b8572b7c"

ecc-jsbn@~0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz#0fc73a9ed5f0d53c38193398523ef7e543777505"
Expand Down Expand Up @@ -3010,7 +3028,7 @@ error@^7.0.0:
string-template "~0.2.1"
xtend "~4.0.0"

es-abstract@^1.6.1, es-abstract@^1.7.0:
es-abstract@^1.5.0, es-abstract@^1.6.1, es-abstract@^1.7.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.9.0.tgz#690829a07cae36b222e7fd9b75c0d0573eb25227"
dependencies:
Expand Down Expand Up @@ -3546,7 +3564,7 @@ fb-watchman@^2.0.0:
dependencies:
bser "^2.0.0"

fbjs@^0.8.16:
fbjs@^0.8.16, fbjs@^0.8.4:
version "0.8.16"
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.16.tgz#5e67432f550dc41b572bf55847b8aca64e5337db"
dependencies:
Expand Down Expand Up @@ -3693,6 +3711,23 @@ flow-bin@0.57.3:
version "0.57.3"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.57.3.tgz#843fb80a821b6d0c5847f7bb3f42365ffe53b27b"

flow-coverage-report@0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/flow-coverage-report/-/flow-coverage-report-0.3.0.tgz#a22d52fc9fa9c24ae0be02712a6fe1ac156f0d93"
dependencies:
array.prototype.find "2.0.0"
babel-runtime "6.11.6"
glob "7.0.5"
minimatch "3.0.3"
mkdirp "0.5.1"
parse-json "2.2.0"
react "15.3.1"
react-dom "15.3.1"
strip-json-comments "2.0.1"
temp "0.8.3"
terminal-table "0.0.12"
yargs "5.0.0"

flow-remove-types@^1.1.2:
version "1.2.1"
resolved "https://registry.yarnpkg.com/flow-remove-types/-/flow-remove-types-1.2.1.tgz#58e261bf8b842bd234c86cafb982a1213aff0edb"
Expand Down Expand Up @@ -4018,6 +4053,17 @@ glob-stream@^5.3.2:
to-absolute-glob "^0.1.1"
unique-stream "^2.0.2"

glob@7.0.5:
version "7.0.5"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.0.5.tgz#b4202a69099bbb4d292a7c1b95b6682b67ebdc95"
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^3.0.2"
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8"
Expand Down Expand Up @@ -5591,6 +5637,10 @@ lodash._reinterpolate@~3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"

lodash.assign@^4.1.0, lodash.assign@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.assign/-/lodash.assign-4.2.0.tgz#0d99f3ccd7a6d261d19bdaeb9245005d285808e7"

lodash.camelcase@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6"
Expand Down Expand Up @@ -6035,7 +6085,7 @@ mixin-deep@^1.2.0:
for-in "^1.0.2"
is-extendable "^0.1.1"

mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
mkdirp@0.5.1, mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
dependencies:
Expand Down Expand Up @@ -6598,7 +6648,7 @@ parse-glob@^3.0.4:
is-extglob "^1.0.0"
is-glob "^2.0.0"

parse-json@^2.2.0:
parse-json@2.2.0, parse-json@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-2.2.0.tgz#f480f40434ef80741f8469099f8dea18f55a4dc9"
dependencies:
Expand Down Expand Up @@ -7304,6 +7354,10 @@ react-docgen@^3.0.0-beta8:
node-dir "^0.1.10"
recast "^0.12.6"

react-dom@15.3.1:
version "15.3.1"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.3.1.tgz#6d42cd2b64c8c5e0b693f3ffaec301e6e627e24e"

react-dom@16.0.0:
version "16.0.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.0.0.tgz#9cc3079c3dcd70d4c6e01b84aab2a7e34c303f58"
Expand Down Expand Up @@ -7396,6 +7450,14 @@ react-test-renderer@16.0.0, react-test-renderer@^16.0.0-0:
fbjs "^0.8.16"
object-assign "^4.1.1"

react@15.3.1:
version "15.3.1"
resolved "https://registry.yarnpkg.com/react/-/react-15.3.1.tgz#f78501ed8c2ec6e6e31c3223652e97f1369d2bd6"
dependencies:
fbjs "^0.8.4"
loose-envify "^1.1.0"
object-assign "^4.1.0"

react@16.0.0:
version "16.0.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.0.0.tgz#ce7df8f1941b036f02b2cca9dbd0cb1f0e855e2d"
Expand Down Expand Up @@ -7548,6 +7610,10 @@ regenerator-runtime@^0.11.0:
version "0.11.0"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz#7e54fe5b5ccd5d6624ea6255c3473be090b802e1"

regenerator-runtime@^0.9.5:
version "0.9.6"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.9.6.tgz#d33eb95d0d2001a4be39659707c51b0cb71ce029"

regenerator-transform@^0.10.0:
version "0.10.1"
resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.10.1.tgz#1e4996837231da8b7f3cf4114d71b5691a0680dd"
Expand Down Expand Up @@ -7856,6 +7922,10 @@ rimraf@2, rimraf@^2.2.8, rimraf@^2.5.1, rimraf@^2.5.4, rimraf@^2.6.1:
dependencies:
glob "^7.0.5"

rimraf@~2.2.6:
version "2.2.8"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.2.8.tgz#e439be2aaee327321952730f99a8929e4fc50582"

ripemd160@^2.0.0, ripemd160@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/ripemd160/-/ripemd160-2.0.1.tgz#0f4584295c53a3628af7e6d79aca21ce57d1c6e7"
Expand Down Expand Up @@ -8615,6 +8685,20 @@ tar@^2.2.1:
fstream "^1.0.2"
inherits "2"

temp@0.8.3:
version "0.8.3"
resolved "https://registry.yarnpkg.com/temp/-/temp-0.8.3.tgz#e0c6bc4d26b903124410e4fed81103014dfc1f59"
dependencies:
os-tmpdir "^1.0.0"
rimraf "~2.2.6"

terminal-table@0.0.12:
version "0.0.12"
resolved "https://registry.yarnpkg.com/terminal-table/-/terminal-table-0.0.12.tgz#7b56d009aa6828dfdd10f11b654e79c062965fa2"
dependencies:
colors "^1.0.3"
eastasianwidth "^0.1.0"

test-exclude@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-4.1.1.tgz#4d84964b0966b0087ecc334a2ce002d3d9341e26"
Expand Down Expand Up @@ -9427,6 +9511,10 @@ window-size@0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.0.tgz#5438cd2ea93b202efa3a19fe8887aee7c94f9c9d"

window-size@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.2.0.tgz#b4315bb4214a3d7058ebeee892e13fa24d98b075"

word-wrap@^1.0.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"
Expand Down Expand Up @@ -9509,6 +9597,13 @@ yallist@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52"

yargs-parser@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-3.2.0.tgz#5081355d19d9d0c8c5d81ada908cb4e6d186664f"
dependencies:
camelcase "^3.0.0"
lodash.assign "^4.1.0"

yargs-parser@^4.2.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-4.2.1.tgz#29cceac0dc4f03c6c87b4a9f217dd18c9f74871c"
Expand All @@ -9521,6 +9616,25 @@ yargs-parser@^7.0.0:
dependencies:
camelcase "^4.1.0"

yargs@5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-5.0.0.tgz#3355144977d05757dbb86d6e38ec056123b3a66e"
dependencies:
cliui "^3.2.0"
decamelize "^1.1.1"
get-caller-file "^1.0.1"
lodash.assign "^4.2.0"
os-locale "^1.4.0"
read-pkg-up "^1.0.1"
require-directory "^2.1.1"
require-main-filename "^1.0.1"
set-blocking "^2.0.0"
string-width "^1.0.2"
which-module "^1.0.0"
window-size "^0.2.0"
y18n "^3.2.1"
yargs-parser "^3.2.0"

yargs@^6.6.0:
version "6.6.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-6.6.0.tgz#782ec21ef403345f830a808ca3d513af56065208"
Expand Down

0 comments on commit 348cbcb

Please sign in to comment.