wpt: use a custom testharness report

This commit is contained in:
Pierre Tachoire
2023-10-10 16:24:00 +02:00
parent 5240870596
commit 8ae6a254c0

View File

@@ -1,57 +1,34 @@
/* global add_completion_callback */
/* global setup */
/*
* This file is intended for vendors to implement code needed to integrate
* testharness.js tests with their own test systems.
*
* Typically test system integration will attach callbacks when each test has
* run, using add_result_callback(callback(test)), or when the whole test file
* has completed, using
* add_completion_callback(callback(tests, harness_status)).
*
* For more documentation about the callback functions and the
* parameters they are called with see testharness.js
* Prepare a report object containeing all tests results.
* https://wpt-docs.readthedocs.io/en/latest/_writing-tests/testharness-api.html#callback-api
*/
var report = {
status: "",
log: "",
};
function dump_test_results(tests, status) {
var results_element = document.createElement("script");
results_element.type = "text/json";
results_element.id = "__testharness__results__";
var test_results = tests.map(function(x) {
return {name:x.name, status:x.status, message:x.message, stack:x.stack}
});
var data = {test:window.location.href,
tests:test_results,
status: status.status,
message: status.message,
stack: status.stack};
results_element.textContent = JSON.stringify(data);
add_completion_callback(function (tests, status) {
// report the tests global status.
// TODO the status.status is always OK even if a test fail.
// I ingore the global status for now, but I build one with the tests results.
//report.status = status.status;
// To avoid a HierarchyRequestError with XML documents, ensure that 'results_element'
// is inserted at a location that results in a valid document.
var parent = document.body
? document.body // <body> is required in XHTML documents
: document.documentElement; // fallback for optional <body> in HTML5, SVG, etc.
parent.appendChild(results_element);
}
add_completion_callback(dump_test_results);
/* If the parent window has a testharness_properties object,
* we use this to provide the test settings. This is used by the
* default in-browser runner to configure the timeout and the
* rendering of results
*/
try {
if (window.opener && "testharness_properties" in window.opener) {
/* If we pass the testharness_properties object as-is here without
* JSON stringifying and reparsing it, IE fails & emits the message
* "Could not complete the operation due to error 80700019".
*/
setup(JSON.parse(JSON.stringify(window.opener.testharness_properties)));
var status = "Pass";
// report a log with details per test.
var log = "";
for (var i = 0; i < tests.length; i++) {
const test = tests[i];
log += test.name+": "+test.format_status();
if (test.message != null) {
log += " " + test.message;
}
} catch (e) {
}
// vim: set expandtab shiftwidth=4 tabstop=4:
log += "\n";
if (test.status !== 0) {
status = test.format_status();
}
}
report.log = log;
report.status = status;
});