Import json fixtures with new helper

This commit is contained in:
2022-08-25 00:23:19 +02:00
parent 2765154c45
commit 463b48a84f
6 changed files with 52 additions and 40 deletions

View File

@@ -0,0 +1,23 @@
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
function determineLocation(fixtureFilename) {
return path.join(__dirname, "..", "fixtures", fixtureFilename);
}
export default function readFixtureContents(fixtureFilename) {
const location = determineLocation(fixtureFilename);
let content = {};
try {
content = JSON.parse(fs.readFileSync(location, { encoding: "utf-8" }));
} catch (err) {
console.error(`Error loading fixture file at path: ${location}`);
}
return content;
}