Closed
Bug 1364045
Opened 7 years ago
Closed 6 years ago
Switch from Karma to Jest for JS unit tests
Categories
(Tree Management :: Treeherder, enhancement, P1)
Tree Management
Treeherder
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: emorley, Assigned: camd)
References
(Blocks 1 open bug)
Details
Attachments
(5 files)
Currently it's not possible to run the JS unit tests locally since they require a browser, which isn't installed in the vagrant environment. In addition, even when I try running them outside of Vagrant (where I have Nightly installed), they still don't work.
We currently use karma/jasmine and what seems to be a bit of a hacky config to make the existing setup work with Neutrino.
I guess we could either use PhantomJS by default instead of Firefox.
Or alternatively perhaps we could switch to Mocha and just run the unit tests with node instead? (We now have the end-to-end Selenium tests in a browser, so perhaps don't need to use Karma for testing against a real browser)
Eli, do you have any suggestions? I don't know that much about the latest JS testing best practices :-)
Flags: needinfo?(eperelman)
Reporter | ||
Comment 1•7 years ago
|
||
If we end up switching to Mocha and using the stock Neutrino preset, I'm presuming it will also fix several of these too:
* Bug 1364030 - Travis JS job is green even though the log shows tests are failing
* Bug 1364037 - The JS unit tests log output associates all failures with 'tests/ui/unit/init.js' rather than the real test file
* Bug 1364040 - The JS unit tests log output displays the error for failing tests multiple times
Comment 3•7 years ago
|
||
Karma: Use this option if you need to run tests in the browser, and need to run tests against certain functionality that consumes some browser-specific APIs that may not be available in a simulated environment.
Mocha/Tape/AVA: I typically reserve this option for testing Node.js only. It's possible to use these for browser testing, but it's usually easier to use Jest.
Jest: Good for running tests against React (and other) projects, but this still runs in Node.js. If you want to run unit tests, or test your React components themselves, this is a good option. Be aware that even though you have a simulated browser environment, not all APIs may be available here. Stick with testing things here that are somewhat platform agnostic or are properly mocked, which usually isn't that big of a deal.
Flags: needinfo?(eperelman)
Reporter | ||
Updated•6 years ago
|
See Also: → https://bugzilla.mozilla.org/show_bug.cgi?id=1364037,
https://bugzilla.mozilla.org/show_bug.cgi?id=1364040
Summary: Make it easier to run the JS unit tests locally → Switch from Karma to Jest for JS unit tests
Reporter | ||
Comment 4•6 years ago
|
||
As part of switching it is probably worth seeing whether we should continue using enzyme (), or whether we should also switch to:
https://github.com/kentcdodds/react-testing-library
More details about it here:
https://blog.kentcdodds.com/introducing-the-react-testing-library-e3a274307e65
Blocks: treeherder-react
Depends on: 1364894
Reporter | ||
Comment 5•6 years ago
|
||
Cameron, did the experiment in getting this set up with the Neutrino Jest preset work out ok in the end? :-)
Assignee | ||
Comment 6•6 years ago
|
||
Assignee: nobody → cdawson
Assignee | ||
Comment 7•6 years ago
|
||
Jest testing is now activated, but not all tests have been converted yet. Keeping this open till we do that and get rid of Karma.
Comment 8•6 years ago
|
||
Comment 9•6 years ago
|
||
Commit pushed to master at https://github.com/mozilla/treeherder
https://github.com/mozilla/treeherder/commit/5c2602fd626e829e6d0f5e4ecdabe2d901d55bf5
Bug 1364045 - Don't load '@neutrinojs/jest' in production (#4381)
Since it's in `devDependencies` so is not installed during deploys.
Fixes:
`Error: Cannot find module '@neutrinojs/jest'`
https://dashboard.heroku.com/apps/treeherder-stage/activity/builds/8228fa8d-0209-43d3-8699-4e6c124b248f
Reporter | ||
Comment 10•6 years ago
|
||
I think we should prioritise this, so that it unblocks the adding of new Perfherder unit tests as parts of Perfherder are converted over to React.
Priority: P2 → P1
Comment 11•6 years ago
|
||
Comment 12•6 years ago
|
||
Commit pushed to master at https://github.com/mozilla/treeherder
https://github.com/mozilla/treeherder/commit/646e716a6af4fc962b312a04784629e38b19980d
Bug 1364045 - Convert the revisions unit tests to Jest (#4495)
Comment 13•6 years ago
|
||
Reporter | ||
Updated•6 years ago
|
Status: NEW → ASSIGNED
Reporter | ||
Comment 14•6 years ago
|
||
The groups unit tests converted in:
https://github.com/mozilla/treeherder/commit/9498ac526a398e4fe226bd3eb20e569bc0264638
Comment 15•6 years ago
|
||
Reporter | ||
Comment 16•6 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Updated•3 years ago
|
Component: Treeherder: Docs & Development → TreeHerder
You need to log in
before you can comment on or make changes to this bug.
Description
•