Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private readFile(fileName: string): Promise {
return fsAsPromised
.readFile(fileName)
.then((content: Buffer) => new File(fileName, content))
.then((file: File) => {
this.reportSourceFilesRead(file);
return file;
})
.catch(error => {
if (
(isErrnoException(error) && error.code === 'ENOENT') ||
error.code === 'EISDIR'
) {
return null; // file is deleted or a directory. This can be a valid result of the git command
} else {
// Rethrow
throw error;
}
private readFile(fileName: string): Promise {
return fsAsPromised
.readFile(fileName)
.then((content: Buffer) => new File(fileName, content))
.then((file: File) => {
this.reportSourceFilesRead(file);
return file;
})
.catch(error => {
if ((isErrnoException(error) && error.code === 'ENOENT') || error.code === 'EISDIR') {
return null; // file is deleted or a directory. This can be a valid result of the git command
} else {
// Rethrow
throw error;
}
});
}
}
export async function readMutationTestResult(eventResultDirectory = path.resolve('reports', 'mutation', 'events')) {
const allReportFiles = await fsAsPromised.readdir(eventResultDirectory);
const mutationTestReportFile = allReportFiles.find(file => !!file.match(/.*onMutationTestReportReady.*/));
expect(mutationTestReportFile).ok;
const mutationTestReportContent = await fsAsPromised.readFile(path.resolve(eventResultDirectory, mutationTestReportFile || ''), 'utf8');
const report = JSON.parse(mutationTestReportContent) as mutationTestReportSchema.MutationTestResult;
const metricsResult = calculateMetrics(report.files);
return metricsResult;
}