mirror of https://github.com/apache/superset.git
chore: coordinate superset-ui unittest with main repository (#1463)
This commit is contained in:
parent
490029a1f3
commit
067fc8a009
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"paths": ["{packages,plugins}/*/{src,test,types}/**/*.{ts,tsx,js,jsx}"],
|
||||
"ignores": ["**/node_modules/**/*"],
|
||||
"port": 5004
|
||||
}
|
|
@ -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)$':
|
||||
'<rootDir>/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)$':
|
||||
'<rootDir>/__mocks__/fileMock.js',
|
||||
'\\.(css|less)$': 'identity-obj-proxy',
|
||||
'\\.(css|less|geojson)$': '<rootDir>/test/__mocks__/mockExportObject.js',
|
||||
'\\.(gif|ttf|eot|png|jpg)$': '<rootDir>/test/__mocks__/mockExportString.js',
|
||||
'\\.svg$': '<rootDir>/test/__mocks__/svgrMock.tsx',
|
||||
'@superset-ui/(((?!(legacy-preset-chart-deckgl|core/src)).)*)$':
|
||||
'<rootDir>/node_modules/@superset-ui/$1/src',
|
||||
'@superset-ui/core/src/(.*)$':
|
||||
'<rootDir>/node_modules/@superset-ui/core/src/$1',
|
||||
},
|
||||
roots: ['<rootDir>/packages', '<rootDir>/plugins'],
|
||||
setupFiles: [
|
||||
'<rootDir>/node_modules/@airbnb/config-jest/setup/shims.js',
|
||||
'<rootDir>/node_modules/@airbnb/config-jest/setup/console.js',
|
||||
'<rootDir>/node_modules/@airbnb/config-jest/setup/dom.js',
|
||||
],
|
||||
setupFilesAfterEnv: [
|
||||
'<rootDir>/node_modules/@airbnb/config-jest/bootstrap/react.js',
|
||||
'<rootDir>/node_modules/@airbnb/config-jest/bootstrap/consumer.js',
|
||||
'@airbnb/config-jest/enzyme',
|
||||
],
|
||||
setupFiles: ['<rootDir>/test/setup.ts'],
|
||||
testEnvironment: 'jsdom',
|
||||
testURL: 'http://localhost',
|
||||
timers: 'real',
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 = {};
|
|
@ -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';
|
|
@ -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<SVGSVGElement, SVGProps<SVGSVGElement>>(
|
||||
(props, ref) => <svg ref={ref} {...props} />,
|
||||
);
|
||||
|
||||
SvgrMock.displayName = 'SvgrMock';
|
||||
|
||||
export const ReactComponent = SvgrMock;
|
||||
export default SvgrMock;
|
|
@ -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() });
|
||||
|
|
Loading…
Reference in New Issue