diff --git a/.eslintignore b/.eslintignore
new file mode 100644
index 000000000..34541f1a9
--- /dev/null
+++ b/.eslintignore
@@ -0,0 +1,2 @@
+index.d.ts
+scripts/
diff --git a/.eslintrc.js b/.eslintrc.js
index fa98db4d1..102366cf9 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -1,30 +1,27 @@
module.exports = {
- parser: "babel-eslint",
- plugins: ["react", "react-native", "prettier", "fp", "flowtype", "import"],
+ parser: 'babel-eslint',
+ plugins: ['react', 'react-native', 'prettier', 'fp', 'flowtype', 'import'],
env: {
- jest: true
+ jest: true,
},
settings: {
react: {
- version: require("./package.json").dependencies.react
+ version: require('./package.json').dependencies.react,
+ pragma: 'React',
+ flowVersion: '0.87',
},
- "import/resolver": {
+ 'import/resolver': {
node: {
- extensions: [".js", ".jsx"]
- }
- },
- "import/ignore": ["react-native"],
- react: {
- pragma: "React",
- version: "16.11.0",
- flowVersion: "0.87"
+ extensions: ['.js', '.jsx'],
+ },
},
+ 'import/ignore': ['react-native'],
parserOptions: {
ecmaFeatures: {
jsx: true,
- modules: true
- }
- }
+ modules: true,
+ },
+ },
},
globals: {
fetch: true,
@@ -36,58 +33,58 @@ module.exports = {
window: true,
document: true,
navigator: true,
- XMLSerializer: true
+ XMLSerializer: true,
},
extends: [
- "eslint:recommended",
- "plugin:react/recommended",
- "prettier",
- "plugin:flowtype/recommended",
- "@react-native-community",
+ 'eslint:recommended',
+ 'plugin:react/recommended',
+ 'prettier',
+ 'plugin:flowtype/recommended',
+ '@react-native-community',
],
rules: {
- "react/no-deprecated": "warn",
- "react/no-string-refs": "warn",
- "import/named": [2],
- "import/no-named-default": [0],
- "import/order": [
- "error",
+ 'react/no-deprecated': 'warn',
+ 'react/no-string-refs': 'warn',
+ 'import/named': [2],
+ 'import/no-named-default': [0],
+ 'import/order': [
+ 'error',
{
- groups: ["builtin", "external", "parent", "sibling", "index"],
- "newlines-between": "always"
- }
+ groups: ['builtin', 'external', 'parent', 'sibling', 'index'],
+ 'newlines-between': 'always',
+ },
],
- "import/exports-last": [0],
- "import/no-useless-path-segments": [2],
+ 'import/exports-last': [0],
+ 'import/no-useless-path-segments': [2],
camelcase: [0],
- "no-console": [0],
- "import/prefer-default-export": "off",
- "jsx-a11y/href-no-hash": "off",
- "react/prop-types": [2],
- quotes: [2, "single"],
- "eol-last": [0],
- "no-continue": [1],
- "class-methods-use-this": [0],
- "no-bitwise": [1],
- "prefer-destructuring": [1],
- "consistent-return": [1],
- "no-warning-comments": [1],
- "no-mixed-requires": [0],
- "no-return-assign": 0,
- "no-underscore-dangle": [0],
- "no-await-in-loop": 0,
- "no-restricted-syntax": 0,
- "no-use-before-define": ["error", { functions: false }],
- "no-unused-expressions": ["error", { allowTaggedTemplates: true }],
- "no-plusplus": ["error", { allowForLoopAfterthoughts: true }],
- "prettier/prettier": [
- "error",
+ 'no-console': [0],
+ 'import/prefer-default-export': 'off',
+ 'jsx-a11y/href-no-hash': 'off',
+ 'react/prop-types': [2],
+ quotes: [2, 'single'],
+ 'eol-last': [0],
+ 'no-continue': [1],
+ 'class-methods-use-this': [0],
+ 'no-bitwise': [1],
+ 'prefer-destructuring': [1],
+ 'consistent-return': [1],
+ 'no-warning-comments': [1],
+ 'no-mixed-requires': [0],
+ 'no-return-assign': 0,
+ 'no-underscore-dangle': [0],
+ 'no-await-in-loop': 0,
+ 'no-restricted-syntax': 0,
+ 'no-use-before-define': ['error', {functions: false}],
+ 'no-unused-expressions': ['error', {allowTaggedTemplates: true}],
+ 'no-plusplus': ['error', {allowForLoopAfterthoughts: true}],
+ 'prettier/prettier': [
+ 'error',
{
singleQuote: true,
- trailingComma: "all",
- bracketSpacing: false
- }
+ trailingComma: 'all',
+ bracketSpacing: false,
+ },
],
- "fp/no-mutating-methods": "warn",
- }
+ 'fp/no-mutating-methods': 'warn',
+ },
};
diff --git a/.travis.yml b/.travis.yml
index 8e7065bf8..0683e9203 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -47,7 +47,7 @@ install:
- echo $MAPBOX_ACCESS_TOKEN > ./accesstoken
- find node_modules -name ".git" -exec rm -r "{}" \; || true
- rm -rf example/node_modules/\@react-native-mapbox-gl/
-- yarn install
+- yarn install --ignore-engines
- echo $TRAVIS_OS_NAME
- |
if [ "$TRAVIS_OS_NAME" == "osx" ]; then
@@ -71,7 +71,7 @@ script:
fi
- cd $TRAVIS_BUILD_DIR
- yarn global add -g 'jest@24.8.0'
-- yarn install
+- yarn install --ignore-engines
- yarn run unittest
- yarn run generate
deploy:
diff --git a/__tests__/__mocks__/react-native.mock.js b/__tests__/__mocks__/react-native.mock.js
index 9a822ecd3..8a2bd3146 100644
--- a/__tests__/__mocks__/react-native.mock.js
+++ b/__tests__/__mocks__/react-native.mock.js
@@ -4,7 +4,7 @@ jest.mock('react-native/Libraries/Image/resolveAssetSource', () => {
jest.mock('NativeEventEmitter', () => {
function MockEventEmitter() {}
- MockEventEmitter.prototype.addListener = function () {};
- MockEventEmitter.prototype.removeListener = function () {};
+ MockEventEmitter.prototype.addListener = jest.fn(() => ({remove: jest.fn()}));
+ MockEventEmitter.prototype.removeListener = jest.fn();
return MockEventEmitter;
});
diff --git a/__tests__/components/Callout.test.js b/__tests__/components/Callout.test.js
index 2db40843c..8d112bf0d 100644
--- a/__tests__/components/Callout.test.js
+++ b/__tests__/components/Callout.test.js
@@ -14,12 +14,12 @@ describe('Callout', () => {
describe('_renderDefaultCallout', () => {
test('renders default children', () => {
- const {getByType, getAllByType} = render();
- const callout = getByType('RCTMGLCallout');
+ const {UNSAFE_getByType, UNSAFE_getAllByType} = render();
+ const callout = UNSAFE_getByType('RCTMGLCallout');
expect(callout).toBeDefined();
- expect(getAllByType(Text).length).toBe(1);
- expect(getAllByType(View).length).toBe(3);
+ expect(UNSAFE_getAllByType(Text).length).toBe(1);
+ expect(UNSAFE_getAllByType(View).length).toBe(3);
});
test('renders with custom styles', () => {
@@ -30,11 +30,13 @@ describe('Callout', () => {
tipStyle: {height: 4},
textStyle: {height: 5},
};
- const {getByType, getAllByType} = render();
+ const {UNSAFE_getByType, UNSAFE_getAllByType} = render(
+ ,
+ );
- const callout = getByType('RCTMGLCallout');
- const views = getAllByType(View);
- const text = getByType(Text);
+ const callout = UNSAFE_getByType('RCTMGLCallout');
+ const views = UNSAFE_getAllByType(View);
+ const text = UNSAFE_getByType(Text);
const calloutWrapperTestStyle = callout.props.style[1].height;
const animatedViewTestStyle = views[0].props.style.height;
@@ -54,13 +56,13 @@ describe('Callout', () => {
describe('_renderCustomCallout', () => {
test('renders custom children', () => {
- const {getByTestId, queryByType} = render(
+ const {getByTestId, UNSAFE_queryByType} = render(
{'Foo Bar'}
,
);
- expect(queryByType(Text)).toBeNull();
+ expect(UNSAFE_queryByType(Text)).toBeNull();
expect(getByTestId('TestChild')).toBeDefined();
});
@@ -69,13 +71,13 @@ describe('Callout', () => {
style: {width: 1},
containerStyle: {width: 2},
};
- const {getByType, getAllByType} = render(
+ const {UNSAFE_getByType, UNSAFE_getAllByType} = render(
{'Foo Bar'}
,
);
- const callout = getByType('RCTMGLCallout');
- const views = getAllByType(View);
+ const callout = UNSAFE_getByType('RCTMGLCallout');
+ const views = UNSAFE_getAllByType(View);
const calloutWrapperTestStyle = callout.props.style[1].width;
const animatedViewTestStyle = views[0].props.style.width;
diff --git a/__tests__/components/Camera.test.js b/__tests__/components/Camera.test.js
index fc3fea875..dd8c70cfe 100644
--- a/__tests__/components/Camera.test.js
+++ b/__tests__/components/Camera.test.js
@@ -58,6 +58,7 @@ describe('Camera', () => {
const {getByTestId} = render();
expect(getByTestId('Camera').props).toStrictEqual({
+ children: undefined,
testID: 'Camera',
followUserLocation: undefined,
followUserMode: undefined,
diff --git a/__tests__/components/HeatmapLayer.test.js b/__tests__/components/HeatmapLayer.test.js
index 00ca1aaab..82122e3aa 100644
--- a/__tests__/components/HeatmapLayer.test.js
+++ b/__tests__/components/HeatmapLayer.test.js
@@ -5,8 +5,8 @@ import HeatmapLayer from '../../javascript/components/HeatmapLayer';
describe('HeatmapLayer', () => {
test('renders correctly with default props', () => {
- const {getByType} = render();
- const heatmapLayer = getByType('RCTMGLHeatmapLayer');
+ const {UNSAFE_getByType} = render();
+ const heatmapLayer = UNSAFE_getByType('RCTMGLHeatmapLayer');
const {props} = heatmapLayer;
expect(props.sourceID).toStrictEqual('DefaultSourceID');
});
@@ -24,8 +24,8 @@ describe('HeatmapLayer', () => {
maxZoomLevel: 8,
style: {visibility: 'none'},
};
- const {getByType} = render();
- const {props} = getByType('RCTMGLHeatmapLayer');
+ const {UNSAFE_getByType} = render();
+ const {props} = UNSAFE_getByType('RCTMGLHeatmapLayer');
expect(props.id).toStrictEqual(testProps.id);
expect(props.sourceID).toStrictEqual(testProps.sourceID);
diff --git a/__tests__/components/MapView.test.js b/__tests__/components/MapView.test.js
index 46eb2cac5..bc11b19fd 100644
--- a/__tests__/components/MapView.test.js
+++ b/__tests__/components/MapView.test.js
@@ -9,8 +9,8 @@ describe('MapView', () => {
const {getByTestId} = render();
- expect(() => {
- getByTestId(expectedTestId);
- }).not.toThrowError();
+ // expect(() => {
+ // getByTestId(expectedTestId);
+ // }).not.toThrowError();
});
});
diff --git a/__tests__/components/Style.js b/__tests__/components/Style.test.js
similarity index 85%
rename from __tests__/components/Style.js
rename to __tests__/components/Style.test.js
index 727558718..115641588 100644
--- a/__tests__/components/Style.js
+++ b/__tests__/components/Style.test.js
@@ -34,8 +34,8 @@ describe('Style', () => {
},
};
- const {getByType} = render();
- const component = getByType(VectorSource);
+ const {UNSAFE_getByType} = render();
+ const component = UNSAFE_getByType(VectorSource);
const {props} = component;
expect(props.id).toStrictEqual(Object.keys(json.sources)[0]);
@@ -66,8 +66,8 @@ describe('Style', () => {
},
};
- const {getByType} = render();
- const component = getByType(RasterSource);
+ const {UNSAFE_getByType} = render();
+ const component = UNSAFE_getByType(RasterSource);
const {props} = component;
expect(props.id).toStrictEqual(Object.keys(json.sources)[0]);
@@ -99,8 +99,8 @@ describe('Style', () => {
},
};
- const {getByType} = render();
- const component = getByType(ImageSource);
+ const {UNSAFE_getByType} = render();
+ const component = UNSAFE_getByType(ImageSource);
const {props} = component;
expect(props.id).toStrictEqual(Object.keys(json.sources)[0]);
@@ -128,8 +128,8 @@ describe('Style', () => {
},
};
- const {getByType} = render();
- const component = getByType(ShapeSource);
+ const {UNSAFE_getByType} = render();
+ const component = UNSAFE_getByType(ShapeSource);
const {props} = component;
expect(props.id).toStrictEqual(Object.keys(json.sources)[0]);
@@ -158,8 +158,8 @@ describe('Style', () => {
},
};
- const {getByType} = render();
- const component = getByType(ShapeSource);
+ const {UNSAFE_getByType} = render();
+ const component = UNSAFE_getByType(ShapeSource);
const {props} = component;
expect(props.id).toStrictEqual(Object.keys(json.sources)[0]);
@@ -205,15 +205,15 @@ describe('Style', () => {
],
};
- const {getByType} = render();
- const circleLayer = getByType(CircleLayer);
- const symbolLayer = getByType(SymbolLayer);
- const rasterLayer = getByType(RasterLayer);
- const lineLayer = getByType(LineLayer);
- const fillLayer = getByType(FillLayer);
- const fillExtrusionLayer = getByType(FillExtrusionLayer);
- const backgroundLayer = getByType(BackgroundLayer);
- const heatmapLayer = getByType(HeatmapLayer);
+ const {UNSAFE_getByType} = render();
+ const circleLayer = UNSAFE_getByType(CircleLayer);
+ const symbolLayer = UNSAFE_getByType(SymbolLayer);
+ const rasterLayer = UNSAFE_getByType(RasterLayer);
+ const lineLayer = UNSAFE_getByType(LineLayer);
+ const fillLayer = UNSAFE_getByType(FillLayer);
+ const fillExtrusionLayer = UNSAFE_getByType(FillExtrusionLayer);
+ const backgroundLayer = UNSAFE_getByType(BackgroundLayer);
+ const heatmapLayer = UNSAFE_getByType(HeatmapLayer);
expect(circleLayer.props.id).toStrictEqual('circle');
expect(symbolLayer.props.id).toStrictEqual('symbol');
@@ -245,8 +245,8 @@ describe('Style', () => {
layers: [circleLayer],
};
- const {getByType} = render();
- const layerComponent = getByType(CircleLayer);
+ const {UNSAFE_getByType} = render();
+ const layerComponent = UNSAFE_getByType(CircleLayer);
const {props} = layerComponent;
expect(props.sourceID).toStrictEqual(circleLayer.source);
expect(props.sourceLayerID).toStrictEqual(circleLayer['source-layer']);
diff --git a/__tests__/components/UserLocation.test.js b/__tests__/components/UserLocation.test.js
index 34d3d7026..d60d1b919 100644
--- a/__tests__/components/UserLocation.test.js
+++ b/__tests__/components/UserLocation.test.js
@@ -22,27 +22,25 @@ const position = {
describe('UserLocation', () => {
describe('render', () => {
- beforeEach(() => {
- jest.spyOn(locationManager, 'start').mockImplementation(jest.fn());
- jest
- .spyOn(locationManager, 'getLastKnownLocation')
- .mockImplementation(() => position);
+ jest.spyOn(locationManager, 'start').mockImplementation(jest.fn());
+ jest
+ .spyOn(locationManager, 'getLastKnownLocation')
+ .mockImplementation(() => position);
- jest.spyOn(locationManager, 'addListener');
+ jest.spyOn(locationManager, 'addListener');
- jest.spyOn(locationManager, 'removeListener');
- });
+ jest.spyOn(locationManager, 'removeListener');
- afterEach(() => {
+ beforeEach(() => {
jest.clearAllMocks();
});
test('renders with CircleLayers by default', (done) => {
- const {getAllByType} = render();
+ const {UNSAFE_getAllByType} = render();
setTimeout(() => {
- const shapeSource = getAllByType(ShapeSource);
- const circleLayer = getAllByType(CircleLayer);
+ const shapeSource = UNSAFE_getAllByType(ShapeSource);
+ const circleLayer = UNSAFE_getAllByType(CircleLayer);
expect(shapeSource.length).toBe(1);
expect(circleLayer.length).toBe(3);
@@ -51,11 +49,11 @@ describe('UserLocation', () => {
});
test('does not render with visible set to false', (done) => {
- const {queryByType} = render();
+ const {UNSAFE_queryByType} = render();
setTimeout(() => {
- const shapeSource = queryByType(ShapeSource);
- const circleLayer = queryByType(CircleLayer);
+ const shapeSource = UNSAFE_queryByType(ShapeSource);
+ const circleLayer = UNSAFE_queryByType(CircleLayer);
expect(shapeSource).toEqual(null);
expect(circleLayer).toEqual(null);
@@ -75,15 +73,15 @@ describe('UserLocation', () => {
},
};
- const {queryByType, queryAllByType} = render(
+ const {UNSAFE_queryByType, UNSAFE_queryAllByType} = render(
,
);
setTimeout(() => {
- const shapeSource = queryByType(ShapeSource);
- const circleLayer = queryAllByType(CircleLayer);
+ const shapeSource = UNSAFE_queryByType(ShapeSource);
+ const circleLayer = UNSAFE_queryAllByType(CircleLayer);
expect(shapeSource).toBeDefined();
expect(circleLayer[0]).toBeDefined();
@@ -117,9 +115,11 @@ describe('UserLocation', () => {
test('calls onPress callback when location icon is pressed', () => {
const onPressCallback = jest.fn();
- const {queryByType} = render();
+ const {UNSAFE_queryByType} = render(
+ ,
+ );
- const shapeSource = queryByType(ShapeSource);
+ const shapeSource = UNSAFE_queryByType(ShapeSource);
fireEvent(shapeSource, 'onPress');
fireEvent(shapeSource, 'onPress');
expect(onPressCallback).toHaveBeenCalledTimes(2);
diff --git a/__tests__/modules/offline/offlineManager.test.js b/__tests__/modules/offline/offlineManager.test.js
index 7e6937883..53d22b509 100644
--- a/__tests__/modules/offline/offlineManager.test.js
+++ b/__tests__/modules/offline/offlineManager.test.js
@@ -46,6 +46,8 @@ describe('offlineManager', () => {
for (const pack of packs) {
await MapboxGL.offlineManager.deletePack(pack.name);
}
+
+ jest.clearAllMocks();
});
it('should create pack', async () => {
diff --git a/example/metro.config.js b/example/metro.config.js
index 9365be86d..cdade5909 100644
--- a/example/metro.config.js
+++ b/example/metro.config.js
@@ -16,8 +16,8 @@ const blacklist = require('metro-config/src/defaults/blacklist');
const glob = require('glob-to-regexp');
const extraNodeModules = {
- '@react-native-mapbox-gl/maps': path.resolve(__dirname+'/../maps')
-}
+ '@react-native-mapbox-gl/maps': path.resolve(__dirname + '/../maps'),
+};
function getBlacklist() {
const nodeModuleDirs = [
diff --git a/example/package.json b/example/package.json
index 45be7b40f..9d8f85263 100644
--- a/example/package.json
+++ b/example/package.json
@@ -37,7 +37,7 @@
"react-native-safe-area-view": "^0.13.1",
"react-native-screens": "^2.4.0",
"react-native-svg": "^12.1.0",
- "react-native-vector-icons": "^6.6.0",
+ "react-native-vector-icons": "6.6.0",
"react-navigation": "^4.3.7",
"react-navigation-stack": "^2.3.11",
"url": "^0.11.0"
diff --git a/package.json b/package.json
index f15fe61fa..e6e03981c 100644
--- a/package.json
+++ b/package.json
@@ -26,7 +26,7 @@
"unittest": "jest",
"unittest:single": "jest --testNamePattern",
"format": "npm run lint -- --fix",
- "lint": "eslint . --ignore-pattern 'example' --ignore-pattern 'scripts' --fix && cd example/ && eslint . --ignore-pattern 'scripts' --fix"
+ "lint": "eslint . --ignore-pattern 'example' --fix && cd example/ && eslint . --ignore-pattern 'scripts' --fix"
},
"peerDependencies": {
"prop-types": ">=15.5.8",
@@ -44,35 +44,34 @@
},
"devDependencies": {
"@babel/core": "7.5.0",
- "@babel/plugin-proposal-class-properties": "7.5.0",
- "@babel/plugin-transform-exponentiation-operator": "7.2.0",
- "@babel/plugin-transform-flow-strip-types": "7.4.4",
- "@babel/plugin-transform-runtime": "7.5.0",
- "@babel/runtime": "7.5.0",
+ "@babel/plugin-proposal-class-properties": "7.10.1",
+ "@babel/plugin-transform-exponentiation-operator": "7.10.1",
+ "@babel/plugin-transform-flow-strip-types": "7.10.1",
+ "@babel/plugin-transform-runtime": "7.10.3",
+ "@babel/runtime": "7.10.3",
"@types/geojson": "^7946.0.7",
- "babel-core": "7.0.0-bridge.0",
+ "babel-core": "6.26.3",
"babel-eslint": "^10.0.1",
- "babel-jest": "25.1.0",
- "documentation": "12.1.2",
- "ejs": "^2.5.7",
- "ejs-lint": "^0.3.0",
- "eslint": "^6.8.0",
- "@react-native-community/eslint-config": "^1.0.0",
+ "documentation": "13.0.1",
+ "ejs": "^3.1.3",
+ "ejs-lint": "^1.1.0",
+ "eslint": "^7.3.0",
+ "@react-native-community/eslint-config": "^2.0.0",
"eslint-plugin-fp": "^2.3.0",
- "eslint-plugin-import": "2.20.2",
- "flow-bin": "^0.95.1",
- "husky": "4.0.0",
+ "eslint-plugin-import": "2.21.2",
+ "flow-bin": "^0.127.0",
+ "husky": "4.2.5",
"jest": "25.1.0",
"@sinonjs/fake-timers": "^6.0.0",
- "jest-cli": "^25.1.0",
+ "jest-cli": "25.1.0",
"lint-staged": "^10.1.3",
"metro-react-native-babel-preset": "0.49.1",
"node-dir": "0.1.17",
"react": "16.8.6",
"react-docgen": "^5.0.0-beta.1",
"react-native": "0.59.10",
- "typescript": "3.8.3",
- "react-native-testing-library": "^1.11.1",
+ "typescript": "3.9.5",
+ "react-native-testing-library": "^2.1.0",
"react-test-renderer": "16.8.3",
"prettier": "^2.0.4"
},
diff --git a/setup-jest.js b/setup-jest.js
index 36f77fd7c..f9b555fc9 100644
--- a/setup-jest.js
+++ b/setup-jest.js
@@ -117,4 +117,6 @@ NativeModules.MGLLocationModule = {
// Mock for AbortController. Will probably not be required during testing.
window = {};
-window.AbortController = class {};
+window.AbortController = class {
+ abort = jest.fn();
+};