mercury-parser/scripts/get-test-report.js
George Haddad 5c0325f5a7
feat: hook up ci to publish to npm (#226)
* chore: add missing fields to  package.json

* feat: add postlight org scope to package name

* feat: automate npm publish

* test: npm publish without filters

* fix: add docker image

* test: change directory

* test: add working directory

* fix: defaults syntax

* test: add workspace

* fix: attach workspace

* fix: use standard mercury email

* fix: use ISO time format and preserve original timezone offset

* fix: do not match time zone offset

* chore: move babel runtime-corejs2 to prod deps

* chore: uncomment config to deploy on git tag

* feat: publish to npm public

* adding browser-request

It doesn't seem to impact the build, but technically it should be there
so for good measure, why not...

* chore: roll version back to original state
2019-01-31 09:33:51 +02:00

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;