LibWeb: Add a feature to LibWeb tests to fail on unhandled exceptions
Previously, if there was an unhandled exception in an async test, it might fail to call done() and timeout. Now we have a default "error" handler to catch unhandled exceptions and fail the test. A few tests want to actually test the behavior of window.onerror, so they need an escape hatch.
This commit is contained in:
parent
1fa948f114
commit
8edaec79de
Notes:
github-actions[bot]
2024-10-05 07:19:21 +00:00
Author: https://github.com/ADKaster Commit: https://github.com/LadybirdBrowser/ladybird/commit/8edaec79dea Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1632
4 changed files with 20 additions and 0 deletions
|
@ -395,6 +395,7 @@ asyncTest
|
|||
printElement
|
||||
println
|
||||
promiseTest
|
||||
removeTestErrorHandler
|
||||
spoofCurrentURL
|
||||
test
|
||||
timeout
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
asyncTest(done => {
|
||||
|
||||
removeTestErrorHandler()
|
||||
|
||||
window.addEventListener("error", (event) => {
|
||||
println(`onerror event fired: ${event.error}`);
|
||||
done();
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
removeTestErrorHandler()
|
||||
|
||||
window.onerror = (message, filename, lineno, colno, error) => {
|
||||
println(`message = ${message}`);
|
||||
println(`lineno = ${lineno}`);
|
||||
|
|
|
@ -52,6 +52,20 @@ function timeout(ms) {
|
|||
return promise;
|
||||
}
|
||||
|
||||
const __testErrorHandlerController = new AbortController();
|
||||
window.addEventListener(
|
||||
"error",
|
||||
event => {
|
||||
println(`Uncaught Error In Test: ${event.message}`);
|
||||
__finishTest();
|
||||
},
|
||||
{ signal: __testErrorHandlerController.signal }
|
||||
);
|
||||
|
||||
function removeTestErrorHandler() {
|
||||
__testErrorHandlerController.abort();
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
__outputElement = document.createElement("pre");
|
||||
__outputElement.setAttribute("id", "out");
|
||||
|
|
Loading…
Add table
Reference in a new issue