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 - This is always available in mochitests, but needs to be explicitly imported from
resource://testing-common/TestUtils.sys.mjsin xpcshell tests.EventUtils - This is always available in mochitests.
BrowserTestUtils - This is always available in mochitests.
SimpleTest.promiseFocus and also
SimpleTest.requestCompleteLogfor debugging.SpecialPowers - especially
pushPrefEnvin mochitests andSpecialPowers.MockColorPicker.MockFilePicker -
resource://testing-common/MockFilePicker.sys.mjsMockRegistrar -
resource://testing-common/MockRegistrar.sys.mjs; replace an XPCOM component for a test.
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.
CalendarTestUtils -
resource://testing-common/calendar/CalendarTestUtils.sys.mjsServerTestUtils -
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.MailTestUtils -
resource://testing-common/mailnews/MailTestUtils.sys.mjsOAuth2TestUtils -
resource://testing-common/mailnews/OAuth2TestUtils.sys.mjsMockExternalProtocolService -
resource://testing-common/mailnews/MockExternalProtocolService.sys.mjs; intercept opening protocols that aren’t handled internally.MockAlertsService -
resource://testing-common/mailnews/MockAlertsService.sys.mjs