diff --git a/src/reports/Reporter.ts b/src/reports/Reporter.ts index 2a30847..135f353 100644 --- a/src/reports/Reporter.ts +++ b/src/reports/Reporter.ts @@ -147,7 +147,9 @@ export class Reporter { private generateDeviceReport(baseData: any, device: Device, userId: number) { let cucumberFile = `${Constants.REPORT_PATH}/${this.testScenario.executionId}/${device.id}/${Constants.FILE_REPORT_NAME}`; - let features = JSON.parse(FileHelper.instance().contentOfFile(cucumberFile)); + var fileContent = FileHelper.instance().contentOfFile(cucumberFile); + if (fileContent === "") fileContent = "[]"; + let features = JSON.parse(fileContent); let data = { apk_path: null, features: features, @@ -210,6 +212,7 @@ export class Reporter { } let fileContent = FileHelper.instance().contentOfFile(deviceReportFilePath); + if (fileContent === "") fileContent = "[]"; devicesReport[device.user] = JSON.parse(fileContent); devicesReport[device.user].forEach((entry: any) => { if (entry.device_model == null || entry.device_model == undefined) { diff --git a/src/utils/FileHelper.ts b/src/utils/FileHelper.ts index 3f50e61..31aec75 100644 --- a/src/utils/FileHelper.ts +++ b/src/utils/FileHelper.ts @@ -69,9 +69,10 @@ export class FileHelper { } } - createFileIfDoesNotExist(path: string) { - if (!fs.existsSync(path)) { - fs.openSync(path, 'w'); + createFileIfDoesNotExist(filePath: string) { + if (!fs.existsSync(filePath)) { + this.createFolderIfDoesNotExist(path.dirname(filePath)); + fs.openSync(filePath, 'w'); } }