wiki:Writing testharness Tests

Writing JavaScript-based DOM only tests using testharness

When writing test cases that only test the DOM it is preferable to use an .html file since it only requires one test file instead of two.

Two JavaScript frameworks exist in the WebKit repository:

The two frameworks contain similar (but not necessarily identical) sets of functionalities for making common test assertions, using unique APIs.

When possible, testharness.js / testharnessreport.js are preferable as this framework is also available in the W3C Test repository, making tests written using this API fully portable to W3C.

Documentation on how to use testharness.js is provided in the comment section at the beginning of the file itself. testharnessreport.js customizes the output of testharness.js to make it compatible with the WebKit test infrastructure (specifically, the HTML formatting is removed and test results are output as plain text).

NOTE: When copying tests from the WebKit repository to W3C, the path to these two scripts will need to be updated. In the W3C repository the scripts are located in a resources folder at the root level, i.e.: /resources/testharness.js and /resources/testharnessreport.js

An example of js-test.js test

<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
description("Test a class selector for <a href=\"\">Bug XXXX</a>: WebKit does not apply class-selector");
jsTestIsAsync = true;

onload = ()=>
    const block = document.getElementsByClassName('block')[0];
    color = document.defaultView.getComputedStyle(block, null).getPropertyValue('color');
    shouldBeEqualToString("color", 'rgb(0, 128, 0)');

    .block { color: green; }
<p class="block"></p>
Last modified 3 years ago Last modified on Sep 6, 2020 8:11:51 PM