You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mercury-parser/scripts/get-test-report.js

58 lines
1.0 KiB
JavaScript

const fs = require('fs');
const getTestReport = path => {
try {
const testReport = JSON.parse(fs.readFileSync(path));
const { numFailedTests } = testReport;
if (numFailedTests === 0) {
return false;
}
const { testResults } = testReport;
const failedTests = testResults
.map(({ assertionResults }) =>
assertionResults.filter(({ status }) => status !== 'passed')
)
.reduce((acc, arr) => acc.concat(arr));
const failureReport = `
<details>
<summary>
<b>${numFailedTests} failed tests 😱</b>
</summary>
---
${failedTests
.map(
({ fullName, failureMessages }) =>
`
**${fullName}**
<details>
<summary>
See what went wrong
</summary>
\`\`\`bash
${failureMessages.join('\n\n')}
\`\`\`
</details>
---
`
)
.join('\n\n')}
</details>
`;
return failureReport;
} catch (e) {
// eslint-disable-next-line no-console
console.log('Error generating test report', e);
return false;
}
};
module.exports = getTestReport;