util node tests: Prevent Intl.ListFormat leaks.

These never happen in practice since util is near the
end of the alphabet, but if you had run the tests in
reverse order, you would have seen this leak.

This leak was introduced in the efb2a5a38d commit.
This commit is contained in:
Steve Howell 2025-01-07 01:40:50 +00:00 committed by Tim Abbott
parent b87d64cd8a
commit 8583e64037

View File

@ -5,7 +5,7 @@ const assert = require("node:assert/strict");
const _ = require("lodash");
const MockDate = require("mockdate");
const {set_global, zrequire} = require("./lib/namespace.cjs");
const {set_global, with_overrides, zrequire} = require("./lib/namespace.cjs");
const {run_test} = require("./lib/test.cjs");
const blueslip = zrequire("blueslip");
@ -369,12 +369,17 @@ run_test("format_array_as_list", () => {
);
// when Intl.ListFormat does not exist
global.Intl.ListFormat = undefined;
assert.equal(util.format_array_as_list(array, "long", "conjunction"), "apple, banana, orange");
assert.equal(
util.format_array_as_list_with_highlighted_elements(array, "long", "conjunction"),
"<b>apple</b>, <b>banana</b>, <b>orange</b>",
);
with_overrides(({override}) => {
override(global.Intl, "ListFormat", undefined);
assert.equal(
util.format_array_as_list(array, "long", "conjunction"),
"apple, banana, orange",
);
assert.equal(
util.format_array_as_list_with_highlighted_elements(array, "long", "conjunction"),
"<b>apple</b>, <b>banana</b>, <b>orange</b>",
);
});
});
run_test("get_remaining_time", () => {