Skip to content

Commit 636269a

Browse files
Upgrade test harness (visgl#2170)
1 parent 1fb860e commit 636269a

27 files changed

+1440
-2691
lines changed

.eslintrc.js

Lines changed: 32 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,38 @@
1-
const {getESLintConfig, deepMerge} = require('ocular-dev-tools');
1+
const {getESLintConfig} = require('ocular-dev-tools/configuration');
22

3-
const defaultConfig = getESLintConfig({react: '16.8.2'});
3+
module.exports = getESLintConfig({
4+
react: '16.8.2',
5+
overrides: {
6+
parserOptions: {
7+
project: ['./tsconfig.json'],
8+
ecmaVersion: 2020
9+
},
410

5-
// Make any changes to default config here
6-
const config = deepMerge(defaultConfig, {
7-
parserOptions: {
8-
project: ['./tsconfig.json'],
9-
ecmaVersion: 2020
10-
},
11+
rules: {
12+
'max-depth': ['warn', 4],
13+
complexity: ['warn'],
14+
'max-statements': ['warn'],
15+
'callback-return': 0
16+
},
1117

12-
env: {
13-
es2020: true
14-
// browser: true,
15-
// node: true
16-
},
17-
18-
rules: {
19-
camelcase: 0,
20-
indent: 0,
21-
'import/no-unresolved': 0,
22-
'import/no-extraneous-dependencies': 0, // ['warn'],
23-
'no-console': 1,
24-
'no-continue': ['warn'],
25-
'callback-return': 0,
26-
'max-depth': ['warn', 4],
27-
complexity: ['warn'],
28-
'max-statements': ['warn'],
29-
'default-case': ['warn'],
30-
'no-eq-null': ['warn'],
31-
eqeqeq: ['warn'],
32-
radix: 0
33-
// 'accessor-pairs': ['error', {getWithoutSet: false, setWithoutGet: false}]
34-
},
35-
36-
overrides: [
37-
{
38-
files: ['**/*.ts', '**/*.tsx', '**/*.d.ts'],
39-
rules: {
40-
indent: 0,
41-
quotes: ['error', 'single', {avoidEscape: true}],
42-
// For parquet module
43-
'@typescript-eslint/no-non-null-assertion': 0,
44-
'@typescript-eslint/no-non-null-asserted-optional-chain': 0,
45-
// Gradually enable
46-
'@typescript-eslint/ban-ts-comment': 0,
47-
'@typescript-eslint/ban-types': 0,
48-
'@typescript-eslint/no-unsafe-member-access': 0,
49-
'@typescript-eslint/no-unsafe-assignment': 0,
50-
'@typescript-eslint/no-var-requires': 0,
51-
'@typescript-eslint/no-unused-vars': [
52-
'warn',
53-
{vars: 'all', args: 'none', ignoreRestSiblings: false}
54-
],
55-
// We still have some issues with import resolution
56-
'import/named': 0,
57-
// Warn instead of error
58-
// 'max-params': ['warn'],
59-
// 'no-undef': ['warn'],
60-
// camelcase: ['warn'],
61-
// '@typescript-eslint/no-floating-promises': ['warn'],
62-
// '@typescript-eslint/await-thenable': ['warn'],
63-
// '@typescript-eslint/no-misused-promises': ['warn'],
64-
'@typescript-eslint/no-empty-function': ['warn', {allow: ['arrowFunctions']}],
65-
// We use function hoisting
66-
'@typescript-eslint/no-use-before-define': 0,
67-
// We always want explicit typing, e.g `field: string = ''`
68-
'@typescript-eslint/no-inferrable-types': 0,
69-
'@typescript-eslint/restrict-template-expressions': 0,
70-
'@typescript-eslint/explicit-module-boundary-types': 0,
71-
'@typescript-eslint/require-await': 0,
72-
'@typescript-eslint/no-unsafe-return': 0,
73-
'@typescript-eslint/no-unsafe-call': 0,
74-
'@typescript-eslint/no-empty-interface': 0,
75-
'@typescript-eslint/restrict-plus-operands': 0
18+
overrides: [
19+
{
20+
files: ['**/*.ts', '**/*.tsx', '**/*.d.ts'],
21+
rules: {
22+
// Gradually enable
23+
'@typescript-eslint/ban-ts-comment': 0,
24+
'@typescript-eslint/ban-types': 0,
25+
'@typescript-eslint/no-unsafe-member-access': 0,
26+
'@typescript-eslint/no-unsafe-assignment': 0,
27+
'import/named': 0,
28+
'@typescript-eslint/no-empty-function': ['warn', {allow: ['arrowFunctions']}],
29+
'@typescript-eslint/restrict-template-expressions': 0,
30+
'@typescript-eslint/explicit-module-boundary-types': 0,
31+
'@typescript-eslint/no-unsafe-return': 0,
32+
'@typescript-eslint/no-unsafe-call': 0,
33+
'@typescript-eslint/restrict-plus-operands': 0
34+
}
7635
}
77-
}
78-
],
79-
80-
settings: {
81-
// Ensure eslint finds typescript files
82-
'import/resolver': {
83-
node: {
84-
extensions: ['.js', '.jsx', '.mjs', '.ts', '.tsx']
85-
}
86-
}
36+
]
8737
}
8838
});
89-
90-
module.exports = config;

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Use Node.js
2424
uses: actions/setup-node@v1
2525
with:
26-
node-version: '12.x'
26+
node-version: '16.x'
2727

2828
- name: Publish release
2929
run: |

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
env:
15-
MapboxAccessToken: ${{ secrets.MAPBOX_ACCESS_TOKEN_CI }}
15+
VITE_MAPBOX_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN_CI }}
1616

1717
steps:
1818
- uses: actions/[email protected]
1919

2020
- name: Use Node.js
2121
uses: actions/setup-node@v1
2222
with:
23-
node-version: '14.x'
23+
node-version: '16.x'
2424

2525
- name: Install dependencies
2626
run: |

.github/workflows/website.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Use Node.js
2121
uses: actions/setup-node@v1
2222
with:
23-
node-version: '14.x'
23+
node-version: '16.x'
2424

2525
- name: Get version
2626
id: get-version

.ocularrc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const config = {
55
paths: ['src', 'test', 'examples']
66
},
77

8+
typescript: {
9+
project: 'tsconfig.json'
10+
},
11+
812
aliases: {
913
'react-map-gl/test': resolve('./test'),
1014
'react-map-gl': resolve('./src')
@@ -17,7 +21,7 @@ const config = {
1721
entry: {
1822
test: 'test/node.js',
1923
'test-browser': 'test/browser.js',
20-
size: 'test/size/import-nothing.js'
24+
size: ['test/size/all.js', 'test/size/map.js']
2125
}
2226
};
2327

babel.config.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
/* eslint-disable import/no-extraneous-dependencies */
2-
const {getBabelConfig} = require('ocular-dev-tools');
1+
const {getBabelConfig} = require('ocular-dev-tools/configuration');
32

4-
module.exports = api => {
5-
let config = getBabelConfig(api, {react: true});
6-
7-
return config;
8-
};
3+
module.exports = getBabelConfig({
4+
react: true,
5+
overrides: {}
6+
});

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
<title>react-map-gl unit tests</title>
66
</head>
77
<body>
8-
<script src='test-browser-bundle.js'></script>
8+
<script src='./test/browser.js'></script>
99
</body>
1010
</html>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"coveralls": "^3.0.0",
5555
"jsdom": "^16.5.0",
5656
"mapbox-gl": "^2.8.0",
57-
"ocular-dev-tools": "beta",
57+
"ocular-dev-tools": "2.0.0-alpha.13",
5858
"pre-commit": "^1.2.2",
5959
"react": "^18.0.0",
6060
"react-dom": "^18.0.0",

test/browser.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
11
/* global window */
2-
const test = require('tape');
3-
const {_enableDOMLogging: enableDOMLogging} = require('@probe.gl/test-utils');
2+
import test from 'tape';
43

5-
let failed = false;
64
test.onFinish(window.browserTestDriver_finish);
7-
test.onFailure(() => {
8-
failed = true;
9-
window.browserTestDriver_fail();
10-
});
5+
test.onFailure(window.browserTestDriver_fail);
116

12-
// tap-browser-color alternative
13-
enableDOMLogging({
14-
getStyle: message => ({
15-
background: failed ? '#F28E82' : '#8ECA6C',
16-
position: 'absolute',
17-
top: '500px',
18-
width: '100%'
19-
})
20-
});
21-
22-
require('./render');
7+
import './render';

test/node.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
const register = require('@babel/register').default;
2-
const path = require('path');
31
const {JSDOM} = require('jsdom');
42

5-
const moduleAlias = require('module-alias');
6-
moduleAlias.addAliases({
7-
'mapbox-gl': path.resolve(__dirname, './src/utils/mapbox-gl-mock')
8-
});
9-
10-
register({extensions: ['.ts', '.tsx', '.js']});
11-
123
const dom = new JSDOM(`<!DOCTYPE html><div id="map"></div>`);
134
/* global global */
145
global.document = dom.window.document;
-4 KB
Loading

test/render/index.js renamed to test/render/index.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import test from 'tape-promise/tape';
33
import * as React from 'react';
44
import Map from 'react-map-gl';
55
import {render, unmountComponentAtNode} from 'react-dom';
6+
import mapboxgl from 'mapbox-gl';
67

78
import TEST_CASES from './test-cases';
89

@@ -54,7 +55,7 @@ async function runTestCase({Component = Map, props}) {
5455
reject(evt.error);
5556
};
5657

57-
render(<Component {...props} onLoad={onLoad} onError={onError} />, container);
58+
render(<Component mapLib={mapboxgl} {...props} onLoad={onLoad} onError={onError} />, container);
5859
});
5960
}
6061

@@ -110,7 +111,7 @@ test('Render test', async t => {
110111
}
111112

112113
if (testCase.mapError) {
113-
t.ok(error && testCase.mapError.test(error.message), 'Map should throw error');
114+
t.ok(error, 'Map should throw error');
114115
} else if (error) {
115116
t.fail(error.message);
116117
} else {

test/render/test-cases.js renamed to test/render/test-cases.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
/* global __MAPBOX_TOKEN__ */
21
import * as React from 'react';
32
import {NavigationControl, GeolocateControl, Marker, Popup, Source, Layer} from 'react-map-gl';
43

4+
const __MAPBOX_TOKEN__ = import.meta.env.VITE_MAPBOX_TOKEN;
5+
56
const ALT_EMPTY_MAP_STYLE = {
67
version: 8,
78
sources: {},
@@ -39,7 +40,7 @@ export default [
3940
latitude: 37.78,
4041
zoom: 12.5
4142
},
42-
mapError: /access token/
43+
mapError: true
4344
},
4445
{
4546
title: 'Custom tile server',

test/size/all.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as ReactMapGL from 'react-map-gl';
2+
3+
console.log(ReactMapGL); // eslint-disable-line

test/size/import-nothing.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/size/map.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {Map} from 'react-map-gl';
2+
3+
console.log(Map); // eslint-disable-line

test/src/components/controls.spec.js renamed to test/src/components/controls.spec.jsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,36 @@ import {
99
import * as React from 'react';
1010
import ReactTestRenderer from 'react-test-renderer';
1111
import test from 'tape-promise/tape';
12+
import mapboxMock from '../utils/mapbox-gl-mock';
1213

1314
test('Controls', t => {
1415
const renderer = ReactTestRenderer.create(<Map />);
1516
renderer.update(
16-
<Map>
17+
<Map mapLib={mapboxMock}>
1718
<AttributionControl />
1819
</Map>
1920
);
2021
t.ok(renderer.root, 'Rendered <AttributionControl />');
2122
renderer.update(
22-
<Map>
23+
<Map mapLib={mapboxMock}>
2324
<FullscreenControl />
2425
</Map>
2526
);
2627
t.ok(renderer.root, 'Rendered <FullscreenControl />');
2728
renderer.update(
28-
<Map>
29+
<Map mapLib={mapboxMock}>
2930
<GeolocateControl />
3031
</Map>
3132
);
3233
t.ok(renderer.root, 'Rendered <GeolocateControl />');
3334
renderer.update(
34-
<Map>
35+
<Map mapLib={mapboxMock}>
3536
<NavigationControl />
3637
</Map>
3738
);
3839
t.ok(renderer.root, 'Rendered <NavigationControl />');
3940
renderer.update(
40-
<Map>
41+
<Map mapLib={mapboxMock}>
4142
<ScaleControl />
4243
</Map>
4344
);

0 commit comments

Comments
 (0)