Skip to content

Commit

Permalink
style: reduce duplicated code in test-helper
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Kott <[email protected]>
  • Loading branch information
janbiasi and boostvolt committed Feb 24, 2024
1 parent b174fe3 commit ebe3dc9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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);

Expand Down

0 comments on commit ebe3dc9

Please sign in to comment.