mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:27:45 +00:00
LibJS: Add a function to ensure calls are made within the same second
Before these tests could be flaky if they happened to be called around the edge of a second. Now we try up to 5 times to execute the tests while staying within the same second.
This commit is contained in:
parent
146d45a652
commit
cf0d30add6
3 changed files with 41 additions and 12 deletions
|
@ -35,12 +35,12 @@ describe("correct behavior", () => {
|
|||
},
|
||||
};
|
||||
|
||||
const plainDateTime = Temporal.Now.plainDateTimeISO("UTC");
|
||||
const plainDateTimeWithOffset = Temporal.Now.plainDateTimeISO(timeZone);
|
||||
const [plainDateTime, plainDateTimeWithOffset] = withinSameSecond(() => {
|
||||
return [Temporal.Now.plainDateTimeISO("UTC"), Temporal.Now.plainDateTimeISO(timeZone)];
|
||||
});
|
||||
|
||||
if (plainDateTime.year !== plainDateTimeWithOffset.year) return;
|
||||
|
||||
// Let's hope the duration between the above two lines is less than a second :^)
|
||||
const differenceSeconds =
|
||||
plainDateTimeToEpochSeconds(plainDateTimeWithOffset) -
|
||||
plainDateTimeToEpochSeconds(plainDateTime);
|
||||
|
@ -55,12 +55,12 @@ describe("correct behavior", () => {
|
|||
},
|
||||
};
|
||||
|
||||
const plainDateTime = Temporal.Now.plainDateTimeISO("UTC");
|
||||
const plainDateTimeWithOffset = Temporal.Now.plainDateTimeISO(timeZone);
|
||||
const [plainDateTime, plainDateTimeWithOffset] = withinSameSecond(() => {
|
||||
return [Temporal.Now.plainDateTimeISO("UTC"), Temporal.Now.plainDateTimeISO(timeZone)];
|
||||
});
|
||||
|
||||
if (plainDateTime.year !== plainDateTimeWithOffset.year) return;
|
||||
|
||||
// Let's hope the duration between the above two lines is less than a second :^)
|
||||
const differenceSeconds =
|
||||
plainDateTimeToEpochSeconds(plainDateTimeWithOffset) -
|
||||
plainDateTimeToEpochSeconds(plainDateTime);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue