From bafa7640002062f3478fc56caab0e3fdf775397e Mon Sep 17 00:00:00 2001 From: Frankie Simms Date: Mon, 1 Apr 2019 17:25:01 -0400 Subject: [PATCH] chore: set up ciftr for failed test reports (#343) --- package.json | 1 + scripts/comment-for-pr.js | 3 +- scripts/get-test-report.js | 57 ------------------------------------ scripts/pr-parser-preview.sh | 1 + scripts/write-test-report.js | 18 ++++++++++++ yarn.lock | 14 +++++++++ 6 files changed, 36 insertions(+), 58 deletions(-) delete mode 100644 scripts/get-test-report.js create mode 100644 scripts/write-test-report.js diff --git a/package.json b/package.json index e9f370b9..a88ba26f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/comment-for-pr.js b/scripts/comment-for-pr.js index ecebe014..12f6409f 100644 --- a/scripts/comment-for-pr.js +++ b/scripts/comment-for-pr.js @@ -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}\` diff --git a/scripts/get-test-report.js b/scripts/get-test-report.js deleted file mode 100644 index 08a36b96..00000000 --- a/scripts/get-test-report.js +++ /dev/null @@ -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 = ` -
- -${numFailedTests} failed tests 😱 - - ---- - -${failedTests - .map( - ({ fullName, failureMessages }) => - ` -**${fullName}** - -
- - See what went wrong - - -\`\`\`bash - ${failureMessages.join('\n\n')} -\`\`\` - -
- ---- - ` - ) - .join('\n\n')} - -
- `; - return failureReport; - } catch (e) { - // eslint-disable-next-line no-console - console.log('Error generating test report', e); - return false; - } -}; - -module.exports = getTestReport; diff --git a/scripts/pr-parser-preview.sh b/scripts/pr-parser-preview.sh index 34712ad0..bc7253ab 100755 --- a/scripts/pr-parser-preview.sh +++ b/scripts/pr-parser-preview.sh @@ -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 diff --git a/scripts/write-test-report.js b/scripts/write-test-report.js new file mode 100644 index 00000000..bdfcfc24 --- /dev/null +++ b/scripts/write-test-report.js @@ -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, + }) + ); +} diff --git a/yarn.lock b/yarn.lock index 5a32f016..b8c7b70d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"