[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,4 +1,3 @@
import { expect } from 'chai';
import sinon from 'sinon';
import { ActionCreators as UndoActionCreators } from 'redux-undo';
@@ -67,8 +66,8 @@ describe('dashboardLayout actions', () => {
const nextComponents = { 1: {} };
const thunk = updateComponents(nextComponents);
thunk(dispatch, getState);
expect(dispatch.callCount).to.equal(1);
expect(dispatch.getCall(0).args[0]).to.deep.equal({
expect(dispatch.callCount).toBe(1);
expect(dispatch.getCall(0).args[0]).toEqual({
type: UPDATE_COMPONENTS,
payload: { nextComponents },
});
@@ -81,10 +80,8 @@ describe('dashboardLayout actions', () => {
const nextComponents = { 1: {} };
const thunk = updateComponents(nextComponents);
thunk(dispatch, getState);
expect(dispatch.callCount).to.equal(2);
expect(dispatch.getCall(1).args[0]).to.deep.equal(
setUnsavedChanges(true),
);
expect(dispatch.callCount).toBe(2);
expect(dispatch.getCall(1).args[0]).toEqual(setUnsavedChanges(true));
});
});
@@ -93,8 +90,8 @@ describe('dashboardLayout actions', () => {
const { getState, dispatch } = setup();
const thunk = deleteComponent('id', 'parentId');
thunk(dispatch, getState);
expect(dispatch.callCount).to.equal(1);
expect(dispatch.getCall(0).args[0]).to.deep.equal({
expect(dispatch.callCount).toBe(1);
expect(dispatch.getCall(0).args[0]).toEqual({
type: DELETE_COMPONENT,
payload: { id: 'id', parentId: 'parentId' },
});
@@ -106,10 +103,8 @@ describe('dashboardLayout actions', () => {
});
const thunk = deleteComponent('id', 'parentId');
thunk(dispatch, getState);
expect(dispatch.callCount).to.equal(2);
expect(dispatch.getCall(1).args[0]).to.deep.equal(
setUnsavedChanges(true),
);
expect(dispatch.callCount).toBe(2);
expect(dispatch.getCall(1).args[0]).toEqual(setUnsavedChanges(true));
});
});
@@ -122,7 +117,7 @@ describe('dashboardLayout actions', () => {
const thunk2 = dispatch.getCall(0).args[0];
thunk2(dispatch, getState);
expect(dispatch.getCall(1).args[0]).to.deep.equal({
expect(dispatch.getCall(1).args[0]).toEqual({
type: UPDATE_COMPONENTS,
payload: {
nextComponents: {
@@ -133,7 +128,7 @@ describe('dashboardLayout actions', () => {
},
});
expect(dispatch.callCount).to.equal(2);
expect(dispatch.callCount).toBe(2);
});
});
@@ -143,8 +138,8 @@ describe('dashboardLayout actions', () => {
const dropResult = {};
const thunk = createTopLevelTabs(dropResult);
thunk(dispatch, getState);
expect(dispatch.callCount).to.equal(1);
expect(dispatch.getCall(0).args[0]).to.deep.equal({
expect(dispatch.callCount).toBe(1);
expect(dispatch.getCall(0).args[0]).toEqual({
type: CREATE_TOP_LEVEL_TABS,
payload: { dropResult },
});
@@ -157,10 +152,8 @@ describe('dashboardLayout actions', () => {
const dropResult = {};
const thunk = createTopLevelTabs(dropResult);
thunk(dispatch, getState);
expect(dispatch.callCount).to.equal(2);
expect(dispatch.getCall(1).args[0]).to.deep.equal(
setUnsavedChanges(true),
);
expect(dispatch.callCount).toBe(2);
expect(dispatch.getCall(1).args[0]).toEqual(setUnsavedChanges(true));
});
});
@@ -170,8 +163,8 @@ describe('dashboardLayout actions', () => {
const dropResult = {};
const thunk = deleteTopLevelTabs(dropResult);
thunk(dispatch, getState);
expect(dispatch.callCount).to.equal(1);
expect(dispatch.getCall(0).args[0]).to.deep.equal({
expect(dispatch.callCount).toBe(1);
expect(dispatch.getCall(0).args[0]).toEqual({
type: DELETE_TOP_LEVEL_TABS,
payload: {},
});
@@ -184,10 +177,8 @@ describe('dashboardLayout actions', () => {
const dropResult = {};
const thunk = deleteTopLevelTabs(dropResult);
thunk(dispatch, getState);
expect(dispatch.callCount).to.equal(2);
expect(dispatch.getCall(1).args[0]).to.deep.equal(
setUnsavedChanges(true),
);
expect(dispatch.callCount).toBe(2);
expect(dispatch.getCall(1).args[0]).toEqual(setUnsavedChanges(true));
});
});
@@ -217,8 +208,8 @@ describe('dashboardLayout actions', () => {
const thunk2 = dispatch.getCall(0).args[0];
thunk2(dispatch, getState);
expect(dispatch.callCount).to.equal(2);
expect(dispatch.getCall(1).args[0]).to.deep.equal({
expect(dispatch.callCount).toBe(2);
expect(dispatch.getCall(1).args[0]).toEqual({
type: UPDATE_COMPONENTS,
payload: {
nextComponents: {
@@ -234,7 +225,7 @@ describe('dashboardLayout actions', () => {
},
});
expect(dispatch.callCount).to.equal(2);
expect(dispatch.callCount).toBe(2);
});
it('should dispatch a setUnsavedChanges action if hasUnsavedChanges=false', () => {
@@ -248,7 +239,7 @@ describe('dashboardLayout actions', () => {
const thunk2 = dispatch.getCall(0).args[0];
thunk2(dispatch, getState);
expect(dispatch.callCount).to.equal(3);
expect(dispatch.callCount).toBe(3);
});
});
@@ -267,14 +258,14 @@ describe('dashboardLayout actions', () => {
const createComponentThunk = dispatch.getCall(0).args[0];
createComponentThunk(dispatch, getState);
expect(dispatch.getCall(1).args[0]).to.deep.equal({
expect(dispatch.getCall(1).args[0]).toEqual({
type: CREATE_COMPONENT,
payload: {
dropResult,
},
});
expect(dispatch.callCount).to.equal(2);
expect(dispatch.callCount).toBe(2);
});
it('should move a component if the component is not new', () => {
@@ -296,14 +287,14 @@ describe('dashboardLayout actions', () => {
const moveComponentThunk = dispatch.getCall(0).args[0];
moveComponentThunk(dispatch, getState);
expect(dispatch.getCall(1).args[0]).to.deep.equal({
expect(dispatch.getCall(1).args[0]).toEqual({
type: MOVE_COMPONENT,
payload: {
dropResult,
},
});
expect(dispatch.callCount).to.equal(2);
expect(dispatch.callCount).toBe(2);
});
it('should dispatch a toast if the drop overflows the destination', () => {
@@ -325,11 +316,9 @@ describe('dashboardLayout actions', () => {
const thunk = handleComponentDrop(dropResult);
thunk(dispatch, getState);
expect(dispatch.getCall(0).args[0].type).to.deep.equal(
addInfoToast('').type,
);
expect(dispatch.getCall(0).args[0].type).toEqual(addInfoToast('').type);
expect(dispatch.callCount).to.equal(1);
expect(dispatch.callCount).toBe(1);
});
it('should delete a parent Row or Tabs if the moved child was the only child', () => {
@@ -360,7 +349,7 @@ describe('dashboardLayout actions', () => {
const deleteThunk = dispatch.getCall(1).args[0];
deleteThunk(dispatch, getState);
expect(dispatch.getCall(2).args[0]).to.deep.equal({
expect(dispatch.getCall(2).args[0]).toEqual({
type: DELETE_COMPONENT,
payload: {
id: 'tabsId',
@@ -369,7 +358,7 @@ describe('dashboardLayout actions', () => {
});
// move thunk, delete thunk, delete result actions
expect(dispatch.callCount).to.equal(3);
expect(dispatch.callCount).toBe(3);
});
it('should create top-level tabs if dropped on root', () => {
@@ -386,14 +375,14 @@ describe('dashboardLayout actions', () => {
const thunk2 = dispatch.getCall(0).args[0];
thunk2(dispatch, getState);
expect(dispatch.getCall(1).args[0]).to.deep.equal({
expect(dispatch.getCall(1).args[0]).toEqual({
type: CREATE_TOP_LEVEL_TABS,
payload: {
dropResult,
},
});
expect(dispatch.callCount).to.equal(2);
expect(dispatch.callCount).toBe(2);
});
});
@@ -405,10 +394,8 @@ describe('dashboardLayout actions', () => {
const thunk = undoLayoutAction();
thunk(dispatch, getState);
expect(dispatch.callCount).to.equal(1);
expect(dispatch.getCall(0).args[0]).to.deep.equal(
UndoActionCreators.undo(),
);
expect(dispatch.callCount).toBe(1);
expect(dispatch.getCall(0).args[0]).toEqual(UndoActionCreators.undo());
});
it('should dispatch a setUnsavedChanges(false) action history length is zero', () => {
@@ -418,10 +405,8 @@ describe('dashboardLayout actions', () => {
const thunk = undoLayoutAction();
thunk(dispatch, getState);
expect(dispatch.callCount).to.equal(2);
expect(dispatch.getCall(1).args[0]).to.deep.equal(
setUnsavedChanges(false),
);
expect(dispatch.callCount).toBe(2);
expect(dispatch.getCall(1).args[0]).toEqual(setUnsavedChanges(false));
});
});
@@ -431,10 +416,8 @@ describe('dashboardLayout actions', () => {
const thunk = redoLayoutAction();
thunk(dispatch, getState);
expect(dispatch.callCount).to.equal(1);
expect(dispatch.getCall(0).args[0]).to.deep.equal(
UndoActionCreators.redo(),
);
expect(dispatch.callCount).toBe(1);
expect(dispatch.getCall(0).args[0]).toEqual(UndoActionCreators.redo());
});
it('should dispatch a setUnsavedChanges(true) action if hasUnsavedChanges=false', () => {
@@ -444,10 +427,8 @@ describe('dashboardLayout actions', () => {
const thunk = redoLayoutAction();
thunk(dispatch, getState);
expect(dispatch.callCount).to.equal(2);
expect(dispatch.getCall(1).args[0]).to.deep.equal(
setUnsavedChanges(true),
);
expect(dispatch.callCount).toBe(2);
expect(dispatch.getCall(1).args[0]).toEqual(setUnsavedChanges(true));
});
});
});