From 269fb87a58c4b159c953f9b2ccaa02608dcae0ad Mon Sep 17 00:00:00 2001 From: "Jan R. Biasi" Date: Sat, 24 Feb 2024 01:31:03 +0100 Subject: [PATCH] style: reduce duplicated code in test-helper Co-authored-by: Jan Kott <51777660+boostvolt@users.noreply.github.com> --- test/helpers.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/helpers.ts b/test/helpers.ts index 94fdfa5..2b2584d 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -5,8 +5,12 @@ import Ajv from "ajv"; import addFormats from "ajv-formats"; import { XMLParser } from "fast-xml-parser"; +function readJsonFile(path: string) { + return JSON.parse(readFileSync(resolve(path), "utf-8")); +} + const bomSchemaVersions = { - "v1.5": JSON.parse(readFileSync(resolve("./test/schemas/bom-1.5.schema.json"), "utf-8")), + "v1.5": readJsonFile("./test/schemas/bom-1.5.schema.json"), }; const ajv = new Ajv({ @@ -15,9 +19,9 @@ const ajv = new Ajv({ strict: false, }); -ajv.addSchema(JSON.parse(readFileSync(resolve("./test/schemas/spdx.schema.json"), "utf-8"))); -ajv.addSchema(JSON.parse(readFileSync(resolve("./test/schemas/cyclonedx-spdx.schema.json"), "utf-8"))); -ajv.addSchema(JSON.parse(readFileSync(resolve("./test/schemas/jsf.schema.json"), "utf-8"))); +ajv.addSchema(readJsonFile("./test/schemas/spdx.schema.json")); +ajv.addSchema(readJsonFile("./test/schemas/cyclonedx-spdx.schema.json")); +ajv.addSchema(readJsonFile("./test/schemas/jsf.schema.json")); addFormats(ajv);