[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:
Christine Chambers
2018-10-15 13:10:18 -07:00
committed by Chris Williams
parent 46c86672c8
commit 9029701f24
177 changed files with 2539 additions and 2166 deletions

View File

@@ -1,5 +1,3 @@
import { expect } from 'chai';
import layoutReducer from '../../../../src/dashboard/reducers/dashboardLayout';
import {
@@ -30,7 +28,7 @@ import {
describe('dashboardLayout reducer', () => {
it('should return initial state for unrecognized actions', () => {
expect(layoutReducer(undefined, {})).to.deep.equal({});
expect(layoutReducer(undefined, {})).toEqual({});
});
it('should delete a component, remove its reference in its parent, and recursively all of its children', () => {
@@ -60,7 +58,7 @@ describe('dashboardLayout reducer', () => {
payload: { id: 'toDelete', parentId: 'parentId' },
},
),
).to.deep.equal({
).toEqual({
parentId: {
id: 'parentId',
children: ['anotherId'],
@@ -96,7 +94,7 @@ describe('dashboardLayout reducer', () => {
payload: { id: 'toDelete', parentId: 'parentId' },
},
),
).to.deep.equal({
).toEqual({
grandparentId: {
id: 'grandparentId',
children: [],
@@ -138,7 +136,7 @@ describe('dashboardLayout reducer', () => {
},
},
),
).to.deep.equal({
).toEqual({
update: {
id: 'update',
newField: 'newField',
@@ -185,7 +183,7 @@ describe('dashboardLayout reducer', () => {
type: MOVE_COMPONENT,
payload: { dropResult },
}),
).to.deep.equal({
).toEqual({
source: {
id: 'source',
type: ROW_TYPE,
@@ -239,9 +237,9 @@ describe('dashboardLayout reducer', () => {
['source', 'destination', 'toMove'].indexOf(component.id) === -1,
);
expect(newRow.children[0]).to.equal('toMove');
expect(result.destination.children[0]).to.equal(newRow.id);
expect(Object.keys(result)).to.have.length(4);
expect(newRow.children[0]).toBe('toMove');
expect(result.destination.children[0]).toBe(newRow.id);
expect(Object.keys(result)).toHaveLength(4);
});
it('should add top-level tabs from a new tabs component, moving grid children to new tab', () => {
@@ -283,11 +281,11 @@ describe('dashboardLayout reducer', () => {
component => component.type === TABS_TYPE,
);
expect(Object.keys(result)).to.have.length(5); // initial + Tabs + Tab
expect(result[DASHBOARD_ROOT_ID].children[0]).to.equal(tabsComponent.id);
expect(result[tabsComponent.id].children[0]).to.equal(tabComponent.id);
expect(result[tabComponent.id].children[0]).to.equal('child');
expect(result[DASHBOARD_GRID_ID].children).to.have.length(0);
expect(Object.keys(result)).toHaveLength(5); // initial + Tabs + Tab
expect(result[DASHBOARD_ROOT_ID].children[0]).toBe(tabsComponent.id);
expect(result[tabsComponent.id].children[0]).toBe(tabComponent.id);
expect(result[tabComponent.id].children[0]).toBe('child');
expect(result[DASHBOARD_GRID_ID].children).toHaveLength(0);
});
it('should add top-level tabs from an existing tabs component, moving grid children to new tab', () => {
@@ -335,11 +333,11 @@ describe('dashboardLayout reducer', () => {
payload: { dropResult },
});
expect(Object.keys(result)).to.have.length(Object.keys(layout).length);
expect(result[DASHBOARD_ROOT_ID].children[0]).to.equal('tabs');
expect(result.tabs.children[0]).to.equal('tab');
expect(result.tab.children).to.deep.equal(['child', 'child2']);
expect(result[DASHBOARD_GRID_ID].children).to.have.length(0);
expect(Object.keys(result)).toHaveLength(Object.keys(layout).length);
expect(result[DASHBOARD_ROOT_ID].children[0]).toBe('tabs');
expect(result.tabs.children[0]).toBe('tab');
expect(result.tab.children).toEqual(['child', 'child2']);
expect(result[DASHBOARD_GRID_ID].children).toHaveLength(0);
});
it('should remove top-level tabs, moving children to the grid', () => {
@@ -387,7 +385,7 @@ describe('dashboardLayout reducer', () => {
payload: { dropResult },
});
expect(result).to.deep.equal({
expect(result).toEqual({
[DASHBOARD_ROOT_ID]: {
id: DASHBOARD_ROOT_ID,
children: [DASHBOARD_GRID_ID],
@@ -436,7 +434,7 @@ describe('dashboardLayout reducer', () => {
});
const newId = result[DASHBOARD_GRID_ID].children[1];
expect(result[DASHBOARD_GRID_ID].children).to.have.length(2);
expect(result[newId].type).to.equal(ROW_TYPE);
expect(result[DASHBOARD_GRID_ID].children).toHaveLength(2);
expect(result[newId].type).toBe(ROW_TYPE);
});
});