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 22, 2024
1 parent e5f2777 commit d4b46ce
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions scripts/updateReadme.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ try {
testResults = require(testResultsPath);
} catch (error) {
console.error('Failed to load test results:', error);
process.exit(1); // Exit if there's no test results
process.exit(1);
}

const updateReadmeForTestResults = (results) => {
Expand All @@ -22,31 +22,35 @@ const updateReadmeForTestResults = (results) => {
return;
}

let lines = readmeContents.split('\n');
let updated = false;
const lines = readmeContents.split('\n');
const tableStartIndex = lines.findIndex(line => line.includes('<!-- START TABLE @HERE -->'));
if (tableStartIndex === -1) {
console.error('Table start marker not found in README.md.');
return;
}

// Assuming the header is the next line after the marker, and the separator is the line after the header
const headerIndex = tableStartIndex + 1;
const separatorIndex = headerIndex + 1;

// Ensure the "Passed Unit Tests?" column exists
const headerIndex = lines.findIndex(line => line.startsWith('|Logo|'));
if (headerIndex !== -1 && !lines[headerIndex].includes('Passed Unit Tests?')) {
lines[headerIndex] = lines[headerIndex].trim() + 'Passed Unit Tests?|';
lines[headerIndex + 1] = lines[headerIndex + 1].trim() + ':---:|'; // Assuming the separator line follows the header
if (!lines[headerIndex].includes('Passed Unit Tests?')) {
lines[headerIndex] = lines[headerIndex].trim() + '|Passed Unit Tests?';
lines[separatorIndex] = lines[separatorIndex].trim() + '|:---:';
}

// Update each manifest entry with test results
let updated = false;

results.testResults.forEach(test => {
const manifestName = path.basename(test.name, '.json');
const passed = test.status === "passed";
const statusIcon = passed ? '&check;' : '&cross;';

const lineIndex = lines.findIndex(line => line.includes(manifestName));
const lineIndex = lines.findIndex(line => line.includes(manifestName) && line.startsWith('|'));
if (lineIndex !== -1) {
updated = true;
let parts = lines[lineIndex].split('|');
if (parts.length - 1 < lines[headerIndex].split('|').length - 1) {
// If the current line has fewer columns than the header, add an empty column for the status
parts.splice(parts.length - 1, 0, ' ');
}
parts[parts.length - 2] = ` ${statusIcon} `; // Update or add the test result icon
parts[parts.length - 1] = ` ${statusIcon} |`; // Update or add the test result icon
lines[lineIndex] = parts.join('|');
}
});
Expand Down

0 comments on commit d4b46ce

Please sign in to comment.