use jest for testing
There are no commits yet
Push commits to the source branch or add previously merged commits to review them.
Created by: sqs
Goal: help people write reliable UI code by making it easier to write and run tests.
Using Facebook's jest for tests helps us achieve this goal because:
shared/
, web/
, and client/browser/
-- and unit tests AND e2e tests) from the same runner (yarn test
in the root dir)--watch
UI and a good vscode-jest extension
--require ts-node --require source-map-support mocha.opts --require long-stack-traces --require esm ...
, no test-time bundling required using unit-test-utils.ts
, etc.)Note: Most of the diff is from https://github.com/skovhus/jest-codemods, which automatically updates our test code to use jest style (describe
, test
, expect
, etc., not it
and assert
).
jest appears to be the most popular tool for solving the problem that we have (testing a large web/multi-platform application), and it was surprisingly painless to set up and a joy to use.
TODOs:
Usage:
This is also documented in
doc/dev/testing.md
anddoc/dev/web_app.md
.
yarn test
from the root directory.yarn test --watch
.
jest.autoEnable: true
(and, if you want, jest.showCoverageOnLoad: true
)test('name ...', ...)
definition in your test file (be sure to set a breakpoint or break on uncaught exceptions by clicking in the left gutter).cd client/browser && yarn test-e2e
cd web && yarn test-e2e
yarn test
from any of the individual project dirs (shared/
, web/
, client/browser/
).Usually while developing you will either have yarn test --watch
running in a terminal or you will use vscode-jest.
Notes:
assert
. They are very similar.test()
instead of it()
for defining test cases.
Push commits to the source branch or add previously merged commits to review them.