1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:08:10 +00:00

LibJS/Tests: Add support for expected failure (xfail) tests

To allow us to add tests that are failing now, but can be enabled as
soon as a change is made to make it pass (without any opportunity to
forget about enabling it).

Additionally, support is added for `xfailIf`, for tests that are
expected to fail given a certain condition, but are expected to pass
otherwise. This is intended to be used for tests that fail in bytecode
mode, but pass in AST (and vice versa).
This commit is contained in:
Shannon Booth 2023-07-22 16:22:47 +12:00 committed by Andreas Kling
parent cb23eaa92d
commit 2401c0ff7e

View file

@ -630,6 +630,41 @@ class ExpectationError extends Error {
};
};
test.xfail = (message, callback) => {
if (!__TestResults__[suiteMessage]) __TestResults__[suiteMessage] = {};
const suite = __TestResults__[suiteMessage];
if (Object.prototype.hasOwnProperty.call(suite, message)) {
suite[message] = {
result: "fail",
details: "Another test with the same message did already run",
duration: 0,
};
return;
}
const now = () => Temporal.Now.instant().epochNanoseconds;
const start = now();
const time_us = () => Number(BigInt.asIntN(53, (now() - start) / 1000n));
try {
callback();
suite[message] = {
result: "fail",
details: "Expected test to fail, but it passed",
duration: time_us(),
};
} catch (e) {
suite[message] = {
result: "xfail",
duration: time_us(),
};
}
};
test.xfailIf = (condition, message, callback) => {
condition ? test.xfail(message, callback) : test(message, callback);
};
withinSameSecond = callback => {
let callbackDuration;
for (let tries = 0; tries < 5; tries++) {