-
Notifications
You must be signed in to change notification settings - Fork 289
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
Change testing framework from Mocha to Jest #719
Conversation
Wiz Scan Summary
|
@@ -18,7 +18,7 @@ jobs: | |||
# run this job for every combination of given matrix variables | |||
strategy: | |||
matrix: | |||
node-version: [12.x, 14.x, 16.x] |
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.
12 is pretty old. Kicked it out, and included 18 and 20 in its place.
@@ -1,8 +1,7 @@ | |||
/** | |||
* Copyright Schrodinger, LLC | |||
*/ | |||
import { assert } from 'chai'; |
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.
assertions are included in jest's expect
@@ -1,8 +1,7 @@ | |||
/** | |||
* Copyright Schrodinger, LLC | |||
*/ | |||
import { assert } from 'chai'; | |||
import sinon from '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.
mocks/spies are included in jest
@@ -33,7 +46,7 @@ describe('FixedDataTableRoot', function () { | |||
renderer.render(table); | |||
let tableRender = renderer.getRenderOutput(); | |||
|
|||
assert.isTrue(isElement(tableRender)); | |||
expect(isElement(tableRender)).toBe(true); |
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.
Here and elsewhere: assert()
calls are replaced with expect()
calls
renderTable({ scrollLeft: undefined }); | ||
}); | ||
}).not.toThrow(); |
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.
expect(...).not
lets you negate the expectations
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.
Removed cause it doesn't work and also cause it relies on mocha-loader
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.
This file isn't needed anymore because we have jest-environment-jsdom
, which setups a DOM environment for our tests.
what is this wiz scan summary |
assert.equal( | ||
table.getTableState().scrollX, | ||
300, | ||
'should set scrollX to 300' |
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.
no way to pass this parameter?
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.
Ah good catch.
Unfortunately there doesn't seem to be a clean and simple enough native way in JEST to do this.
There's some workarounds in https://stackoverflow.com/a/68332874, like wrapping the individual checks inside another it
like it("should set scrollX to 300")
, or to use the https://github.com/mattphillips/jest-expect-message package.
But they all seem like an overkill at this point.
We can look into this in a separate PR if anyone reports they're missing the custom error messages.
lgtm |
Released with v2.0.9. |
Description
I'm replacing Mocha with Jest.
Motivation and Context
Jest vs Mocha
Jest already comes packed with assertions, stubs, mocks, and snapshot testing features.
I'm planning to add some snapshot testing later, and maintaining two testing frameworks seem like a pain.
With Mocha, we also had to add Chai and Sinon to the stack.
Morever, it doesn't support snapshot testing out of the box.
Security vulnerabilities
I also had trouble fixing security issues cause of
mocha-webpack
andmocha-loader
, cause they haven't released newer versions in a while.We've also been using a beta version of
mocha-webpack
which doesn't work with newer versions of mocha...And I don't think anyones been using these cause they appear broken since forever...
A bonus is that the following vulnerability should now be resolved since
mocha
will be removed.Extra changes
I've bumped up the node versions in our CI workflow from [12, 14, 16] to [14, 16, 18, 20].
Node v12 reached EoL on 2022, and v14 reach EoL last year.
How Has This Been Tested?
Ran
yarn run test
and verified all tests pass.Types of changes
Checklist: