diff --git a/superset-frontend/temporary_superset_ui/superset-ui/.esprintrc b/superset-frontend/temporary_superset_ui/superset-ui/.esprintrc deleted file mode 100644 index 4c0d584b94..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui/.esprintrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "paths": ["{packages,plugins}/*/{src,test,types}/**/*.{ts,tsx,js,jsx}"], - "ignores": ["**/node_modules/**/*"], - "port": 5004 -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui/jest.config.js b/superset-frontend/temporary_superset_ui/superset-ui/jest.config.js index 732a8de696..21826fa4cb 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/jest.config.js +++ b/superset-frontend/temporary_superset_ui/superset-ui/jest.config.js @@ -48,23 +48,16 @@ module.exports = { }, moduleFileExtensions: ['mock.js', 'ts', 'tsx', 'js', 'jsx', 'json', 'node'], moduleNameMapper: { - '^.+\\.(ttf|eot|otf|svg|woff|woff2|mp3|png|jpg|jpeg|gif|ico)$': - '/node_modules/@airbnb/config-jest/mocks/file.js', - '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': - '/__mocks__/fileMock.js', - '\\.(css|less)$': 'identity-obj-proxy', + '\\.(css|less|geojson)$': '/test/__mocks__/mockExportObject.js', + '\\.(gif|ttf|eot|png|jpg)$': '/test/__mocks__/mockExportString.js', + '\\.svg$': '/test/__mocks__/svgrMock.tsx', + '@superset-ui/(((?!(legacy-preset-chart-deckgl|core/src)).)*)$': + '/node_modules/@superset-ui/$1/src', + '@superset-ui/core/src/(.*)$': + '/node_modules/@superset-ui/core/src/$1', }, roots: ['/packages', '/plugins'], - setupFiles: [ - '/node_modules/@airbnb/config-jest/setup/shims.js', - '/node_modules/@airbnb/config-jest/setup/console.js', - '/node_modules/@airbnb/config-jest/setup/dom.js', - ], - setupFilesAfterEnv: [ - '/node_modules/@airbnb/config-jest/bootstrap/react.js', - '/node_modules/@airbnb/config-jest/bootstrap/consumer.js', - '@airbnb/config-jest/enzyme', - ], + setupFiles: ['/test/setup.ts'], testEnvironment: 'jsdom', testURL: 'http://localhost', timers: 'real', diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-core/test/translation/Translator.test.ts b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-core/test/translation/Translator.test.ts index ff1b09f45c..bab9081a7c 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-core/test/translation/Translator.test.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-core/test/translation/Translator.test.ts @@ -17,6 +17,7 @@ * under the License. */ +import { logging } from '@superset-ui/core'; import Translator from '@superset-ui/core/src/translation/Translator'; import { configure, @@ -34,6 +35,18 @@ configure({ }); describe('Translator', () => { + const spy = jest.spyOn(logging, 'warn'); + + beforeAll(() => { + spy.mockImplementation((info: any) => { + throw new Error(info); + }); + }); + + afterAll(() => { + spy.mockRestore(); + }); + describe('new Translator(config)', () => { it('initializes when config is not specified', () => { expect(new Translator()).toBeInstanceOf(Translator); diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-core/test/utils/logging.test.ts b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-core/test/utils/logging.test.ts index dcca3a69f4..c5e158c946 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-core/test/utils/logging.test.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-core/test/utils/logging.test.ts @@ -21,6 +21,10 @@ describe('logging', () => { beforeEach(() => { jest.resetModules(); + // Explicit is better than implicit + console.warn = console.error = function mockedConsole(message) { + throw new Error(message); + }; }); it('should pipe to `console` methods', () => { const { logging } = require('@superset-ui/core/src'); @@ -36,9 +40,16 @@ describe('logging', () => { expect(() => { logging.error('error'); }).toThrow('error'); + + // to support: npx jest --silent + const spy = jest.spyOn(logging, 'trace'); + spy.mockImplementation(() => { + throw new Error('Trace:'); + }); expect(() => { logging.trace(); }).toThrow('Trace:'); + spy.mockRestore(); }); it('should use noop functions when console unavailable', () => { const { console } = window; diff --git a/superset-frontend/temporary_superset_ui/superset-ui/test/__mocks__/mockExportObject.js b/superset-frontend/temporary_superset_ui/superset-ui/test/__mocks__/mockExportObject.js new file mode 100644 index 0000000000..ab22d88b5b --- /dev/null +++ b/superset-frontend/temporary_superset_ui/superset-ui/test/__mocks__/mockExportObject.js @@ -0,0 +1,19 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +module.exports = {}; diff --git a/superset-frontend/temporary_superset_ui/superset-ui/test/__mocks__/mockExportString.js b/superset-frontend/temporary_superset_ui/superset-ui/test/__mocks__/mockExportString.js new file mode 100644 index 0000000000..5b7f1d6da9 --- /dev/null +++ b/superset-frontend/temporary_superset_ui/superset-ui/test/__mocks__/mockExportString.js @@ -0,0 +1,19 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +module.exports = 'test-file-stub'; diff --git a/superset-frontend/temporary_superset_ui/superset-ui/test/__mocks__/svgrMock.tsx b/superset-frontend/temporary_superset_ui/superset-ui/test/__mocks__/svgrMock.tsx new file mode 100644 index 0000000000..6073fd6d9f --- /dev/null +++ b/superset-frontend/temporary_superset_ui/superset-ui/test/__mocks__/svgrMock.tsx @@ -0,0 +1,29 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import React, { SVGProps } from 'react'; + +const SvgrMock = React.forwardRef>( + (props, ref) => , +); + +SvgrMock.displayName = 'SvgrMock'; + +export const ReactComponent = SvgrMock; +export default SvgrMock; diff --git a/superset-frontend/temporary_superset_ui/superset-ui/test/setup.ts b/superset-frontend/temporary_superset_ui/superset-ui/test/setup.ts index 778ae502ad..ff1499de9b 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/test/setup.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/test/setup.ts @@ -16,10 +16,11 @@ * specific language governing permissions and limitations * under the License. */ -import { configure } from '@superset-ui/core'; +import { configure } from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; import CacheStorage from './shims/CacheStorage'; -configure(); - // @ts-ignore global.caches = new CacheStorage(); + +configure({ adapter: new Adapter() });