Skip to content
Snippets Groups Projects
Commit 99c20f92 authored by michael.minelli's avatar michael.minelli
Browse files

ExerciceHelper => Add possibility to pass file or string to result file validation

parent 7238f906
No related branches found
No related tags found
No related merge requests found
...@@ -5,9 +5,7 @@ import JSON5 from 'json5'; ...@@ -5,9 +5,7 @@ import JSON5 from 'json5';
class ExerciceHelper { class ExerciceHelper {
validateResultFile(resultsFilePath: string): { validateResultFile(resultsFilePathOrStr: string, isFile: boolean = true): { results: ExerciceResultsFile | undefined, isValid: boolean, errors: Array<ErrorObject<string, Record<string, any>, unknown> | string> | null | undefined } {
results: ExerciceResultsFile | undefined, isValid: boolean, errors: Array<ErrorObject<string, Record<string, any>, unknown> | string> | null | undefined
} {
const ajv = new Ajv(); const ajv = new Ajv();
const schema: JTDSchemaType<ExerciceResultsFile> = { const schema: JTDSchemaType<ExerciceResultsFile> = {
...@@ -35,7 +33,7 @@ class ExerciceHelper { ...@@ -35,7 +33,7 @@ class ExerciceHelper {
const validator = ajv.compile(schema); const validator = ajv.compile(schema);
try { try {
const results = JSON5.parse(fs.readFileSync(resultsFilePath, 'utf8')); const results = JSON5.parse(isFile ? fs.readFileSync(resultsFilePathOrStr, 'utf8') : resultsFilePathOrStr);
const isValid = validator(results); const isValid = validator(results);
return { return {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment