Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dx: include test results in comment #230

Merged
merged 2 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;