-
Notifications
You must be signed in to change notification settings - Fork 13.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[refactor] Migrate from Mocha+Chai to Jest #6079
Conversation
5792b4f
to
9a62140
Compare
superset/assets/package.json
Outdated
"test:one": "mocha --require ignore-styles --compilers js:babel-core/register --require spec/helpers/shim.js", | ||
"tdd": "jest --watch", | ||
"test": "jest", | ||
"test:one": "jest", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we remove this one since it's the same as test
? I added test:one
for mocha just a couple months ago.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, we can.
@@ -19,40 +18,40 @@ describe('AddSliceContainer', () => { | |||
wrapper = shallow(<AddSliceContainer {...defaultProps} />); | |||
}); | |||
|
|||
it('uses table as default visType', () => { | |||
expect(wrapper.state().visType).to.equal('table'); | |||
test('uses table as default visType', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be useful to also add the eslint-plugin-jest
while adding jest for consistent styles from the start. for example within describe
blocks it recommends using it
over test
. (that one is auto-fixable so shouldn't be much work 😄 )
I noticed a mix in the file changes here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a quick look at eslint-plugin-jest
. I like the rules it advocates. Good suggestion!
Let me add it to this PR so we don't change it
to test
and the back to it
. 😛
@@ -46,9 +45,6 @@ global.XMLHttpRequest = global.window.XMLHttpRequest; | |||
|
|||
global.sinon = require('sinon'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a future PR I think we can actually also remove sinon
because jest
has support for spies, stubs, etc. I doubt that's code-mod-able, tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agree. I didn't do it in the same PR to limit the scope. :) Yeah, for sinon
, we need to modify things manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! thanks again for doing this, it's amazing 🙌
sorry the cypress build is broken, I introduced a flaky test, will fix now.
Looks like I have some linting errors to fix as well. :) On it. |
Ah. It seems like you have to deal with Istanbul as well. Rooting for you. This PR is gold 🥇 |
@kristw I agree we should remove
note this is compatible with our current setup for |
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.
…arn run lint --fix` The only noteworthy change is the one in eslintrc for tests. The env has been updated from mocha to jest.
- 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.
- Remove dependency on stand-alone istanbul and babel-istanbul as they're built-into jest. Yes!
88bceb1
to
3437946
Compare
@williaster That is even better. No need for |
@kristw @williaster yep, that's exactly what I did as well. |
ef155eb
to
f32b583
Compare
be6e39b
to
1df4883
Compare
Codecov Report
@@ Coverage Diff @@
## master #6079 +/- ##
=======================================
Coverage 77.56% 77.56%
=======================================
Files 47 47
Lines 9484 9484
=======================================
Hits 7356 7356
Misses 2128 2128 Continue to review full report at Codecov.
|
1df4883
to
fd7bbac
Compare
… codecov - remove dynamic import in shim.js now that it is set in babelrc for tests only.
298cc23
to
1dfe55f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
* [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 change migrates all the existing unit tests
The majority of the mechanical changes to tests are achieved through running jest-codemods. The only two note-worthy manual tweaks:
This change also removes dependencies to Mocha and Chai.
@williaster @kristw @mistercrunch @betodealmeida