Skip to content

Commit

Permalink
Update updateReadme.js
Browse files Browse the repository at this point in the history
  • Loading branch information
izzoa authored Mar 24, 2024
1 parent 87c68e4 commit 337280b
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions scripts/updateReadme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 337280b

Please sign in to comment.