1# DevTools node tests
2
3In addition to mochitests and xpcshell tests, some panels in DevTools are using node test libraries to run unit tests. For instance, several panels are using [Jest](https://jestjs.io/) to run React component unit tests.
4
5## Find the node tests on Try
6
7The DevTools node tests are split in two different test suites on try:
8- `node(devtools)`: all the DevTools node tests, except the ones for the debugger
9- `node(debugger)`: only the Debugger node tests
10
11They are running on the `Linux 64 opt` platform. They are both tier 1 jobs, which means that any failure will lead to a backout.
12
13## Run Tests On Try
14
15To run the DevTools node tests on try, you can use `./mach try fuzzy` and look for the jobs named `source-test-node-debugger-tests` and `source-test-node-devtools-tests`.
16
17They are also run when using the "devtools" preset: `./mach try --preset devtools`.
18
19### Node tests try job definition
20
21The definition of those try jobs can be found at [taskcluster/ci/source-test/node.yml](https://searchfox.org/mozilla-central/source/taskcluster/ci/source-test/node.yml).
22
23The definition also contains the list of files that will trigger the node test jobs. Currently the debugger tests run when any file is modified under `devtools/client/debugger`, the devtools tests run when any file is modified under `devtools/client` or `devtools/shared`.
24
25## Run Tests Locally
26
27### Prerequisite: yarn
28
29You will need yarn to be installed in order to run both the debugger and the DevTools tests. See [https://yarnpkg.com/getting-started](https://yarnpkg.com/getting-started).
30
31### Debugger
32
33To run the debugger node tests:
34```
35> cd devtools/client/debugger/
36> yarn && node bin/try-runner.js
37```
38
39Note that the debugger is running other tasks than just unit tests: `flow`, `eslint`, `stylelint` etc...
40Using `yarn && yarn test` would only run the Jest tests, while `node bin/try-runner` will run the same tests and scripts as the ones used on try.
41
42### DevTools
43
44To run the other (non-debugger) DevTools tests, the easiest is to rely on the same script as the one used to run the tests on try:
45```
46> node devtools/client/bin/devtools-node-test-runner.js --suite={suitename}
47```
48
49At the moment of writing, the supported suites for this script are:
50- `aboutdebugging`
51- `accessibility`
52- `application`
53- `compatibility`
54- `framework`
55- `netmonitor`
56- `performance`
57- `shared_components`
58- `webconsole`
59
60(You can see the full list and the associated configuration in devtools/client/bin/devtools-node-test-runner.js)
61
62Alternatively, you can also locate the `package.json` corresponding to a given suite, and run `yarn && yarn test`.
63
64## Updating snapshots
65
66Some of the node tests are snapshot tests, which means they compare the output of a given component to a previous text snapshot. They might break if you are legitimately modifying a component and it means the snapshots need to be updated.
67
68A snapshot failure will show up as follows:
69```
70› 1 snapshot failed from 1 test suite
71```
72
73It should also mention the command you can run to update the snapshots:
74```
75Inspect your code changes or run `yarn run test-ci -u` to update them.
76```
77
78For example, if you need to update snapshots in a specific panel, first locate the package.json corresponding to the node test folder of the panel. In theory it should be under `devtools/client/{panelname}/test/node/` but it might be slightly different depending on each panel. Then run `yarn run test-ci -u` in this folder and add the snapshot changes to your commit.
79
80## TypeScript
81
82The "performance" suite performs TypeScript checks. The TypeScript usage in the performance panel is documented at [devtools/client/performance-new/typescript.md](https://searchfox.org/mozilla-central/source/devtools/client/performance-new/typescript.md) ([see rendered version on GitHub](https://github.com/mozilla/gecko-dev/blob/master/devtools/client/performance-new/typescript.md)).
83