1# Console Tests
2
3The console panel uses currently two different frameworks for tests:
4
5- Mochitest - [Mochitest](https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Mochitest) is an automated testing framework built on top of the MochiKit JavaScript libraries. It's just one of the automated regression testing frameworks used by Mozilla.
6
7Mochitests are located in `devtools/client/webconsole/test/browser/` and can be run with the following command:
8
9```sh
10./mach test devtools/client/webconsole/test/browser/
11```
12
13These tests can be run on CI when pushing to TRY. Not all tests are enabled at the moment since they were copied over from the old frontend (See Bug 1400847).
14
15- Mocha + Enzyme - [mocha](https://mochajs.org/) Mocha is JavaScript test framework running on Node.js
16  [Enzyme](http://airbnb.io/enzyme/) is a JavaScript Testing utility for React that makes it easier to assert, manipulate, and traverse your React Components' output.
17
18These tests are located in `tests/node/`, and can be run with the following command:
19
20```sh
21cd devtools/client/webconsole/test/node && npm install && npm test
22```
23
24or using yarn with
25
26```sh
27cd devtools/client/webconsole/test/node && yarn && yarn test
28```
29
30---
31
32The team is leaning towards Enzyme since it's well known and suitable for React.
33It's also easier to contribute to tests written on top of Enzyme.
34
35# Stubs
36
37Many tests depends on fix data structures (aka stubs) that mimic
38<abbr title="Remote Debugging Protocol">RDP<abbr> packets that represents Console logs.
39Stubs are stored in `test/fixtures` directory and you might automatically generate them.
40
41## Append new stubs
42
43- Append new entry into the `getCommands` function return value in on of the `\tests\browser\browser_webconsole_stubs_*.js`
44  and run the generator using `mach` command, with the `WEBCONSOLE_STUBS_UPDATE=true` environment variable.
45
46For console API stubs, you can do:
47
48`./mach test devtools/client/webconsole/test/browser/browser_webconsole_stubs_console_api.js --headless --setenv WEBCONSOLE_STUBS_UPDATE=true`
49
50This will override `tests/node/fixtures/stubs/consoleApi.js`.
51
52The same can be done in:
53
54- `browser_webconsole_stubs_css_message.js` (writes to `tests/node/fixtures/stubs/cssMessage.js`)
55- `browser_webconsole_stubs_evaluation_result.js` (writes to `tests/node/fixtures/stubs/evaluationResult.js`)
56- `browser_webconsole_stubs_network_event.js` (writes to `tests/node/fixtures/stubs/networkEvent.js`)
57- `browser_webconsole_stubs_page_error.js` (writes to `tests/node/fixtures/stubs/pageError.js`)
58
59If you made some changes that impact all stubs, you can update all at once using:
60
61`./mach test devtools/client/webconsole/test/browser/browser_webconsole_stubs --headless --setenv WEBCONSOLE_STUBS_UPDATE=true`
62