ladybird/Tests/LibWeb/Text/input/error-stack-must-contain-full-url.html
Sam Atkins 7c8d1806c9 Tests: Ensure error-stack-must-contain-full-url prints output in order
Store the error traces on a map until they're all done, then sort them
and print them out in alphabetical order by type. This test was
sometimes flaking and printing the module stack before the classic
stack, which this prevents.
2026-05-13 11:02:40 +01:00

53 lines
1.8 KiB
HTML

<!DOCTYPE html>
<script src="include.js"></script>
<div id="script-container"></div>
<script>
asyncTest(async (done) => {
const scriptContainer = document.getElementById("script-container");
globalThis.errors = new Map();
const createScript = (type) => {
return new Promise((resolve) => {
const scriptSource = `
try {
throw Error();
} catch (e) {
const uuidRegex = /[a-zA-Z0-9]+-[a-zA-Z0-9]+-[a-zA-Z0-9]+-[a-zA-Z0-9]+-[a-zA-Z0-9]+/g;
const normalizedStack = e.stack
.replace(uuidRegex, "[flaky-uuid-replaced]")
.replace(/blob:(file:\\/\\/\\/|ladybird\\/)/g, "blob:<origin>/");
globalThis.errors.set("${type}", normalizedStack);
}
`;
const scriptBlob = new Blob([scriptSource], { type: "text/javascript" });
const scriptBlobUrl = URL.createObjectURL(scriptBlob);
const script = document.createElement("script");
script.onload = () => {
resolve();
};
script.src = scriptBlobUrl;
if (type !== "classic")
script.type = type;
scriptContainer.appendChild(script);
});
};
const scriptPromises = [
createScript("classic"),
createScript("module"),
];
await Promise.all(scriptPromises);
const sortedErrors = new Map([...globalThis.errors.entries()].sort());
for (const [type, normalizedStack] of sortedErrors) {
globalThis.println(`${type}: ${normalizedStack}`);
}
done();
});
</script>