diff --git a/helpers/ExerciceHelper.ts b/helpers/ExerciceHelper.ts index c6ff93b4ebaef25f03892ee78ac8ffbfc0d49dc9..190a9bc88fcbefae6d3f8e390140430b37bc8105 100644 --- a/helpers/ExerciceHelper.ts +++ b/helpers/ExerciceHelper.ts @@ -5,9 +5,7 @@ import JSON5 from 'json5'; class ExerciceHelper { - validateResultFile(resultsFilePath: string): { - results: ExerciceResultsFile | undefined, isValid: boolean, errors: Array<ErrorObject<string, Record<string, any>, unknown> | string> | null | undefined - } { + validateResultFile(resultsFilePathOrStr: string, isFile: boolean = true): { results: ExerciceResultsFile | undefined, isValid: boolean, errors: Array<ErrorObject<string, Record<string, any>, unknown> | string> | null | undefined } { const ajv = new Ajv(); const schema: JTDSchemaType<ExerciceResultsFile> = { @@ -35,7 +33,7 @@ class ExerciceHelper { const validator = ajv.compile(schema); try { - const results = JSON5.parse(fs.readFileSync(resultsFilePath, 'utf8')); + const results = JSON5.parse(isFile ? fs.readFileSync(resultsFilePathOrStr, 'utf8') : resultsFilePathOrStr); const isValid = validator(results); return {