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)

enhancement

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)
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
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)
Blocks: 1416266
No longer blocks: 1340305
Summary: Make it easier to run the JS unit tests locally → Switch from Karma to Jest for JS unit tests
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
Depends on: 1364894
Blocks: 1503510
Cameron, did the experiment in getting this set up with the Neutrino Jest preset work out ok in the end? :-)
Attached file GitHub Pull Request (deleted) —
Assignee: nobody → cdawson
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.
Depends on: 1514720
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
Blocks: 1513527

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
No longer blocks: 1513527
Status: NEW → ASSIGNED
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Blocks: 1527237
Component: Treeherder: Docs & Development → TreeHerder
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: