Skip to content

Commit

Permalink
[Chore] fix tests (#2602)
Browse files Browse the repository at this point in the history
- Fix jest test by importing loader.gl/polyfill from esm
- Fix browser jsdom test by importing loaders.gl/polyfill from esm
- Import @kepler.gl src in test
- Delete unused files
- Update jsdom

Signed-off-by: Shan He <heshan0131@gmail.com>
  • Loading branch information
heshan0131 authored Aug 9, 2024
1 parent e5111da commit bc90b0e
Show file tree
Hide file tree
Showing 25 changed files with 161 additions and 248 deletions.
8 changes: 4 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"jestPuppeteer": true
},
"parser": "@typescript-eslint/parser",
"plugins": ["babel", "prettier", "react", "@typescript-eslint", "enzyme-deprecation"],
"plugins": ["babel", "prettier", "react", "@typescript-eslint", "enzyme-deprecation", "jest"],
"rules": {
"valid-jsdoc": 0,
"no-var": 0,
Expand Down Expand Up @@ -53,9 +53,9 @@
"files": ["*.ts", "*.tsx"],
"rules": {
"no-undef": 0,
"no-unused-vars": 0,
},
},
"no-unused-vars": 0
}
}
],
"settings": {
"react": {
Expand Down
7 changes: 0 additions & 7 deletions .prettierrc

This file was deleted.

10 changes: 10 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project

module.exports = {
bracketSpacing: false,
printWidth: 100,
semi: true,
singleQuote: true,
trailingComma: "none"
}
4 changes: 0 additions & 4 deletions actions.js

This file was deleted.

9 changes: 7 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

const {resolve} = require('path');
const KeplerPackage = require('./package');
const {RESOLVE_ALIASES} = require('./webpack/shared-webpack-configuration');

const nodeModules = resolve(__dirname, 'node_modules');

Expand Down Expand Up @@ -30,8 +31,12 @@ const PLUGINS = [
test: './test',
// We explicitly transpile this ESM library in scripts/fix-dependencies.js and consume the transpiled version here
// This may not be needed once switch to Jest is complete as it is handled by transformIgnorePatterns
'@mapbox/tiny-sdf': `${nodeModules}/@mapbox/tiny-sdf/index.cjs`
},
'@mapbox/tiny-sdf': `${nodeModules}/@mapbox/tiny-sdf/index.cjs`,
// compile from @kepler.gl src
...RESOLVE_ALIASES,
// loaders.gl cjs bundle of polyfills is not transpiled properly, use esm instead
'@loaders.gl/polyfills': `${nodeModules}/@loaders.gl/polyfills/src`
}
}
],
[
Expand Down
2 changes: 1 addition & 1 deletion bindings/kepler.gl-jupyter/keplergl/keplergl.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""module for keplergl-jupyter"""
# SPDX-License-Identifier: MIT
# Copyright contributors to the kepler.gl project

#module for keplergl-jupyter
import base64
import sys
import json
Expand Down
4 changes: 0 additions & 4 deletions cloud-providers.js

This file was deleted.

4 changes: 0 additions & 4 deletions components.js

This file was deleted.

4 changes: 0 additions & 4 deletions constants.js

This file was deleted.

4 changes: 0 additions & 4 deletions effects.js

This file was deleted.

24 changes: 15 additions & 9 deletions examples/webpack.config.local.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ function makeLocalDevConfig(env, EXAMPLE_DIR = LIB_DIR, externals = {}) {
test: /\.(js|ts|tsx)$/,
use: ['source-map-loader'],
enforce: 'pre',
exclude: [/node_modules\/react-palm/, /node_modules\/react-data-grid/, /node_modules\/@loaders.gl/, /node_module\/@probe.gl/]
exclude: [
/node_modules\/react-palm/,
/node_modules\/react-data-grid/,
/node_modules\/@loaders.gl/,
/node_modules\/@probe.gl/,
/node_modules\/@turf\/jsts/
]
},
// for compiling apache-arrow ESM module
{
Expand All @@ -129,18 +135,18 @@ function makeLocalDevConfig(env, EXAMPLE_DIR = LIB_DIR, externals = {}) {
loader: 'babel-loader',
options: {
plugins: [
"@babel/plugin-transform-class-properties",
"@babel/plugin-transform-optional-chaining",
"@babel/plugin-transform-logical-assignment-operators",
"@babel/plugin-transform-nullish-coalescing-operator",
"@babel/plugin-transform-export-namespace-from"
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from'
],
include: [
/node_modules\/@loaders\.gl/,
/node_modules\/@probe\.gl/,
/node_modules\/@math\.gl/
],
exclude: [/node_modules\/(?!(@loaders\.gl|@probe\.gl|@math\.gl)).*/],
exclude: [/node_modules\/(?!(@loaders\.gl|@probe\.gl|@math\.gl)).*/]
}
}
}
Expand Down Expand Up @@ -184,8 +190,8 @@ function makeBabelRule(env, exampleDir) {
presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'],
plugins: [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
"@babel/plugin-transform-logical-assignment-operators",
"@babel/plugin-transform-nullish-coalescing-operator",
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-export-namespace-from',
Expand Down
13 changes: 10 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ const config = {
verbose: true,
testPathIgnorePatterns: [
// ignore all dist computed directories
"<rootDir>/.*(/|\\\\)dist(/|\\\\).*"
'<rootDir>/.*(/|\\\\)dist(/|\\\\).*'
],
testMatch: [
'<rootDir>/src/**/*.spec.(ts|tsx)',
'<rootDir>/src/**/*.spec.js',
'<rootDir>/test/**/*.spec.js'
],
testMatch: ['<rootDir>/src/**/*.spec.(ts|tsx)', '<rootDir>/src/**/*.spec.js', '<rootDir>/test/**/*.spec.js'],
// Per https://jestjs.io/docs/configuration#transformignorepatterns-arraystring, transformIgnorePatterns ignores
// node_modules and pnp folders by default so that they are not transpiled
// Some libraries (even if transitive) are transitioning to ESM and need additional transpilation. Relevant issues:
// - tiny-sdf: https://github.com/visgl/deck.gl/issues/7735
transformIgnorePatterns: ['/node_modules/(?!(.*@mapbox/tiny-sdf.*))', '\\.pnp\\.[^\\/]+$']
transformIgnorePatterns: [
'/node_modules\\/(?!(.*@mapbox\\/tiny-sdf\\.*|@loaders\\.gl))',
'\\.pnp\\.[^\\/]+$'
]
};

module.exports = config;
5 changes: 2 additions & 3 deletions jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Copyright contributors to the kepler.gl project

import '@testing-library/jest-dom';
import * as Utils from '@kepler.gl/utils';
require('@loaders.gl/polyfills');
import {installFilePolyfills} from '@loaders.gl/polyfills';
installFilePolyfills();

jest.mock('mapbox-gl/dist/mapbox-gl', () => ({
Map: () => ({})
Expand All @@ -16,4 +16,3 @@ jest.mock('@kepler.gl/utils', () => ({
}));

global.URL.createObjectURL = jest.fn();

4 changes: 0 additions & 4 deletions layers.js

This file was deleted.

4 changes: 0 additions & 4 deletions localization.js

This file was deleted.

4 changes: 0 additions & 4 deletions middleware.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"global": "^4.4.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jsdom": "^16.4.0",
"jsdom": "^24.1.1",
"json-loader": "^0.5.4",
"maplibre-gl": "^3.6.2",
"minimist": "^1.2.6",
Expand Down
4 changes: 0 additions & 4 deletions processors.js

This file was deleted.

4 changes: 0 additions & 4 deletions reducers.js

This file was deleted.

4 changes: 0 additions & 4 deletions schemas.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/src/modals/save-map-modal.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {fireEvent} from '@testing-library/react';
import SaveMapModalFactory from './save-map-modal';
import {renderWithTheme} from 'test/helpers/component-jest-utils';
import {useCloudListProvider} from '../hooks/use-cloud-list-provider';
import {dataTestIds} from '@kepler.gl/constants/src';
import {dataTestIds} from '@kepler.gl/constants';

const SaveMapModal = SaveMapModalFactory();

Expand Down
4 changes: 0 additions & 4 deletions styles.js

This file was deleted.

6 changes: 5 additions & 1 deletion test/browser/components/injector-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,17 @@ test('Components -> injector -> wrong factory type', t => {
</Provider>
);

t.ok(spy.calledTwice, 'should call console.error twice');
t.equal(
spy.getCall(0).args[0],
'Error injecting factory: ',
'should warn when default factory is not provided'
);

t.equal(
spy.getCall(1).args[0],
'factory and its replacement should be a function',
'should warn when default factory is not provided'
);
// test if custom header is rendered
t.ok(wrapper.find('.side-panel__panel-header').length, 'should render default header');

Expand Down
4 changes: 0 additions & 4 deletions utils.js

This file was deleted.

Loading

0 comments on commit bc90b0e

Please sign in to comment.