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.mjs in xpcshell tests.

  • EventUtils - This is always available in mochitests.

  • BrowserTestUtils - This is always available in mochitests.

  • SimpleTest.promiseFocus and also SimpleTest.requestCompleteLog for debugging.

  • SpecialPowers - especially pushPrefEnv in mochitests and SpecialPowers.MockColorPicker.

  • MockFilePicker - resource://testing-common/MockFilePicker.sys.mjs

  • MockRegistrar - resource://testing-common/MockRegistrar.sys.mjs; replace an XPCOM component for a test.

  • HttpServer

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.mjs

  • 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.

  • MailTestUtils - resource://testing-common/mailnews/MailTestUtils.sys.mjs

  • OAuth2TestUtils - resource://testing-common/mailnews/OAuth2TestUtils.sys.mjs

  • MockExternalProtocolService - resource://testing-common/mailnews/MockExternalProtocolService.sys.mjs; intercept opening protocols that aren’t handled internally.

  • MockAlertsService - resource://testing-common/mailnews/MockAlertsService.sys.mjs