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.
53 lines
1.8 KiB
HTML
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>
|