You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/mochitests.md
+50-6
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,8 @@
8
8
9
9
We use [mochitests] to do integration testing. Mochitests are part of Firefox and allow us to test the debugger literally as you would use it (as a devtools panel).
10
10
11
+
Mochitests are different from Jest, Mocha, Selenium, because we have access to firefox internals and run inside the browser toolbox. This makes it possible to write tests as if we're a user interacting with the debugger natively :)
12
+
11
13

12
14
13
15
### Getting Started
@@ -17,7 +19,6 @@ We use [mochitests] to do integration testing. Mochitests are part of Firefox an
@@ -39,8 +40,9 @@ reflected in the new firefox directory.
39
40
40
41
`mochi` passes its params along to `mochitest`, so you can include `--jsdebugger` and test globs
41
42
42
-
*`yarn mochi -- --jsdebugger` opens a browser toolbox
43
-
*`yarn mochi browser_dbg-editor-highlight` runs just one test
43
+
*`yarn mochi dbg-editor-highlight` runs just one test
44
+
*`yarn mochid dbg-editor-highlight` opens a browser toolbox
45
+
*`yarn mochih dbg-editor-highlight` runs the test headlessly
44
46
45
47
## Writing Tests
46
48
@@ -50,17 +52,60 @@ Here are a few tips for writing mochitests:
50
52
* Try to write async user actions that involve a user action like clicking a button or typing a key press followed by a redux action to listen for. For example, the user step in action involves the user clicking the step in button followed by the "stepIn" action firing.
51
53
* The `dbg` object has several helpful properties (actions, selectors, getState, store, toolbox, win)
52
54
55
+
### Logging
56
+
57
+
The mochitests run in a special environment, which make `console.log` a little different than usual.
58
+
`console.log` inside the test will print to the terminal. `console.log` in the debugger source, will be redirected to the browser console and will not be outputed. This is why we recommend using the special firefox `dump` call which is available everywhere.
59
+
60
+
If you want a convenience method for logging in the test, `log` is a bit cleaner than `dump`.
61
+
62
+
```js
63
+
console.log(">>> YO")
64
+
log("FOO", { t:3 })
65
+
dump(">> FOOO\n");
66
+
```
67
+
68
+
69
+
### Pausing the test
70
+
71
+
There are two ways to pause the tests and see what is going on.
72
+
73
+
The first is to add a `debugger` statement to the test and run `yarn mochid {test_name}` (ex: `dbg-sources`). Here you'll have to click a modal when the test opens. When the test pauses, the browser toolbox will show your test with the `dbg` object you can interact with.
74
+
75
+
The other way is to add `await waitForever()` to your test. This stops the test and gives you a chance to interact with the debugger as the user would. Both ways of pausing are useful for different use cases!
76
+
77
+
### Waiting in a test
78
+
79
+
It's really common to want to wait for something to happen in a test. Generally we wait for one of two things to happen:
80
+
81
+
* waiting for the Redux state to change
82
+
* waiting for an action to be dispatched
83
+
84
+
```js
85
+
awaitwaitForState(dbg, state=>isPaused(state));
86
+
awaitwaitForDispatch(dbg, "STEP_OVER";)
87
+
```
88
+
53
89
### Testing the DOM
54
90
55
91
You can find common elements in the debugger with the `findElement` function,
56
92
which use shared selectors. You can also find any element with the
@@ -94,9 +139,8 @@ We recommend prefixing your logs and formatting them so they are easy to scan e.
94
139
*`info(">> Current breakpoints ${breakpoints.map(bp => bp.location.line).join(", ")}\n")`
95
140
*`info(">> Symbols for source ${source.url} ${JSON.stringify(symbols)}\n")`
96
141
97
-
At some point, it can be nice to pause the test and debug it. We are working on a debugger after all :)
98
-
Mochitest, makes it easy to pause the test at `debugger` statements with the `--jsdebugger` flag.
99
-
You can run the test like this `yarn mochid browser_dbg-editor-highlight`.
142
+
At some point, it can be nice to pause the test and debug it. Mochitest makes it easy to pause the test at `debugger` statements with the `--jsdebugger` flag.
143
+
You can run the test with `yarn mochid {test_name}` (ex: `browser_dbg-editor-highlight`).
0 commit comments