chore: set up ciftr for failed test reports (#343)
parent
262dda94b3
commit
bafa764000
@ -1,57 +0,0 @@
|
||||
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;
|
@ -0,0 +1,18 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const { getReport } = require('@postlight/ci-failed-test-reporter');
|
||||
|
||||
const report = getReport(path.join(__dirname, '../', '/test-output.json'));
|
||||
if (report) {
|
||||
const commentPath = 'tmp/artifacts/comment.json';
|
||||
fs.mkdirSync('tmp');
|
||||
fs.mkdirSync('tmp/artifacts');
|
||||
fs.writeFileSync(
|
||||
commentPath,
|
||||
JSON.stringify({
|
||||
body: report,
|
||||
issue: process.env.CIRCLE_PULL_REQUEST,
|
||||
})
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue