mirror of
https://github.com/postlight/mercury-parser
synced 2024-10-31 03:20:40 +00:00
chore: set up ciftr for failed test reports (#343)
This commit is contained in:
parent
262dda94b3
commit
bafa764000
@ -108,6 +108,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime-corejs2": "^7.2.0",
|
"@babel/runtime-corejs2": "^7.2.0",
|
||||||
|
"@postlight/ci-failed-test-reporter": "^1.0",
|
||||||
"browser-request": "github:postlight/browser-request#feat-add-headers-to-response",
|
"browser-request": "github:postlight/browser-request#feat-add-headers-to-response",
|
||||||
"cheerio": "^0.22.0",
|
"cheerio": "^0.22.0",
|
||||||
"difflib": "github:postlight/difflib.js",
|
"difflib": "github:postlight/difflib.js",
|
||||||
|
@ -4,6 +4,7 @@ const Mercury = require('../dist/mercury.js');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const getTestReport = require('./get-test-report');
|
const getTestReport = require('./get-test-report');
|
||||||
const execSync = require('child_process').execSync;
|
const execSync = require('child_process').execSync;
|
||||||
|
const { getReport } = require('@postlight/ci-failed-test-reporter');
|
||||||
|
|
||||||
const run = () => {
|
const run = () => {
|
||||||
const screenshotPath = process.argv[2];
|
const screenshotPath = process.argv[2];
|
||||||
@ -37,7 +38,7 @@ const run = () => {
|
|||||||
fs.writeFileSync(fixtureArtifactPath, html);
|
fs.writeFileSync(fixtureArtifactPath, html);
|
||||||
|
|
||||||
const testReport =
|
const testReport =
|
||||||
getTestReport('./test-output.json') || '✅ All tests passed';
|
getReport('./test-output.json') || '✅ All tests passed';
|
||||||
|
|
||||||
const comment = `### 🤖 Automated Parsing Preview 🤖
|
const comment = `### 🤖 Automated Parsing Preview 🤖
|
||||||
**Commit:** \`${bot.env.commitMessage}\`
|
**Commit:** \`${bot.env.commitMessage}\`
|
||||||
|
@ -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;
|
|
@ -24,4 +24,5 @@ if [[ $fixtures ]]; then
|
|||||||
done
|
done
|
||||||
else
|
else
|
||||||
echo "No fixtures added in this PR, so no preview needed"
|
echo "No fixtures added in this PR, so no preview needed"
|
||||||
|
node scripts/write-test-report.js
|
||||||
fi
|
fi
|
||||||
|
18
scripts/write-test-report.js
Normal file
18
scripts/write-test-report.js
Normal 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,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
14
yarn.lock
14
yarn.lock
@ -597,6 +597,14 @@
|
|||||||
universal-user-agent "^2.0.0"
|
universal-user-agent "^2.0.0"
|
||||||
url-template "^2.0.8"
|
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":
|
"@samverschueren/stream-to-observable@^0.3.0":
|
||||||
version "0.3.0"
|
version "0.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.0.tgz#ecdf48d532c58ea477acfcab80348424f8d0662f"
|
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"
|
dom-serializer "0"
|
||||||
domelementtype "1"
|
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:
|
duplexer2@^0.1.2, duplexer2@~0.1.0, duplexer2@~0.1.2, duplexer2@~0.1.4:
|
||||||
version "0.1.4"
|
version "0.1.4"
|
||||||
resolved "https://registry.yarnpkg.com/duplexer2/-/duplexer2-0.1.4.tgz#8b12dab878c0d69e3e7891051662a32fc6bddcc1"
|
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:
|
node-fetch@^2.3.0:
|
||||||
version "2.3.0"
|
version "2.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.3.0.tgz#1a1d940bbfb916a1d3e0219f037e89e71f8c5fa5"
|
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:
|
node-int64@^0.4.0:
|
||||||
version "0.4.0"
|
version "0.4.0"
|
||||||
|
Loading…
Reference in New Issue
Block a user