mirror of
https://github.com/apache/superset.git
synced 2026-04-22 01:24:43 +00:00
[refactor] Migrate from Mocha+Chai to Jest (#6079)
* [refactor] Migrate from Mocha+Chai to Jest This change migrates all the existing unit tests - to Jest's global expect and matchers from chai's imported expect, asserts and matchers. - to Jest's describe/test from mocha's describe/it The majority of the mechanical changes to tests are achieved through running jest-codemods. The only two note-worthy manual tweaks: 1. Setting a testURL of http://localhost in jest config and adjusting a few tests to leverage this value instead of relying on about:blank. 2. Re-enabling ExploreChartPanel_spec which was previously commented out as we cannot have empty tests with nothing in it with Jest. :) This change also removes dependencies to Mocha and Chai. * Remove the test:one command as it now does the same thing as test. * Fixing lint errors. The diff looks large but is large done through `yarn run lint --fix` The only noteworthy change is the one in eslintrc for tests. The env has been updated from mocha to jest. * Adding eslint-plugin-jest and further modify tests. - One small fix in sqllab's Timer Spec for a test that is not using the spy it created for testing. - Deletion of a duplicated test caught by eslint-plugin-jest. * - Make istanbul coverage work with Jest. - Remove dependency on stand-alone istanbul and babel-istanbul as they're built-into jest. Yes! * Attempt to fix dynamic imports in tests. * run sequentially and log heap usage * - tweaking maxworkers for travis and specifying coverageDirectory for codecov - remove dynamic import in shim.js now that it is set in babelrc for tests only.
This commit is contained in:
committed by
Chris Williams
parent
46c86672c8
commit
9029701f24
@@ -3,7 +3,6 @@ import configureStore from 'redux-mock-store';
|
||||
import thunk from 'redux-thunk';
|
||||
|
||||
import { shallow } from 'enzyme';
|
||||
import { expect } from 'chai';
|
||||
import sinon from 'sinon';
|
||||
|
||||
import $ from 'jquery';
|
||||
@@ -65,13 +64,13 @@ describe('ExploreResultsButton', () => {
|
||||
}).dive());
|
||||
|
||||
it('renders', () => {
|
||||
expect(React.isValidElement(<ExploreResultsButton />)).to.equal(true);
|
||||
expect(React.isValidElement(<ExploreResultsButton />)).toBe(true);
|
||||
});
|
||||
|
||||
it('renders with props', () => {
|
||||
expect(
|
||||
React.isValidElement(<ExploreResultsButton {...mockedProps} />),
|
||||
).to.equal(true);
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('detects bad columns', () => {
|
||||
@@ -82,15 +81,15 @@ describe('ExploreResultsButton', () => {
|
||||
});
|
||||
|
||||
const badCols = wrapper.instance().getInvalidColumns();
|
||||
expect(badCols).to.deep.equal(['COUNT(*)', '1', '123', 'CASE WHEN 1=1 THEN 1 ELSE 0 END']);
|
||||
expect(badCols).toEqual(['COUNT(*)', '1', '123', 'CASE WHEN 1=1 THEN 1 ELSE 0 END']);
|
||||
|
||||
const msgWrapper = shallow(wrapper.instance().renderInvalidColumnMessage());
|
||||
expect(msgWrapper.find('div')).to.have.length(1);
|
||||
expect(msgWrapper.find('div')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('renders a Button', () => {
|
||||
const wrapper = getExploreResultsButtonWrapper();
|
||||
expect(wrapper.find(Button)).to.have.length(1);
|
||||
expect(wrapper.find(Button)).toHaveLength(1);
|
||||
});
|
||||
|
||||
describe('datasourceName', () => {
|
||||
@@ -107,19 +106,19 @@ describe('ExploreResultsButton', () => {
|
||||
it('should generate data source name from query', () => {
|
||||
const sampleQuery = queries[0];
|
||||
const name = wrapper.instance().datasourceName();
|
||||
expect(name).to.equal(`${sampleQuery.user}-${sampleQuery.tab}-abcd`);
|
||||
expect(name).toBe(`${sampleQuery.user}-${sampleQuery.tab}-abcd`);
|
||||
});
|
||||
it('should generate data source name with empty query', () => {
|
||||
wrapper.setProps({ query: {} });
|
||||
const name = wrapper.instance().datasourceName();
|
||||
expect(name).to.equal('undefined-abcd');
|
||||
expect(name).toBe('undefined-abcd');
|
||||
});
|
||||
|
||||
it('should build viz options', () => {
|
||||
wrapper.setState({ chartType: mockChartTypeTB });
|
||||
const spy = sinon.spy(wrapper.instance(), 'buildVizOptions');
|
||||
wrapper.instance().buildVizOptions();
|
||||
expect(spy.returnValues[0]).to.deep.equal({
|
||||
expect(spy.returnValues[0]).toEqual({
|
||||
schema: 'test_schema',
|
||||
sql: wrapper.instance().props.query.sql,
|
||||
dbId: wrapper.instance().props.query.dbId,
|
||||
@@ -141,7 +140,7 @@ describe('ExploreResultsButton', () => {
|
||||
context: { store },
|
||||
}).dive();
|
||||
const inst = longQueryWrapper.instance();
|
||||
expect(inst.getQueryDuration()).to.equal(100.7050400390625);
|
||||
expect(inst.getQueryDuration()).toBe(100.7050400390625);
|
||||
});
|
||||
|
||||
describe('visualize', () => {
|
||||
@@ -173,12 +172,12 @@ describe('ExploreResultsButton', () => {
|
||||
|
||||
it('should build request', () => {
|
||||
wrapper.instance().visualize();
|
||||
expect(ajaxSpy.callCount).to.equal(1);
|
||||
expect(ajaxSpy.callCount).toBe(1);
|
||||
|
||||
const spyCall = ajaxSpy.getCall(0);
|
||||
expect(spyCall.args[0].type).to.equal('POST');
|
||||
expect(spyCall.args[0].url).to.equal('/superset/sqllab_viz/');
|
||||
expect(spyCall.args[0].data.data).to.equal(JSON.stringify(mockOptions));
|
||||
expect(spyCall.args[0].type).toBe('POST');
|
||||
expect(spyCall.args[0].url).toBe('/superset/sqllab_viz/');
|
||||
expect(spyCall.args[0].data.data).toBe(JSON.stringify(mockOptions));
|
||||
});
|
||||
it('should open new window', () => {
|
||||
const infoToastSpy = sinon.spy();
|
||||
@@ -197,9 +196,9 @@ describe('ExploreResultsButton', () => {
|
||||
});
|
||||
|
||||
wrapper.instance().visualize();
|
||||
expect(exploreUtils.exportChart.callCount).to.equal(1);
|
||||
expect(exploreUtils.exportChart.getCall(0).args[0].datasource).to.equal('107__table');
|
||||
expect(infoToastSpy.callCount).to.equal(1);
|
||||
expect(exploreUtils.exportChart.callCount).toBe(1);
|
||||
expect(exploreUtils.exportChart.getCall(0).args[0].datasource).toBe('107__table');
|
||||
expect(infoToastSpy.callCount).toBe(1);
|
||||
});
|
||||
it('should add error toast', () => {
|
||||
const dangerToastSpy = sinon.spy();
|
||||
@@ -219,8 +218,8 @@ describe('ExploreResultsButton', () => {
|
||||
});
|
||||
|
||||
wrapper.instance().visualize();
|
||||
expect(exploreUtils.exportChart.callCount).to.equal(0);
|
||||
expect(dangerToastSpy.callCount).to.equal(1);
|
||||
expect(exploreUtils.exportChart.callCount).toBe(0);
|
||||
expect(dangerToastSpy.callCount).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user