www.byjp.me/indiekit/helpers/fixtures/index.js
JP Hastings-Spital f90ecd1dcd [Indiekit] Add fixture helpers
I can't quite get my head around how @indiekit-test/fixtures is available to the tests in the official indiekit repo, so I've copied it here for now.
2024-10-08 12:13:23 +01:00

14 lines
418 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import fs from "node:fs";
import { fileURLToPath } from "node:url";
/**
* @param {string} filename - Fixtures file name
* @param {boolean} utf8 - Encoding fixture as UTF8
* @returns {object} File contents
*/
export const getFixture = (filename, utf8 = true) => {
const file = fileURLToPath(new URL(filename, import.meta.url));
return fs.readFileSync(file, {
...(utf8 && { encoding: "utf8" }),
});
};