dx: include test results in comment (#230)

pull/228/head^2
Adam Pash 5 years ago committed by GitHub
parent bb6ad2682b
commit 1c7ae48de0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

1
.gitignore vendored

@ -10,3 +10,4 @@ dist/mercury_test.js
dist/mercury_test.js.map
dist/mercury_test.web.js
tmp/artifacts
test-output.json

@ -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",

@ -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];
@ -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 🤖
@ -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}
`
);
});

@ -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;
Loading…
Cancel
Save