-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17a2658
commit 5247a7e
Showing
7 changed files
with
158 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "ctrf", | ||
"version": "0.0.6", | ||
"version": "0.0.9", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
export async function identifyFlakyTests(filePath: string) { | ||
try { | ||
const resolvedFilePath = path.resolve(filePath); | ||
|
||
if (!fs.existsSync(resolvedFilePath)) { | ||
console.error(`The file ${resolvedFilePath} does not exist.`); | ||
return; | ||
} | ||
|
||
const fileContent = fs.readFileSync(resolvedFilePath, 'utf8'); | ||
const report = JSON.parse(fileContent); | ||
|
||
const flakyTests = report.results.tests.filter((test: any) => test.flaky === true); | ||
|
||
if (flakyTests.length > 0) { | ||
console.log(`Found ${flakyTests.length} flaky test(s):`); | ||
flakyTests.forEach((test: any) => { | ||
console.log(`- Test Name: ${test.name}, Retries: ${test.retries}`); | ||
}); | ||
} else { | ||
console.log(`No flaky tests found in ${resolvedFilePath}.`); | ||
} | ||
} catch (error) { | ||
console.error('Error identifying flaky tests:', error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
export async function mergeReports(directory: string, output: string, outputDir: string, keepReports: boolean) { | ||
try { | ||
const directoryPath = path.resolve(directory); | ||
const outputFileName = output; | ||
const resolvedOutputDir = outputDir ? path.resolve(outputDir) : directoryPath; | ||
const outputPath = path.join(resolvedOutputDir, outputFileName); | ||
|
||
console.log("Merging CTRF reports..."); | ||
|
||
const files = fs.readdirSync(directoryPath); | ||
|
||
files.forEach((file) => { | ||
console.log('Found CTRF report file:', file); | ||
}); | ||
|
||
const ctrfReportFiles = files.filter((file) => { | ||
try { | ||
const filePath = path.join(directoryPath, file); | ||
const fileContent = fs.readFileSync(filePath, 'utf8'); | ||
const jsonData = JSON.parse(fileContent); | ||
return jsonData.hasOwnProperty('results'); | ||
} catch (error) { | ||
console.error(`Error reading JSON file '${file}':`, error); | ||
return false; | ||
} | ||
}); | ||
|
||
if (ctrfReportFiles.length === 0) { | ||
console.log('No CTRF reports found in the specified directory.'); | ||
return; | ||
} | ||
|
||
if (!fs.existsSync(resolvedOutputDir)) { | ||
fs.mkdirSync(resolvedOutputDir, { recursive: true }); | ||
console.log(`Created output directory: ${resolvedOutputDir}`); | ||
} | ||
|
||
const mergedReport = ctrfReportFiles | ||
.map((file) => { | ||
console.log("Merging report:", file); | ||
const filePath = path.join(directoryPath, file); | ||
const fileContent = fs.readFileSync(filePath, 'utf8'); | ||
return JSON.parse(fileContent); | ||
}) | ||
.reduce((acc, curr) => { | ||
if (!acc.results) { | ||
return curr; | ||
} | ||
|
||
acc.results.summary.tests += curr.results.summary.tests; | ||
acc.results.summary.passed += curr.results.summary.passed; | ||
acc.results.summary.failed += curr.results.summary.failed; | ||
acc.results.summary.skipped += curr.results.summary.skipped; | ||
acc.results.summary.pending += curr.results.summary.pending; | ||
acc.results.summary.other += curr.results.summary.other; | ||
|
||
acc.results.tests.push(...curr.results.tests); | ||
|
||
acc.results.summary.start = Math.min(acc.results.summary.start, curr.results.summary.start); | ||
acc.results.summary.stop = Math.max(acc.results.summary.stop, curr.results.summary.stop); | ||
|
||
return acc; | ||
}, { results: null }); | ||
|
||
fs.writeFileSync(outputPath, JSON.stringify(mergedReport, null, 2)); | ||
|
||
if (!keepReports) { | ||
ctrfReportFiles.forEach((file) => { | ||
const filePath = path.join(directoryPath, file); | ||
if (file !== outputFileName) { | ||
fs.unlinkSync(filePath); | ||
} | ||
}); | ||
} | ||
|
||
console.log('CTRF reports merged successfully.'); | ||
console.log(`Merged report saved to: ${outputPath}`); | ||
} catch (error) { | ||
console.error('Error merging CTRF reports:', error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters