mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +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
@@ -1,6 +1,5 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import { expect } from 'chai';
|
||||
|
||||
import DragDroppable from '../../../../../../src/dashboard/components/dnd/DragDroppable';
|
||||
import DraggableNewComponent from '../../../../../../src/dashboard/components/gridComponents/new/DraggableNewComponent';
|
||||
@@ -33,13 +32,13 @@ describe('DraggableNewComponent', () => {
|
||||
|
||||
it('should render a DragDroppable', () => {
|
||||
const wrapper = setup();
|
||||
expect(wrapper.find(DragDroppable)).to.have.length(1);
|
||||
expect(wrapper.find(DragDroppable)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should pass component={ type, id } to DragDroppable', () => {
|
||||
const wrapper = setup();
|
||||
const dragdroppable = wrapper.find(DragDroppable);
|
||||
expect(dragdroppable.prop('component')).to.deep.equal({
|
||||
expect(dragdroppable.prop('component')).toEqual({
|
||||
id: props.id,
|
||||
type: props.type,
|
||||
});
|
||||
@@ -48,7 +47,7 @@ describe('DraggableNewComponent', () => {
|
||||
it('should pass appropriate parent source and id to DragDroppable', () => {
|
||||
const wrapper = setup();
|
||||
const dragdroppable = wrapper.find(DragDroppable);
|
||||
expect(dragdroppable.prop('parentComponent')).to.deep.equal({
|
||||
expect(dragdroppable.prop('parentComponent')).toEqual({
|
||||
id: NEW_COMPONENTS_SOURCE_ID,
|
||||
type: NEW_COMPONENT_SOURCE_TYPE,
|
||||
});
|
||||
@@ -56,12 +55,12 @@ describe('DraggableNewComponent', () => {
|
||||
|
||||
it('should render the passed label', () => {
|
||||
const wrapper = setup();
|
||||
expect(wrapper.find('.new-component').text()).to.equal(props.label);
|
||||
expect(wrapper.find('.new-component').text()).toBe(props.label);
|
||||
});
|
||||
|
||||
it('should add the passed className', () => {
|
||||
const wrapper = setup();
|
||||
const className = `.new-component-placeholder.${props.className}`;
|
||||
expect(wrapper.find(className)).to.have.length(1);
|
||||
expect(wrapper.find(className)).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { expect } from 'chai';
|
||||
|
||||
import DraggableNewComponent from '../../../../../../src/dashboard/components/gridComponents/new/DraggableNewComponent';
|
||||
import NewColumn from '../../../../../../src/dashboard/components/gridComponents/new/NewColumn';
|
||||
@@ -15,12 +14,12 @@ describe('NewColumn', () => {
|
||||
|
||||
it('should render a DraggableNewComponent', () => {
|
||||
const wrapper = setup();
|
||||
expect(wrapper.find(DraggableNewComponent)).to.have.length(1);
|
||||
expect(wrapper.find(DraggableNewComponent)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should set appropriate type and id', () => {
|
||||
const wrapper = setup();
|
||||
expect(wrapper.find(DraggableNewComponent).props()).to.include({
|
||||
expect(wrapper.find(DraggableNewComponent).props()).toMatchObject({
|
||||
type: COLUMN_TYPE,
|
||||
id: NEW_COLUMN_ID,
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { expect } from 'chai';
|
||||
|
||||
import DraggableNewComponent from '../../../../../../src/dashboard/components/gridComponents/new/DraggableNewComponent';
|
||||
import NewDivider from '../../../../../../src/dashboard/components/gridComponents/new/NewDivider';
|
||||
@@ -15,12 +14,12 @@ describe('NewDivider', () => {
|
||||
|
||||
it('should render a DraggableNewComponent', () => {
|
||||
const wrapper = setup();
|
||||
expect(wrapper.find(DraggableNewComponent)).to.have.length(1);
|
||||
expect(wrapper.find(DraggableNewComponent)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should set appropriate type and id', () => {
|
||||
const wrapper = setup();
|
||||
expect(wrapper.find(DraggableNewComponent).props()).to.include({
|
||||
expect(wrapper.find(DraggableNewComponent).props()).toMatchObject({
|
||||
type: DIVIDER_TYPE,
|
||||
id: NEW_DIVIDER_ID,
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { expect } from 'chai';
|
||||
|
||||
import DraggableNewComponent from '../../../../../../src/dashboard/components/gridComponents/new/DraggableNewComponent';
|
||||
import NewHeader from '../../../../../../src/dashboard/components/gridComponents/new/NewHeader';
|
||||
@@ -15,12 +14,12 @@ describe('NewHeader', () => {
|
||||
|
||||
it('should render a DraggableNewComponent', () => {
|
||||
const wrapper = setup();
|
||||
expect(wrapper.find(DraggableNewComponent)).to.have.length(1);
|
||||
expect(wrapper.find(DraggableNewComponent)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should set appropriate type and id', () => {
|
||||
const wrapper = setup();
|
||||
expect(wrapper.find(DraggableNewComponent).props()).to.include({
|
||||
expect(wrapper.find(DraggableNewComponent).props()).toMatchObject({
|
||||
type: HEADER_TYPE,
|
||||
id: NEW_HEADER_ID,
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { expect } from 'chai';
|
||||
|
||||
import DraggableNewComponent from '../../../../../../src/dashboard/components/gridComponents/new/DraggableNewComponent';
|
||||
import NewRow from '../../../../../../src/dashboard/components/gridComponents/new/NewRow';
|
||||
@@ -15,12 +14,12 @@ describe('NewRow', () => {
|
||||
|
||||
it('should render a DraggableNewComponent', () => {
|
||||
const wrapper = setup();
|
||||
expect(wrapper.find(DraggableNewComponent)).to.have.length(1);
|
||||
expect(wrapper.find(DraggableNewComponent)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should set appropriate type and id', () => {
|
||||
const wrapper = setup();
|
||||
expect(wrapper.find(DraggableNewComponent).props()).to.include({
|
||||
expect(wrapper.find(DraggableNewComponent).props()).toMatchObject({
|
||||
type: ROW_TYPE,
|
||||
id: NEW_ROW_ID,
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { expect } from 'chai';
|
||||
|
||||
import DraggableNewComponent from '../../../../../../src/dashboard/components/gridComponents/new/DraggableNewComponent';
|
||||
import NewTabs from '../../../../../../src/dashboard/components/gridComponents/new/NewTabs';
|
||||
@@ -15,12 +14,12 @@ describe('NewTabs', () => {
|
||||
|
||||
it('should render a DraggableNewComponent', () => {
|
||||
const wrapper = setup();
|
||||
expect(wrapper.find(DraggableNewComponent)).to.have.length(1);
|
||||
expect(wrapper.find(DraggableNewComponent)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should set appropriate type and id', () => {
|
||||
const wrapper = setup();
|
||||
expect(wrapper.find(DraggableNewComponent).props()).to.include({
|
||||
expect(wrapper.find(DraggableNewComponent).props()).toMatchObject({
|
||||
type: TABS_TYPE,
|
||||
id: NEW_TABS_ID,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user