mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
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'],
|
moduleFileExtensions: ['mock.js', 'ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
'^.+\\.(ttf|eot|otf|svg|woff|woff2|mp3|png|jpg|jpeg|gif|ico)$':
|
'\\.(css|less|geojson)$': '<rootDir>/test/__mocks__/mockExportObject.js',
|
||||||
'<rootDir>/node_modules/@airbnb/config-jest/mocks/file.js',
|
'\\.(gif|ttf|eot|png|jpg)$': '<rootDir>/test/__mocks__/mockExportString.js',
|
||||||
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
|
'\\.svg$': '<rootDir>/test/__mocks__/svgrMock.tsx',
|
||||||
'<rootDir>/__mocks__/fileMock.js',
|
'@superset-ui/(((?!(legacy-preset-chart-deckgl|core/src)).)*)$':
|
||||||
'\\.(css|less)$': 'identity-obj-proxy',
|
'<rootDir>/node_modules/@superset-ui/$1/src',
|
||||||
|
'@superset-ui/core/src/(.*)$':
|
||||||
|
'<rootDir>/node_modules/@superset-ui/core/src/$1',
|
||||||
},
|
},
|
||||||
roots: ['<rootDir>/packages', '<rootDir>/plugins'],
|
roots: ['<rootDir>/packages', '<rootDir>/plugins'],
|
||||||
setupFiles: [
|
setupFiles: ['<rootDir>/test/setup.ts'],
|
||||||
'<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',
|
|
||||||
],
|
|
||||||
testEnvironment: 'jsdom',
|
testEnvironment: 'jsdom',
|
||||||
testURL: 'http://localhost',
|
testURL: 'http://localhost',
|
||||||
timers: 'real',
|
timers: 'real',
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { logging } from '@superset-ui/core';
|
||||||
import Translator from '@superset-ui/core/src/translation/Translator';
|
import Translator from '@superset-ui/core/src/translation/Translator';
|
||||||
import {
|
import {
|
||||||
configure,
|
configure,
|
||||||
@ -34,6 +35,18 @@ configure({
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Translator', () => {
|
describe('Translator', () => {
|
||||||
|
const spy = jest.spyOn(logging, 'warn');
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
spy.mockImplementation((info: any) => {
|
||||||
|
throw new Error(info);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
spy.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
describe('new Translator(config)', () => {
|
describe('new Translator(config)', () => {
|
||||||
it('initializes when config is not specified', () => {
|
it('initializes when config is not specified', () => {
|
||||||
expect(new Translator()).toBeInstanceOf(Translator);
|
expect(new Translator()).toBeInstanceOf(Translator);
|
||||||
|
@ -21,6 +21,10 @@
|
|||||||
describe('logging', () => {
|
describe('logging', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetModules();
|
jest.resetModules();
|
||||||
|
// Explicit is better than implicit
|
||||||
|
console.warn = console.error = function mockedConsole(message) {
|
||||||
|
throw new Error(message);
|
||||||
|
};
|
||||||
});
|
});
|
||||||
it('should pipe to `console` methods', () => {
|
it('should pipe to `console` methods', () => {
|
||||||
const { logging } = require('@superset-ui/core/src');
|
const { logging } = require('@superset-ui/core/src');
|
||||||
@ -36,9 +40,16 @@ describe('logging', () => {
|
|||||||
expect(() => {
|
expect(() => {
|
||||||
logging.error('error');
|
logging.error('error');
|
||||||
}).toThrow('error');
|
}).toThrow('error');
|
||||||
|
|
||||||
|
// to support: npx jest --silent
|
||||||
|
const spy = jest.spyOn(logging, 'trace');
|
||||||
|
spy.mockImplementation(() => {
|
||||||
|
throw new Error('Trace:');
|
||||||
|
});
|
||||||
expect(() => {
|
expect(() => {
|
||||||
logging.trace();
|
logging.trace();
|
||||||
}).toThrow('Trace:');
|
}).toThrow('Trace:');
|
||||||
|
spy.mockRestore();
|
||||||
});
|
});
|
||||||
it('should use noop functions when console unavailable', () => {
|
it('should use noop functions when console unavailable', () => {
|
||||||
const { console } = window;
|
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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* 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';
|
import CacheStorage from './shims/CacheStorage';
|
||||||
|
|
||||||
configure();
|
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
global.caches = new CacheStorage();
|
global.caches = new CacheStorage();
|
||||||
|
|
||||||
|
configure({ adapter: new Adapter() });
|
||||||
|
Loading…
Reference in New Issue
Block a user