Skip to content

Commit

Permalink
dx: include test results in comment (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
adampash authored Jan 30, 2019
1 parent bb6ad26 commit 1c7ae48
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ dist/mercury_test.js
dist/mercury_test.js.map
dist/mercury_test.web.js
tmp/artifacts
test-output.json
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"build:generator": "rollup -c scripts/rollup.config.js",
"test_build": "rollup -c",
"test": "yarn test:node && yarn test:web",
"test:node": "jest",
"test:node": "jest --json --outputFile test-output.json",
"test:web": "node ./node_modules/karma/bin/karma start karma.conf.js --auto-watch",
"test:build": "cd ./scripts && jest check-build.test.js",
"test:build:web": "node ./scripts/proxy-browser-test.js",
Expand Down
8 changes: 7 additions & 1 deletion scripts/comment-on-pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const bot = require('@jesses/circle-github-bot').default.create();
const Mercury = require('../dist/mercury.js');
const fs = require('fs');
const getTestReport = require('./get-test-report');

const run = () => {
const screenshotPath = process.argv[2];
Expand Down Expand Up @@ -34,6 +35,9 @@ const run = () => {
fs.writeFileSync(jsonPath, JSON.stringify(json));
fs.writeFileSync(fixtureArtifactPath, html);

const testReport =
getTestReport('./test-output.json') || '✅ All tests passed';

bot.comment(
process.env.GH_AUTH_TOKEN,
`### 🤖 Automated Parsing Preview 🤖
Expand Down Expand Up @@ -63,8 +67,10 @@ ${JSON.stringify(json, null, 2)}
${Object.keys(json)
.map(key => (json[key] !== null ? '' : ` * \`${key}\n\``))
.join('') || 'None'}
.join('\n\n') || 'None'}
${testReport}
`
);
});
Expand Down
56 changes: 56 additions & 0 deletions scripts/get-test-report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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) {
console.log('Error generating test report', e);
return false;
}
};

module.exports = getTestReport;

0 comments on commit 1c7ae48

Please sign in to comment.