21 lines
764 B
JavaScript
21 lines
764 B
JavaScript
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { tmpdir } from "node:os";
|
|
import { describe, expect, it } from "vitest";
|
|
import { readJsonFile, stripUtf8Bom } from "./helpers/readJsonFile";
|
|
|
|
describe("readJsonFile helper", () => {
|
|
it("strips UTF-8 BOM prefixes before parsing JSON", () => {
|
|
const baseDir = mkdtempSync(join(tmpdir(), "read-json-file-"));
|
|
const fixturePath = join(baseDir, "locale.json");
|
|
|
|
try {
|
|
writeFileSync(fixturePath, '\uFEFF{"label":"Hej"}', "utf8");
|
|
expect(readJsonFile(fixturePath)).toEqual({ label: "Hej" });
|
|
expect(stripUtf8Bom("\uFEFFsample")).toBe("sample");
|
|
} finally {
|
|
rmSync(baseDir, { recursive: true, force: true });
|
|
}
|
|
});
|
|
});
|