You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -45,7 +46,7 @@ To create the code coverage JSON when deploying or validating, append `--coverag
45
46
sf project deploy [start/validate] --coverage-formatters json --results-dir "coverage"
46
47
```
47
48
48
-
To create the code coverage JSON when running tests directly in the org, append `--code-coverage --result-format json --output-dir "coverage"` to the `sf apex run test` or `sf apex get test` command. This will create the code coverage JSON in a folder named "coverage".
49
+
To create the code coverage JSON when running tests directly in the org, append `--code-coverage --result-format json --output-dir "coverage"` to the `sf apex run test` or `sf apex get test` command. This will create the code coverage JSON in this relative path - `coverage/test-result-codecoverage.json`
49
50
50
51
```
51
52
sf apex run test --code-coverage --result-format json --output-dir "coverage"
@@ -54,6 +55,12 @@ sf apex get test --test-run-id <test run id> --code-coverage --result-format jso
54
55
55
56
The code coverage JSONs created by the Salesforce CLI aren't accepted automatically for Salesforce DX repositories and needs to be converted using this plugin.
56
57
58
+
## Creating Code Coverage Files with SFDX Hardis
59
+
60
+
This plugin can be used after running [sfdx-hardis](https://github.com/hardisgroupcom/sfdx-hardis) commands `hardis:project:deploy:smart` (only if `COVERAGE_FORMATTER_JSON=true` environment variable is defined) and `hardis:org:test:apex` assuming you have sfdx-hardis and this plugin installed.
61
+
62
+
Both hardis commands will create the code coverage JSON to transform here: `hardis-report/apex-coverage-results.json`. Provide this relative path as the `--coverage-json`/`-j` input for this plugin.
63
+
57
64
## What this Plugin fixes in the Salesforce CLI Coverage Reports
58
65
59
66
1. The coverage reports created by this plugin will add correct file-paths per your Salesforce DX repository. Salesforce CLI coverage reports have the `no-map/` prefix hard-coded into their coverage reports. The coverage report created in this plugin will only contain Apex coverage results against files found in your Salesforce DX repository, allowing you to use these reports in external code quality tools like SonarQube.
@@ -105,38 +112,30 @@ EXAMPLES
105
112
106
113
## Hook
107
114
108
-
A post-run hook has been configured if you elect to use it.
115
+
A post-run hook has been configured if you opt into using it by creating a `.apexcodecovtransformer.config.json` config file in the root of your repo. If the config file is found, the post-run hook will automatically run after the following commands:
109
116
110
-
The post-run hook will automatically transform the code coverage JSON file after every Salesforce CLI deployment (`sf project deploy start`, `sf project deploy validate`, `sf project deploy report`, `sf project deploy resume` commands) and test run (`sf apex run test` and `sf apex get test` commands) if the JSON is found.
117
+
-`sf project deploy start`
118
+
-`sf project deploy validate`
119
+
-`sf project deploy report`
120
+
-`sf project deploy resume`
121
+
-`sf apex run test`
122
+
-`sf apex get test`
123
+
-`hardis:project:deploy:smart` (only if sfdx-hardis is installed and `COVERAGE_FORMATTER_JSON=true` environment variable is defined)
124
+
-`hardis:org:test:apex` (only if sfdx-hardis is installed)
111
125
112
-
The hook requires you to create this file in the root of your repo: `.apexcodecovtransformer.config.json`
126
+
You can copy the sample [Salesforce CLI .apexcodecovtransformer.config.json](https://raw.githubusercontent.com/mcarvin8/apex-code-coverage-transformer/main/defaults/salesforce-cli/.apexcodecovtransformer.config.json), which assumes you are running the Salesforce CLI commands and specifying the `--results-dir`/`--output-dir` directory as "coverage". Update this sample with your desired output report path and format.
113
127
114
-
The `.apexcodecovtransformer.config.json` should look like this:
128
+
You can copy the sample [SFDX Hardis .apexcodecovtransformer.config.json](https://raw.githubusercontent.com/mcarvin8/apex-code-coverage-transformer/main/defaults/sfdx-hardis/.apexcodecovtransformer.config.json), which assumes you are running the SFDX Hardis commands. Update this sample with your desired output report path and format.
The `.apexcodecovtransformer.config.json` follows this structure:
124
131
125
-
-`deployCoverageJsonPath` is required to use the hook after deployments and should be the path to the code coverage JSON created by the Salesforce CLI deployment command. Recommend using a relative path.
126
-
-`testCoverageJsonPath` is required to use the hook after test runs and should be the path to the code coverage JSON created by the Salesforce CLI test command. Recommend using a relative path.
132
+
-`deployCoverageJsonPath` is required to use the hook after deploy commands and should be the path to the code coverage JSON created by the Salesforce CLI/SFDX Hardis deploy command. Recommend using a relative path.
133
+
-`testCoverageJsonPath` is required to use the hook after test commands and should be the path to the code coverage JSON created by the Salesforce CLI/SFDX Hardis test command. Recommend using a relative path.
127
134
-`outputReportPath` is optional and should be the path to the code coverage file created by this plugin. Recommend using a relative path. If this isn't provided, it will default to `coverage.[xml/info]` in the working directory.
128
135
-`format` is optional and should be the intended output format for the code coverage file created by this plugin. Options are "sonar", "clover", "lcovonly", or "cobertura". If this isn't provided, it will default to "sonar".
129
136
130
137
If the `.apexcodecovtransformer.config.json` file isn't found, the hook will be skipped.
131
138
132
-
The post-run hook can also run after the [sfdx-hardis](https://github.com/hardisgroupcom/sfdx-hardis) commands `hardis:project:deploy:smart` (only if `COVERAGE_FORMATTER_JSON=true` environment variable is defined) and `hardis:org:test:apex` assuming you:
133
-
134
-
- Install both plugins, apex-code-coverage-transformer and sfdx-hardis, with the Salesforce CLI
135
-
- Create the `.apexcodecovtransformer.config.json` file in the root of your repo
136
-
- Set `deployCoverageJsonPath` and `testCoverageJsonPath` in `.apexcodecovtransformer.config.json` to `hardis-report/apex-coverage-results.json`
137
-
138
-
Since sfdx-hardis invokes Salesforce CLI commands, the hooks will fire twice per hardis command, once after the Salesforce CLI command and once after the sfdx-hardis command. The hook will end early without errors after the Salesforce CLI command and will run successfully after the sfdx-hardis command assuming the hardis report is found.
139
-
140
139
## Errors and Warnings
141
140
142
141
Any file in the coverage JSON that isn't found in any package directory will result in this warning:
0 commit comments