Skip to content

Commit c8dc711

Browse files
committed
fix: fix default test command path in doc and provide defaults
1 parent 4e7046b commit c8dc711

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed

README.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [Install](#install)
1010
- [Who is the Plugin For?](#who-is-the-plugin-for)
1111
- [Creating Code Coverage Files with the Salesforce CLI](#creating-code-coverage-files-with-the-salesforce-cli)
12+
- [Creating Code Coverage Files with SFDX Hardis](#creating-code-coverage-files-with-sfdx-hardis)
1213
- [What this Plugin fixes in the Salesforce CLI Coverage Reports](#what-this-plugin-fixes-in-the-salesforce-cli-coverage-reports)
1314
- [Command](#command)
1415
- [`sf acc-transformer transform`](#sf-acc-transformer-transform)
@@ -45,7 +46,7 @@ To create the code coverage JSON when deploying or validating, append `--coverag
4546
sf project deploy [start/validate] --coverage-formatters json --results-dir "coverage"
4647
```
4748

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`
4950

5051
```
5152
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
5455

5556
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.
5657

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+
5764
## What this Plugin fixes in the Salesforce CLI Coverage Reports
5865

5966
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
105112

106113
## Hook
107114

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:
109116

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)
111125

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.
113127

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.
115129

116-
```json
117-
{
118-
"deployCoverageJsonPath": "coverage/coverage/coverage.json",
119-
"testCoverageJsonPath": "coverage/test-coverage.json",
120-
"outputReportPath": "coverage.xml",
121-
"format": "sonar"
122-
}
123-
```
130+
The `.apexcodecovtransformer.config.json` follows this structure:
124131

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.
127134
- `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.
128135
- `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".
129136

130137
If the `.apexcodecovtransformer.config.json` file isn't found, the hook will be skipped.
131138

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-
140139
## Errors and Warnings
141140

142141
Any file in the coverage JSON that isn't found in any package directory will result in this warning:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"deployCoverageJsonPath": "coverage/coverage/coverage.json",
3+
"testCoverageJsonPath": "coverage/test-result-codecoverage.json",
4+
"outputReportPath": "coverage.xml",
5+
"format": "sonar"
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"deployCoverageJsonPath": "hardis-report/apex-coverage-results.json",
3+
"testCoverageJsonPath": "hardis-report/apex-coverage-results.json",
4+
"outputReportPath": "coverage.xml",
5+
"format": "sonar"
6+
}

0 commit comments

Comments
 (0)