Revision control

Copy as Markdown

Other Tools

# Test Helpers
There are a lot of utilities for writing JavaScript tests. This document wants
to highlight those you should use in new tests.
## From Firefox
- [TestUtils](https://firefox-source-docs.mozilla.org/testing/testutils.html) - This is always available in mochitests, but needs to be explicitly imported from `resource://testing-common/TestUtils.sys.mjs` in xpcshell tests.
- [EventUtils](https://firefox-source-docs.mozilla.org/testing/eventutils.html) - This is always available in mochitests.
- [BrowserTestUtils](https://firefox-source-docs.mozilla.org/testing/browser-chrome/browsertestutils.html) - This is always available in mochitests.
- [SpecialPowers](https://searchfox.org/firefox-main/source/testing/specialpowers/content/SpecialPowersParent.sys.mjs) - especially `pushPrefEnv` in mochitests and `SpecialPowers.MockColorPicker`.
## Thunderbird Specific
All of these need to be imported in tests when needed. None of these have links,
since there's no documentation apart from usage examples in existing tests and
the implementation itself.
- ServerTestUtils - `resource://testing-common/mailnews/ServerTestUtils.sys.mjs`; of course sometimes you also just want one of the individual servers this uses.
- NetworkTestUtils - `resource://testing-common/mailnews/NetworkTestUtils.sys.mjs`; add a redirect at any domain to a local test server.
- HttpsServer - `resource://testing-common/mailnews/HttpsProxy.sys.mjs`; add an HTTPS proxy in front of a local test server.
- PromiseTestUtils - `resource://testing-common/mailnews/PromiseTestUtils.sys.mjs`; converts some common transactions to a promise.
- MockExternalProtocolService - `resource://testing-common/mailnews/MockExternalProtocolService.sys.mjs`; intercept opening protocols that aren't handled internally.