From 83ed6c54ea14be92b3236bae7e077eca3a9c45e7 Mon Sep 17 00:00:00 2001 From: Edoardo Pirovano Date: Mon, 12 Aug 2024 17:04:32 +0100 Subject: [PATCH] Show code coverage in PR comment --- package.json | 14 ++-- src/actions/main/utils/results-reporter.ts | 30 +++++++- yarn.lock | 90 +++++++++++----------- 3 files changed, 80 insertions(+), 54 deletions(-) diff --git a/package.json b/package.json index 8249f2b3..2ea4f8b1 100644 --- a/package.json +++ b/package.json @@ -38,12 +38,12 @@ "dependencies": { "@actions/core": "^1.10.0", "@actions/github": "^5.1.1", - "@alwaysmeticulous/client": "^2.143.0", - "@alwaysmeticulous/common": "^2.143.0", - "@alwaysmeticulous/remote-replay-launcher": "^2.143.0", + "@alwaysmeticulous/client": "^2.145.0", + "@alwaysmeticulous/common": "^2.145.0", + "@alwaysmeticulous/remote-replay-launcher": "^2.145.0", "//": "Upgrading `replay-orchestrator-launcher`? Consider bumping the environment version `LOGICAL_ENVIRONMENT_VERSION` in `constants.ts` if the new version includes visible changes.", - "@alwaysmeticulous/replay-orchestrator-launcher": "^2.143.0", - "@alwaysmeticulous/sentry": "^2.143.0", + "@alwaysmeticulous/replay-orchestrator-launcher": "^2.145.0", + "@alwaysmeticulous/sentry": "^2.145.0", "@sentry/node": "^7.107.0", "lodash.debounce": "^4.0.8", "loglevel": "^1.8.1", @@ -51,8 +51,8 @@ "retry": "^0.13.1" }, "devDependencies": { - "@alwaysmeticulous/api": "^2.141.0", - "@alwaysmeticulous/sdk-bundles-api": "^2.143.0", + "@alwaysmeticulous/api": "^2.144.0", + "@alwaysmeticulous/sdk-bundles-api": "^2.145.0", "@parcel/packager-ts": "^2.12.0", "@parcel/transformer-typescript-types": "^2.12.0", "@types/jest": "^27.0.3", diff --git a/src/actions/main/utils/results-reporter.ts b/src/actions/main/utils/results-reporter.ts index ab6143c8..23ffa73d 100644 --- a/src/actions/main/utils/results-reporter.ts +++ b/src/actions/main/utils/results-reporter.ts @@ -138,6 +138,32 @@ export class ResultsReporter { 0 ); + let coverageLine = ""; + const executableLinesEdited = + testRun.coverageInfo?.editedFileCoverage?.executableLinesEdited; + const executableLinesEditedAndCovered = + testRun.coverageInfo?.editedFileCoverage?.executableLinesEditedAndCovered; + if ( + executableLinesEdited && + executableLinesEditedAndCovered !== undefined && + testRun.coverageInfo?.hadCoverageData + ) { + const notTested = executableLinesEdited - executableLinesEditedAndCovered; + coverageLine += "\n\n"; + const coverageLink = `${testRun.url}/coverage?mode=pr`; + if (executableLinesEditedAndCovered === 0) { + coverageLine += `Meticulous tested none of the executable lines edited in this PR. If this PR does not modify your frontend this is expected. If this is a new feature or Meticulous was recently introduced then Meticulous will generate tests to cover your code in the coming days[1].`; + coverageLine += + "[^1]:\n1. If you wish to increase coverage immediately you can do so by interacting with your feature on localhost."; + } else if (notTested > 0) { + coverageLine += `Meticulous tested [${executableLinesEditedAndCovered}/${executableLinesEdited} of the executable lines](${coverageLink}) edited in this PR1.\n\n`; + coverageLine += + "[^1]:\n1. These lines will likely automatically gain test coverage over the coming days, however if you wish to increase coverage immediately you can do so by interacting with your feature on localhost."; + } else { + coverageLine += `Meticulous tested [100% of the executable lines](${coverageLink}) edited in this PR.`; + } + } + if (screensWithDifferences === 0) { if (!(testRun.project as EnrichedProject).isGitHubIntegrationActive) { await this.setCommitStatus({ @@ -149,7 +175,7 @@ export class ResultsReporter { if (totalScreensCompared > 0) { await this.setStatusComment({ createIfDoesNotExist: true, - body: `✅ Meticulous spotted zero visual differences across ${totalScreensCompared} screens tested: [view results](${testRun.url}).`, + body: `✅ Meticulous spotted zero visual differences across ${totalScreensCompared} screens tested: [view results](${testRun.url}).${coverageLine}`, }); } else { if (totalScreenshotsTaken === 0) { @@ -181,7 +207,7 @@ export class ResultsReporter { } await this.setStatusComment({ createIfDoesNotExist: true, - body: `🤖 Meticulous spotted visual differences in ${screensWithDifferences} of ${totalScreensCompared} screens tested: [view and approve differences detected](${testRun.url}).`, + body: `🤖 Meticulous spotted visual differences in ${screensWithDifferences} of ${totalScreensCompared} screens tested: [view and approve differences detected](${testRun.url}).${coverageLine}`, }); } } diff --git a/yarn.lock b/yarn.lock index 8bf143f4..7dc4b526 100644 --- a/yarn.lock +++ b/yarn.lock @@ -32,38 +32,38 @@ dependencies: tunnel "^0.0.6" -"@alwaysmeticulous/api@^2.141.0": - version "2.141.0" - resolved "https://registry.yarnpkg.com/@alwaysmeticulous/api/-/api-2.141.0.tgz#5e5d964e5dd8bcd5331b86a4ebb37ec674efe1b6" - integrity sha512-4qxPb4dsalwB8kxWv68V7kNnwVN0n3vVGRvG373R9bLSavsvaPPteY1Rqo0IrwJ/tMYdDUFxLr5EQ6x6o0mVAQ== - -"@alwaysmeticulous/client@^2.143.0": - version "2.143.0" - resolved "https://registry.yarnpkg.com/@alwaysmeticulous/client/-/client-2.143.0.tgz#ae7021b272dc790e2f16f3f9509bd7a7f8cf7560" - integrity sha512-IQfDJzwkFZQep9yrrmWJxp1x9vrGfPTeIHaeJFNYDK0lqoHZRmq61YB30fAqpj9haOyXaohz+AYoTj8IMSi+8w== - dependencies: - "@alwaysmeticulous/api" "^2.141.0" - "@alwaysmeticulous/common" "^2.143.0" +"@alwaysmeticulous/api@^2.144.0": + version "2.144.0" + resolved "https://registry.yarnpkg.com/@alwaysmeticulous/api/-/api-2.144.0.tgz#265053f34ced76818f1933f62afef32a2cfe87c2" + integrity sha512-0bSHe2Gctf5KyEVi/IcOd543voIkzzhKhb/AnOVxjY/ONhmIwpcErt0f/4ETdwboNAYwVjqSHRfxGGKf+JsO6A== + +"@alwaysmeticulous/client@^2.145.0": + version "2.145.0" + resolved "https://registry.yarnpkg.com/@alwaysmeticulous/client/-/client-2.145.0.tgz#0fd27d4df8b659c669c4183aefd82695f5dbacb2" + integrity sha512-7LwcBJiv55XOuSIupSWCT7GgB0oXrsR3T5/H77z940kx+UhzU4dCtJDfdMYNHX2NBq0qZHpBJp0860Qk8EicbA== + dependencies: + "@alwaysmeticulous/api" "^2.144.0" + "@alwaysmeticulous/common" "^2.145.0" axios "^1.2.6" axios-retry "^4.1.0" loglevel "^1.8.0" -"@alwaysmeticulous/common@^2.143.0": - version "2.143.0" - resolved "https://registry.yarnpkg.com/@alwaysmeticulous/common/-/common-2.143.0.tgz#6262efc6b24b8dade86e5be6e142408eab77b10a" - integrity sha512-Hjec/WVxy7tkqry/MK5Ave3bUUhXgfl5DDCWNeCkk+iP4heflqLQQTtG+bQMueXKNabq322snrVxYekRRw6AFg== +"@alwaysmeticulous/common@^2.145.0": + version "2.145.0" + resolved "https://registry.yarnpkg.com/@alwaysmeticulous/common/-/common-2.145.0.tgz#68de9dafd7de6ba3046bf9c0e78d1bc52f2a056f" + integrity sha512-a9M+Howvaq0FmYDQpnDqHj95KB/FGeK6oXtuXUlt5GLfejR69x1h7Sc+dRawxfGd1cVhPBkict577U8FaY6Jsg== dependencies: loglevel "^1.8.0" luxon "^3.2.1" -"@alwaysmeticulous/downloading-helpers@^2.143.0": - version "2.143.0" - resolved "https://registry.yarnpkg.com/@alwaysmeticulous/downloading-helpers/-/downloading-helpers-2.143.0.tgz#477328e567c3433e15ffbd68bb4a13d80366199d" - integrity sha512-48XabHmZL3UXo1sBoDUT3A3ciZxEYrAWhHIzYoJDJAhP4y/MrutrfwejtUUXe3fVwBH5XFjuYupBUhxqE8v1BA== +"@alwaysmeticulous/downloading-helpers@^2.145.0": + version "2.145.0" + resolved "https://registry.yarnpkg.com/@alwaysmeticulous/downloading-helpers/-/downloading-helpers-2.145.0.tgz#8d5683825696c1cf9467c5fa1b92a17240516f78" + integrity sha512-UBiYoSPQDkcYel/9s7APQjC5PLLyRD3CCMb7IQWdPZTFaX6vg/Yy5FTczdQJzTNRts6rNKCLDNiwn4unZcEJtA== dependencies: - "@alwaysmeticulous/api" "^2.141.0" - "@alwaysmeticulous/client" "^2.143.0" - "@alwaysmeticulous/common" "^2.143.0" + "@alwaysmeticulous/api" "^2.144.0" + "@alwaysmeticulous/client" "^2.145.0" + "@alwaysmeticulous/common" "^2.145.0" axios "^1.2.6" axios-retry "^4.1.0" extract-zip "^2.0.1" @@ -72,38 +72,38 @@ p-limit "^3.1.0" proper-lockfile "^4.1.2" -"@alwaysmeticulous/remote-replay-launcher@^2.143.0": - version "2.143.0" - resolved "https://registry.yarnpkg.com/@alwaysmeticulous/remote-replay-launcher/-/remote-replay-launcher-2.143.0.tgz#9c3a5f14533a765401868830159f6f6ff66f4f42" - integrity sha512-1yxfEL6daZXGAMgKG9LrDrfr0I2vv9oORwFJ/wyluZsfgGjnDLTt+Sl+tNeX+le57jbRQsJStgQ2d6EwADQZ5A== +"@alwaysmeticulous/remote-replay-launcher@^2.145.0": + version "2.145.0" + resolved "https://registry.yarnpkg.com/@alwaysmeticulous/remote-replay-launcher/-/remote-replay-launcher-2.145.0.tgz#39e06a951d6dd8624835b2696e09480fc34bbcb4" + integrity sha512-OaA/NfzALDXl/yycu6GtH018sOCFtkge422mCHN+niwa8bP6vDqbLSgjCoguJoOlFEDnK2Dck6Z9jFpYLZhg1Q== dependencies: - "@alwaysmeticulous/client" "^2.143.0" - "@alwaysmeticulous/common" "^2.143.0" + "@alwaysmeticulous/client" "^2.145.0" + "@alwaysmeticulous/common" "^2.145.0" "@alwaysmeticulous/tunnels-client" "^2.143.0" loglevel "^1.8.0" -"@alwaysmeticulous/replay-orchestrator-launcher@^2.143.0": - version "2.143.0" - resolved "https://registry.yarnpkg.com/@alwaysmeticulous/replay-orchestrator-launcher/-/replay-orchestrator-launcher-2.143.0.tgz#48e8da0d35ebf6c2e0787fb0c3185ae0cc5791b0" - integrity sha512-5BiiT22nCim9Fh623aMRX3MCE3Q6dC8yRX5Xa3SulQiozbGERLTfQZhypPkHjE+Q47FO4O8/KUuBWltBUd+ODQ== +"@alwaysmeticulous/replay-orchestrator-launcher@^2.145.0": + version "2.145.0" + resolved "https://registry.yarnpkg.com/@alwaysmeticulous/replay-orchestrator-launcher/-/replay-orchestrator-launcher-2.145.0.tgz#db3441005fe922cd2f34d47cf39914c503887d86" + integrity sha512-bEOQuZBJwtyIwU1hfwPMfrH8iP1QzfPGUpwLMzhTVMCts3AmGb3OYerJmEJuOk1f7BH2sPDDLqynkNdN+jL8LA== dependencies: - "@alwaysmeticulous/common" "^2.143.0" - "@alwaysmeticulous/downloading-helpers" "^2.143.0" - "@alwaysmeticulous/sdk-bundles-api" "^2.143.0" + "@alwaysmeticulous/common" "^2.145.0" + "@alwaysmeticulous/downloading-helpers" "^2.145.0" + "@alwaysmeticulous/sdk-bundles-api" "^2.145.0" loglevel "^1.8.0" puppeteer "21.9.0" -"@alwaysmeticulous/sdk-bundles-api@^2.143.0": - version "2.143.0" - resolved "https://registry.yarnpkg.com/@alwaysmeticulous/sdk-bundles-api/-/sdk-bundles-api-2.143.0.tgz#ddb0406b674d1e3e9429e3c818db46f53dc3b91e" - integrity sha512-K/Y76faIlyvZM3UB035qtETHdnJ5J8AG1VAYW3m9ufS/LEdhmQQaUI88U5Wmk4lmVC4eykTgvLzIprwGCNjR/Q== +"@alwaysmeticulous/sdk-bundles-api@^2.145.0": + version "2.145.0" + resolved "https://registry.yarnpkg.com/@alwaysmeticulous/sdk-bundles-api/-/sdk-bundles-api-2.145.0.tgz#10b253ac2a3b8c0920601eb41fe8fec7d3fc3868" + integrity sha512-G12xevDlZ9IM2UXHg/3K+nYX1O11qIaSFrHr3QH7Wo6AJmk+2GJnyxixVhtfFPBc4kr9xpi6FiaYPzWYQ7p9RQ== -"@alwaysmeticulous/sentry@^2.143.0": - version "2.143.0" - resolved "https://registry.yarnpkg.com/@alwaysmeticulous/sentry/-/sentry-2.143.0.tgz#d254ab0dcac2b1172a7cf750661423abc71abd89" - integrity sha512-tS/3lwhO2RFasTxn9dFadLNB4B4ZA2OHlGF37+/yIlkGzgog9kkOQGQoku2UknMgODYh5HA/Ss/nNwEnf9SO5w== +"@alwaysmeticulous/sentry@^2.145.0": + version "2.145.0" + resolved "https://registry.yarnpkg.com/@alwaysmeticulous/sentry/-/sentry-2.145.0.tgz#2007ba9f9aa6aaed3391a4ad5220d0c05f4ae3b9" + integrity sha512-0d7mbSfKEdBJbbwUIanzF5kjYynBRe06Hxk+CS5tnLs3OBxAkstxWc0ydzbe7rCICUGMorMj1g7rjIqGwi6Gmg== dependencies: - "@alwaysmeticulous/common" "^2.143.0" + "@alwaysmeticulous/common" "^2.145.0" "@sentry/node" "^7.107.0" "@sentry/tracing" "^7.107.0" luxon "^3.2.1"