-
Notifications
You must be signed in to change notification settings - Fork 407
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
Visual display of apex code coverage #1145
Conversation
const codeCoverage = JSON.parse(testResultOutput) as CoverageTestResult; | ||
if (codeCoverage.coverage === undefined) { | ||
throw new Error( | ||
`No code coverage information was found for test run ${testRunId}.` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error showed when the test results do not include code coverage information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would we recommend that people do next? Set "salesforcedx-vscode-core.retrieve-test-code-coverage": true
? Or did something else probably cause this error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, running tests without that setting on.
function getTestRunId() { | ||
const testRunIdFile = path.join(apexDirPath, 'test-run-id.txt'); | ||
if (!fs.existsSync(testRunIdFile)) { | ||
throw new Error('No test run information was found for this project.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error when the project does not have any test run information, this would happen if they've never run tests via vscode/cli.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a next step? Something like, 'No test run information was found for this project. Set "salesforcedx-vscode-core.retrieve-test-code-coverage": true in your user or workspace settings, then run Apex tests from the Apex Tests sidebar or from within a test class file.'
|
||
if (!codeCovItem) { | ||
throw new Error( | ||
'No code coverage information was found for the current file.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll show this when the test results do have code coverage information but not for the apex file currently in focus.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a next step? Something like, 'No code coverage information was found for this file. Set "salesforcedx-vscode-core.retrieve-test-code-coverage": true in your user or workspace settings. Then, run Apex tests that include methods in this file from the Apex Tests sidebar or using the Run Tests or Run All Tests code lens within the file.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import { window } from 'vscode'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the color definitions used (green & red).
const statusBarToggle = new StatusBarToggle(); | ||
const colorizer = new CodeCoverage(statusBarToggle); | ||
const colorizerCmd = vscode.commands.registerCommand( | ||
'sfdx.force.apex.toggle.colorizer', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tied everything under one command so that it's easy to trigger the feature using keyboard shortcuts.
@@ -0,0 +1,105 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to add these files under testresults
in order to run the tests. Let me know if you have a better idea for generating these for testing purposes.
'sfdx.force.apex.toggle.colorizer'; | ||
private static readonly showIcon = '$(tasklist)'; | ||
private static readonly hideIcon = '$(three-bars)'; | ||
private static readonly toolTip = 'Apex Code Coverage highlighter'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Text showed when you hover the status bar icon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other nearby hover text seems to use imperative verbs and title-case capitalization. How about this? 'Highlight Apex Code Coverage'
Codecov Report
@@ Coverage Diff @@
## develop #1145 +/- ##
=========================================
+ Coverage 72.59% 72.7% +0.1%
=========================================
Files 189 193 +4
Lines 7124 7222 +98
Branches 731 746 +15
=========================================
+ Hits 5172 5251 +79
- Misses 1803 1814 +11
- Partials 149 157 +8
Continue to review full report at Codecov.
|
Glad to see this, @lcampos . I added some comments on the messages. Also, shouldn't the messages be externalized into messages files? |
@@ -130,6 +139,7 @@ function registerCommands( | |||
forceApexTestMethodRunCodeAction | |||
); | |||
return vscode.Disposable.from( | |||
colorizerCmd, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be forceApexToggleColorizerCmd to match the rest?
// Colorize code coverage | ||
const statusBarToggle = new StatusBarToggle(); | ||
const colorizer = new CodeCoverage(statusBarToggle); | ||
const colorizerCmd = vscode.commands.registerCommand( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the pattern i am seeing for other commands, i think this could be renamed to forceApexToggleColorizerCmd.
@lcampos what happens if we try this feature on a stale run result? Let's say that the apex class has since been edited and a bunch of methods have been removed. Does attempting to map nonexistent lines fail gracefully? |
@praksb it does fail gracefully. If the code just shifted but the lines that will be colored are still in the range of the document, then we will just color whatever code, comment, empty space available. If the document's length has shortened, then it will just display a warning about it if the lines that need to be colored are not part of the range of the document. |
@ruthemmanuelle thanks for the review, yes we will have these messages on the extension's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The command renames Prakash mentioned seem like a good idea, otherwise the changes look cool!
8981e06
to
d198fe0
Compare
@@ -40,5 +40,14 @@ export const messages = { | |||
|
|||
client_name: 'Apex Language Server', | |||
cannot_determine_workspace: | |||
'Unable to determine workspace folders for workspace' | |||
'Unable to determine workspace folders for workspace', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ruthemmanuelle here are the new error messages, let me know if any changes are needed.
…dle some common scenarios where coverage info is not available
d198fe0
to
e808340
Compare
What does this PR do?
It takes the info from the test run results that contain code coverage and highlights which lines those test results cover and which they don't.
What issues does this PR fix or reference?
#973