For Resource Timing tests, we want to have a consistent and clear coding style. The goals of this style are to:
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.
<title>
for controlling labels in results pages<link rel="help">
to point at the relevant piece of the specWe want the test suite to run consistently. Flaky tests are counterproductive.
promise_test
to async_test
add_cleanup()
if neededWe want the tests to be readable. Tests should be written in a modern style with recurring patterns.
80 character line limits where we can
Consistent use of anonymous functions
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(); });
Prefer const
(or, if needed, let
) to var
Contain use of ‘.sub’ in filenames to known helper utilities where possible
{{host}}
or {{ports[0]}}
expressionsAvoid use of webperftestharness[extension].js as it’s a layer of cognitive overhead between test content and test intent
Prefer fetch_tests_from_window
to collect test results from embedded iframes instead of hand-rolled postMessage
approaches
Use the assert_*
family of functions to check conformance to the spec but throw exceptions explicitly when the test itself is broken.
Where possible, we want tests to be scalable - adding another test case should be as simple as calling the tests with new parameters, rather than copying an existing test and modifying it.