tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

CodingConventions.md (3306B)


For [Resource Timing][1] tests, we want to have a consistent and clear coding style. The goals of this style are to:

Lots of the following rules are arbitrary but the value is realized in consistency instead of adhering to the 'perfect' style.

We want the test suite to be navigable. Developers should be able to easily find the file or test that is relevant to their work.

test

* <title> for controlling labels in results pages * <link rel="help"> to point at the relevant piece of the spec

We want the test suite to run consistently. Flaky tests are counterproductive.

* Note that there’s [still potential for some concurrency][2]; use add_cleanup() if needed

We want the tests to be readable. Tests should be written in a modern style with recurring patterns.

* prefer ` const func1 = param1 => { body(); } const func2 = (param1, param2) => { body(); } fn(param => { body(); }); `

over

` function func1(param1) { body(); } function func2(param1, param2) { body(); } fn(function(param) { body(); }); `

* E.g. prefer use of get-host-info.sub.js to {{host}} or {{ports[0]}} expressions

overhead between test content and test intent * Helper .js files are still encouraged where it makes sense but we want to avoid a testing framework that is specific to Resource Timing (or web performance APIs, in general).

iframes instead of hand-rolled postMessage approaches

but throw exceptions explicitly when the test itself is broken. * A failed assert indicates "the implementation doesn't conform to the spec" * Other uncaught exceptions indicate "the test case itself has a bug"

should be as simple as calling the tests with new parameters, rather than copying an existing test and modifying it.

[1]: https://www.w3.org/TR/resource-timing-2/ [2]: https://web-platform-tests.org/writing-tests/testharness-api.html#promise-tests [3]: https://web-platform-tests.org/writing-tests/testharness-api.html#consolidating-tests-from-other-documents [4]: https://web-platform-tests.org/writing-tests/testharness-api.html#list-of-assertions