Skip to content

Commit 64a283b

Browse files
committed
fix: gracefully handle non ctrf file
1 parent 0cd5c33 commit 64a283b

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ctrf",
3-
"version": "0.0.9",
3+
"version": "0.0.10",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

src/merge.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,23 @@ export async function mergeReports(directory: string, output: string, outputDir:
1313
const files = fs.readdirSync(directoryPath);
1414

1515
files.forEach((file) => {
16-
console.log('Found CTRF report file:', file);
16+
console.log('Found file:', file);
1717
});
1818

1919
const ctrfReportFiles = files.filter((file) => {
2020
try {
21+
if (path.extname(file) !== '.json') {
22+
console.log(`Skipping non-CTRF file: ${file}`);
23+
return false;
24+
}
2125
const filePath = path.join(directoryPath, file);
2226
const fileContent = fs.readFileSync(filePath, 'utf8');
2327
const jsonData = JSON.parse(fileContent);
24-
return jsonData.hasOwnProperty('results');
28+
if (!jsonData.hasOwnProperty('results')) {
29+
console.log(`Skipping non-CTRF file: ${file}`);
30+
return false;
31+
}
32+
return true;
2533
} catch (error) {
2634
console.error(`Error reading JSON file '${file}':`, error);
2735
return false;

0 commit comments

Comments
 (0)