diff --git a/scripts/updateReadme.js b/scripts/updateReadme.js index 6587ef8..38eef29 100644 --- a/scripts/updateReadme.js +++ b/scripts/updateReadme.js @@ -18,45 +18,42 @@ try { console.error(`Error reading README.md from ${readmePath}:`, error); process.exit(1); } - let lines = readmeContents.split('\n'); -// Normalize file name for comparison -const normalizeFileName = (fileName) => { - return fileName.toLowerCase().replace(/_/g, '-').replace('.json', ''); -}; - -// Initialize counters -let updatedRowsCount = 0; -let passedCount = 0; -let failedCount = 0; - const updateReadme = () => { - console.log(`Processing ${data.numTotalTestSuites} test suites with ${data.numTotalTests} total tests.`); + let manifestResults = {}; + // Aggregate test results by manifest file data.testResults.forEach(testSuite => { - // Extract and normalize the manifest file name from the ancestorTitles - if (testSuite.assertionResults.length > 0) { - const manifestFileName = normalizeFileName(testSuite.assertionResults[0].ancestorTitles[1]); - const allPassed = testSuite.assertionResults.every(result => result.status === "passed"); - const statusIcon = allPassed ? '✓' : '✗'; - - const rowToUpdateIndex = lines.findIndex(line => line.toLowerCase().includes(manifestFileName)); - if (rowToUpdateIndex !== -1) { - let parts = lines[rowToUpdateIndex].split('|'); - parts[parts.length - 2] = ` ${statusIcon} `; - lines[rowToUpdateIndex] = parts.join('|'); - updatedRowsCount++; - allPassed ? passedCount++ : failedCount++; - } else { - console.log(`Could not find row for ${manifestFileName} in README.md.`); + testSuite.assertionResults.forEach(result => { + const manifestFilename = result.ancestorTitles[1]; // Assuming the manifest filename is always the second value + if (!manifestResults[manifestFilename]) { + manifestResults[manifestFilename] = { passed: true, failedTests: [] }; + } + if (result.status !== "passed") { + manifestResults[manifestFilename].passed = false; + manifestResults[manifestFilename].failedTests.push(result.fullName); } + }); + }); + + // Update README.md based on aggregated results + Object.keys(manifestResults).forEach(manifestFilename => { + const statusIcon = manifestResults[manifestFilename].passed ? '✓' : '✗'; + const rowToUpdateIndex = lines.findIndex(line => line.includes(manifestFilename)); + + if (rowToUpdateIndex !== -1) { + let parts = lines[rowToUpdateIndex].split('|'); + parts[parts.length - 2] = ` ${statusIcon} `; + lines[rowToUpdateIndex] = parts.join('|'); + } else { + console.log(`Could not find row for ${manifestFilename} in README.md.`); } }); try { fs.writeFileSync(readmePath, lines.join('\n')); - console.log(`README.md has been successfully updated. Rows updated: ${updatedRowsCount} (Passed: ${passedCount}, Failed: ${failedCount})`); + console.log('README.md has been successfully updated.'); } catch (error) { console.error('Error writing updates to README.md:', error); }