
Security News
ESLint Adds Official Support for Linting HTML
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
apex-code-coverage-transformer
Advanced tools
Transform Salesforce Apex code coverage JSONs created during deployments and test runs into other formats accepted by SonarQube, GitHub, GitLab, Azure, Bitbucket, etc.
apex-code-coverage-transformer
Transform the Salesforce Apex code coverage JSON files created during deployments and test runs into other formats accepted by SonarQube, GitHub, GitLab, Azure, Bitbucket, etc.
If there's a coverage format not yet supported by this plugin, feel free to provide a pull request or issue for the coverage format.
sf plugins install apex-code-coverage-transformer@x.y.z
This plugin is designed for users deploying Apex or running Apex tests within Salesforce DX projects (sfdx-project.json
). It transforms Salesforce CLI JSON coverage reports into formats recognized by external tools.
The plugin ensures that coverage data is only reported for files found in your package directories, preventing mismatches in tools like SonarQube. If Apex files are missing from your project (i.e. Apex from managed or unlocked packages), they will be excluded from the transformed report with a warning.
To automate coverage transformation after deployments or test executions, see Hook.
This plugin will only support the "json" coverage format from the Salesforce CLI. Do not use other coverage formats from the Salesforce CLI.
To create the code coverage JSON when deploying or validating, append --coverage-formatters json --results-dir "coverage"
to the sf project deploy
command. This will create a coverage JSON in this relative path - coverage/coverage/coverage.json
.
sf project deploy [start/validate/report/resume] --coverage-formatters json --results-dir "coverage"
To create the code coverage JSON when running tests directly in the org, append --code-coverage --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
sf apex run test --code-coverage --output-dir "coverage"
sf apex get test --test-run-id <test run id> --code-coverage --output-dir "coverage"
This plugin can be used after running the below sfdx-hardis commands:
sf hardis project deploy smart
(only if COVERAGE_FORMATTER_JSON=true
environment variable is defined)sf hardis org test apex
Both hardis commands will create the code coverage JSON to transform here: hardis-report/apex-coverage-results.json
.
no-map/AccountTriggerHandler
) to their corresponding relative file paths in the Salesforce DX project (e.g., force-app/main/default/classes/AccountTriggerHandler.cls
).covered
lines to unused lines, ensuring reports are accepted by external tools.uncovered
lines are always correctly reported by the deploy command.The apex-code-coverage-transformer
has 1 command:
sf acc-transformer transform
sf acc-transformer transform
USAGE
$ sf acc-transformer transform -j <value> [-r <value>] [-f <value>] [-i <value>] [--json]
FLAGS
-j, --coverage-json=<value> Path to the code coverage JSON file created by the Salesforce CLI deploy or test command.
-r, --output-report=<value> Path to the code coverage file that will be created by this plugin.
[default: "coverage.[xml/info]"]
-f, --format=<value> Output format for the code coverage format.
[default: "sonar"]
-i, --ignore-package-directory=<value> Package directory to ignore when looking for matching files in the coverage report.
Should be as they appear in the "sfdx-project.json".
Can be declared multiple times.
GLOBAL FLAGS
--json Format output as json.
EXAMPLES
Transform the JSON into Sonar format:
$ sf acc-transformer transform -j "coverage.json" -r "coverage.xml" -f "sonar"
Transform the JSON into Cobertura format:
$ sf acc-transformer transform -j "coverage.json" -r "coverage.xml" -f "cobertura"
Transform the JSON into Clover format:
$ sf acc-transformer transform -j "coverage.json" -r "coverage.xml" -f "clover"
Transform the JSON into LCovOnly format:
$ sf acc-transformer transform -j "coverage.json" -r "coverage.info" -f "lcovonly"
Transform the JSON into Sonar format, ignoring Apex in the "force-app" directory:
$ sf acc-transformer transform -j "coverage.json" -i "force-app"
The -f
/--format
flag allows you to specify the format of the transformed coverage report.
Flag Option | Description |
---|---|
sonar | Generates a SonarQube-compatible coverage report. This is the default option. |
clover | Produces a Clover XML report format, commonly used with Atlassian tools. |
lcovonly | Outputs coverage data in LCOV format, useful for integrating with LCOV-based tools. |
cobertura | Creates a Cobertura XML report, a widely used format for coverage reporting. |
jacoco | Creates a JaCoCo XML report, the standard for Java projects. |
To enable automatic transformation after the below sf
commands complete, create a .apexcodecovtransformer.config.json
in your project’s root directory.
sf project deploy [start/validate/report/resume]
sf apex run test
sf apex get test
sf hardis project deploy smart
sfdx-hardis
is installedCOVERAGE_FORMATTER_JSON=true
must be set in the environment variablessf hardis org test apex
sfdx-hardis
is installedYou can copy & update the sample Salesforce CLI .apexcodecovtransformer.config.json, which assumes you are running the Salesforce CLI commands and specifying the --results-dir
/--output-dir
directory as "coverage".
You can copy & update the sample SFDX Hardis .apexcodecovtransformer.config.json, which assumes you are running the SFDX Hardis commands.
.apexcodecovtransformer.config.json
structure
JSON Key | Required | Description |
---|---|---|
deployCoverageJsonPath | Yes (for deploy command) | Code coverage JSON created by the Salesforce CLI deploy commands. |
testCoverageJsonPath | Yes (for test command) | Code coverage JSON created by the Salesforce CLI test commands. |
outputReportPath | No (defaults to coverage.[xml/info] ) | Transformed code coverage report path. |
format | No (defaults to sonar ) | Transformed code coverage report format. |
ignorePackageDirectories | No | Comma-separated string of package directories to ignore when looking for matching Apex files. |
If a file listed in the coverage JSON cannot be found in any package directory, a warning is displayed, and the file will not be included in the transformed report:
Warning: The file name AccountTrigger was not found in any package directory.
If none of the files in the coverage JSON are found in a package directory, the plugin will print an additional warning, and the generated report will be empty:
Warning: The file name AccountTrigger was not found in any package directory.
Warning: The file name AccountProfile was not found in any package directory.
Warning: None of the files listed in the coverage JSON were processed. The coverage report will be empty.
Salesforce CLI generates code coverage JSONs in two different structures (deploy and test command formats). If the provided coverage JSON does not match one of these expected structures, the plugin will fail with:
Error (1): The provided JSON does not match a known coverage data format from the Salesforce deploy or test command.
If sfdx-project.json
file is missing from the project root, the plugin will fail with:
Error (1): sfdx-project.json not found in any parent directory.
If a package directory listed in sfdx-project.json
cannot be found, the plugin will encounter a ENOENT error:
Error (1): ENOENT: no such file or directory: {packageDir}
If you encounter any issues or would like to suggest features, please create an issue.
Contributions are welcome! See Contributing.
This project is licensed under the MIT license. Please see the LICENSE file for details.
FAQs
Transform Salesforce Apex code coverage JSONs created during deployments and test runs into other formats accepted by SonarQube, GitHub, GitLab, Azure, Bitbucket, etc.
The npm package apex-code-coverage-transformer receives a total of 894 weekly downloads. As such, apex-code-coverage-transformer popularity was classified as not popular.
We found that apex-code-coverage-transformer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.