chore: set up ciftr for failed test reports (#343)

This commit is contained in:
Frankie Simms 2019-04-01 17:25:01 -04:00 committed by Adam Pash
parent 262dda94b3
commit bafa764000
6 changed files with 36 additions and 58 deletions

View File

@ -108,6 +108,7 @@
},
"dependencies": {
"@babel/runtime-corejs2": "^7.2.0",
"@postlight/ci-failed-test-reporter": "^1.0",
"browser-request": "github:postlight/browser-request#feat-add-headers-to-response",
"cheerio": "^0.22.0",
"difflib": "github:postlight/difflib.js",

View File

@ -4,6 +4,7 @@ const Mercury = require('../dist/mercury.js');
const fs = require('fs');
const getTestReport = require('./get-test-report');
const execSync = require('child_process').execSync;
const { getReport } = require('@postlight/ci-failed-test-reporter');
const run = () => {
const screenshotPath = process.argv[2];
@ -37,7 +38,7 @@ const run = () => {
fs.writeFileSync(fixtureArtifactPath, html);
const testReport =
getTestReport('./test-output.json') || '✅ All tests passed';
getReport('./test-output.json') || '✅ All tests passed';
const comment = `### 🤖 Automated Parsing Preview 🤖
**Commit:** \`${bot.env.commitMessage}\`

View File

@ -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;

View File

@ -24,4 +24,5 @@ if [[ $fixtures ]]; then
done
else
echo "No fixtures added in this PR, so no preview needed"
node scripts/write-test-report.js
fi

View File

@ -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,
})
);
}

View File

@ -597,6 +597,14 @@
universal-user-agent "^2.0.0"
url-template "^2.0.8"
"@postlight/ci-failed-test-reporter@^1.0":
version "1.0.22"
resolved "https://registry.yarnpkg.com/@postlight/ci-failed-test-reporter/-/ci-failed-test-reporter-1.0.22.tgz#c382c3e75a4bcf078e4ed1abf14ea63d074d56b3"
integrity sha512-k8YkZgrxgnYoju6Y0XZTXKk2fFeWBZ0+voA3WyVvEK3i9FsExCNMoKb5s0VBSqO6V9FxIQDXhjmcwn6t8cIDWA==
dependencies:
dotenv "^6.2.0"
node-fetch "^2.3.0"
"@samverschueren/stream-to-observable@^0.3.0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.0.tgz#ecdf48d532c58ea477acfcab80348424f8d0662f"
@ -2513,6 +2521,11 @@ domutils@1.5.1, domutils@^1.5.1:
dom-serializer "0"
domelementtype "1"
dotenv@^6.2.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-6.2.0.tgz#941c0410535d942c8becf28d3f357dbd9d476064"
integrity sha512-HygQCKUBSFl8wKQZBSemMywRWcEDNidvNbjGVyZu3nbZ8qq9ubiPoGLMdRDpfSrpkkm9BXYFkpKxxFX38o/76w==
duplexer2@^0.1.2, duplexer2@~0.1.0, duplexer2@~0.1.2, duplexer2@~0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/duplexer2/-/duplexer2-0.1.4.tgz#8b12dab878c0d69e3e7891051662a32fc6bddcc1"
@ -5637,6 +5650,7 @@ node-environment-flags@1.0.4:
node-fetch@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.3.0.tgz#1a1d940bbfb916a1d3e0219f037e89e71f8c5fa5"
integrity sha512-MOd8pV3fxENbryESLgVIeaGKrdl+uaYhCSSVkjeOb/31/njTpcis5aWfdqgNlHIrKOLRbMnfPINPOML2CIFeXA==
node-int64@^0.4.0:
version "0.4.0"