Automatic update from web-platform-tests Don't set test fail status in web-extensions-helper.js. (#61149) web-extension-helper.js was overriding the test status to just `test.FAIL`, leaving out the test message. This causes a test failure to look like: `FAIL message: Undefined.UNDEFINED` since the message and stack are `undefined`. `test.set_status(status, message, stack);` is already being handled by testharness.js in the `step()` method (see line 2878) so we can just rely on that. -- wpt-commits: f4bc67f44b7cfe06d8d829e5a97a39eef7660b91 wpt-pr: 61149
63 lines
1.8 KiB
JavaScript
63 lines
1.8 KiB
JavaScript
// testharness file with WebExtensions utilities
|
|
|
|
/**
|
|
* Loads the WebExtension at the path specified and runs the tests defined in the extension's resources.
|
|
* Listens to messages sent from the user agent and converts the `browser.test` assertions
|
|
* into testharness.js assertions.
|
|
*
|
|
* @param {string} extensionPath - a path to the extension's resources.
|
|
*/
|
|
|
|
setup({ explicit_done: true })
|
|
globalThis.runTestsWithWebExtension = function(extensionPath) {
|
|
let test;
|
|
let installPromise;
|
|
|
|
function onTestStartedListener(data) {
|
|
test = async_test(data.testName);
|
|
}
|
|
|
|
function onTestFinishedListener(data) {
|
|
test.step(() => {
|
|
let description = data.message ?
|
|
`${data.assertionDescription}. ${data.message}` :
|
|
data.assertionDescription;
|
|
assert_true(data.result, description);
|
|
});
|
|
|
|
test.done();
|
|
|
|
if (data.remainingTests) {
|
|
return;
|
|
}
|
|
|
|
cleanupListeners();
|
|
installPromise
|
|
.then((extension_id) => {
|
|
return test_driver.uninstall_web_extension(extension_id);
|
|
})
|
|
.then(() => {
|
|
done();
|
|
});
|
|
}
|
|
|
|
function cleanupListeners() {
|
|
browser.test.onTestStarted.removeListener(onTestStartedListener);
|
|
browser.test.onTestFinished.removeListener(onTestFinishedListener);
|
|
}
|
|
|
|
// Attach event listeners synchronously before calling `install_web_extension`
|
|
// to prevent a possible race condition for some browsers where the extension
|
|
// could install and run tests before `installPromise` resolves.
|
|
browser.test.onTestStarted.addListener(onTestStartedListener);
|
|
browser.test.onTestFinished.addListener(onTestFinishedListener);
|
|
|
|
installPromise =
|
|
test_driver.install_web_extension({type: 'path', path: extensionPath});
|
|
|
|
return installPromise.catch((error) => {
|
|
cleanupListeners();
|
|
throw error;
|
|
});
|
|
}
|