mirror of
https://github.com/by-jp/www.byjp.me.git
synced 2025-08-09 18:06:07 +01:00
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.
14 lines
418 B
JavaScript
14 lines
418 B
JavaScript
import fs from "node:fs";
|
||
import { fileURLToPath } from "node:url";
|
||
|
||
/**
|
||
* @param {string} filename - Fixture’s 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" }),
|
||
});
|
||
};
|