Skip to content

Commit

Permalink
fix: gracefully handle non ctrf file
Browse files Browse the repository at this point in the history
  • Loading branch information
Ma11hewThomas committed Sep 5, 2024
1 parent 0cd5c33 commit 64a283b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ctrf",
"version": "0.0.9",
"version": "0.0.10",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 10 additions & 2 deletions src/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,23 @@ export async function mergeReports(directory: string, output: string, outputDir:
const files = fs.readdirSync(directoryPath);

files.forEach((file) => {
console.log('Found CTRF report file:', file);
console.log('Found file:', file);
});

const ctrfReportFiles = files.filter((file) => {
try {
if (path.extname(file) !== '.json') {
console.log(`Skipping non-CTRF file: ${file}`);
return false;
}
const filePath = path.join(directoryPath, file);
const fileContent = fs.readFileSync(filePath, 'utf8');
const jsonData = JSON.parse(fileContent);
return jsonData.hasOwnProperty('results');
if (!jsonData.hasOwnProperty('results')) {
console.log(`Skipping non-CTRF file: ${file}`);
return false;
}
return true;
} catch (error) {
console.error(`Error reading JSON file '${file}':`, error);
return false;
Expand Down

0 comments on commit 64a283b

Please sign in to comment.