-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: build XML using xmlbuilder2 and normalize path building using posix
- Loading branch information
Showing
10 changed files
with
628 additions
and
1,067 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,29 +2,29 @@ | |
|
||
[![NPM](https://img.shields.io/npm/v/apex-code-coverage-transformer.svg?label=apex-code-coverage-transformer)](https://www.npmjs.com/package/apex-code-coverage-transformer) [![Downloads/week](https://img.shields.io/npm/dw/apex-code-coverage-transformer.svg)](https://npmjs.org/package/apex-code-coverage-transformer) [![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://raw.githubusercontent.com/mcarvin8/apex-code-coverage-transformer/main/LICENSE.md) | ||
|
||
The `apex-code-coverage-transformer` is a simple Salesforce CLI plugin to transform the Apex Code Coverage JSON file into Generic Test Coverage Format (XML). This format is accepted by static code analysis tools like SonarQube. | ||
The `apex-code-coverage-transformer` is a Salesforce CLI plugin to transform the Apex Code Coverage JSON files created during deployments into the Generic Test Coverage Format (XML). This format is accepted by static code analysis tools like SonarQube. | ||
|
||
This plugin supports code coverage metrics created for Apex Classes and Apex Triggers. This also supports multiple package directories as listed in your project's `sfdx-project.json` configuration, assuming unique file-names are used in your package directories. | ||
|
||
To create the code coverage JSON during a Salesforce CLI deployment/validation, append `--coverage-formatters json --results-dir coverage` to the `sf project deploy` command: | ||
|
||
``` | ||
sf project deploy validate -x manifest/package.xml -l RunSpecifiedTests -t {testclasses} --verbose --coverage-formatters json --results-dir coverage | ||
sf project deploy [start/validate] -x manifest/package.xml -l RunSpecifiedTests -t {testclasses} --verbose --coverage-formatters json --results-dir coverage | ||
``` | ||
|
||
This will create a coverage JSON in this relative path - `coverage/coverage/coverage.json` | ||
|
||
This JSON isn't accepted by SonarQube automatically and needs to be converted using this plugin. | ||
|
||
**Disclaimer**: Due to existing bugs with how the Salesforce CLI reports `covered` lines (see [5511](https://github.com/forcedotcom/salesforcedx-vscode/issues/5511) and [1568](https://github.com/forcedotcom/cli/issues/1568)), to add support for `covered` lines in this plugin, I had to add a function to re-number out-of-range `covered` lines the CLI may report (ex: line 100 in a 98-line Apex Class is reported back as `covered` by the Salesforce CLI deploy command). Once Salesforce updates the API to correctly return `covered` lines in the deploy command, this function will be removed. | ||
**Disclaimer**: Due to existing bugs with how the Salesforce CLI reports covered lines (see [5511](https://github.com/forcedotcom/salesforcedx-vscode/issues/5511) and [1568](https://github.com/forcedotcom/cli/issues/1568)), to add support for covered lines in this plugin, I had to add a function to re-number out-of-range covered lines the CLI may report (ex: line 100 in a 98-line Apex Class is reported back as covered by the Salesforce CLI deploy command). Salesforce's coverage result may also include extra lines as covered (ex: 120 lines are included in the coverage report for a 100 line file), so the coverage percentage may vary based on how many lines the API returns in the coverage report. Once Salesforce fixes the API to correctly return covered lines in the deploy command, this function will be removed. | ||
|
||
## Install | ||
|
||
```bash | ||
sf plugins install [email protected] | ||
``` | ||
|
||
## Commands | ||
## Command | ||
|
||
The `apex-code-coverage-transformer` has 1 command: | ||
|
||
|
@@ -39,18 +39,18 @@ USAGE | |
$ sf apex-code-coverage transformer transform -j <value> -x <value> -c <value> [--json] | ||
FLAGS | ||
-j, --coverage-json=<value> The path to the JSON file created by the Salesforce CLI for code coverage. | ||
-x, --xml=<value> [default: coverage.xml] Output path for the XML file created by this plugin | ||
-c, --sfdx-configuration=<value> [default: 'sfdx-project.json' in the current working directory] The path to your Salesforce DX configuration file, 'sfdx-project.json'. | ||
-j, --coverage-json=<value> Path to the code coverage JSON file created by the Salesforce CLI deployment command. | ||
-x, --xml=<value> [default: coverage.xml] Path to code coverage XML file that will be created by this plugin. | ||
-c, --sfdx-configuration=<value> [default: 'sfdx-project.json'] Path to your project's Salesforce DX configuration file. | ||
GLOBAL FLAGS | ||
--json Format output as json. | ||
DESCRIPTION | ||
This plugin will convert the JSON file created by the Salesforce CLI during Apex deployments into the Generic Test Coverage Format. | ||
This plugin will convert the code coverage JSON file created by the Salesforce CLI during Apex deployments into an XML accepted by tools like SonarQube. | ||
EXAMPLES | ||
$ apex-code-coverage transformer transform -j "test.json" -x "coverage.xml" -c "sfdx-project.json" | ||
$ sf apex-code-coverage transformer transform -j "coverage.json" -x "coverage.xml" -c "sfdx-project.json" | ||
``` | ||
|
||
## Errors and Warnings | ||
|
@@ -85,76 +85,76 @@ Error (1): ENOENT: no such file or directory: {packageDirPath} | |
|
||
## Example | ||
|
||
This [code coverage JSON file](https://raw.githubusercontent.com/mcarvin8/apex-code-coverage-transformer/main/test/coverage_no_file_exts.json) created by the Salesforce CLI will be transformed into: | ||
This [code coverage JSON file](https://raw.githubusercontent.com/mcarvin8/apex-code-coverage-transformer/main/test/coverage_no_file_exts.json) created during a Salesforce CLI deployment will be transformed into: | ||
|
||
```xml | ||
<?xml version="1.0"?> | ||
<coverage version="1"> | ||
<file path="packaged\triggers\AccountTrigger.trigger"> | ||
<lineToCover lineNumber="52" covered="false"/> | ||
<lineToCover lineNumber="53" covered="false"/> | ||
<lineToCover lineNumber="59" covered="false"/> | ||
<lineToCover lineNumber="60" covered="false"/> | ||
<lineToCover lineNumber="1" covered="true"/> | ||
<lineToCover lineNumber="2" covered="true"/> | ||
<lineToCover lineNumber="3" covered="true"/> | ||
<lineToCover lineNumber="4" covered="true"/> | ||
<lineToCover lineNumber="5" covered="true"/> | ||
<lineToCover lineNumber="6" covered="true"/> | ||
<lineToCover lineNumber="7" covered="true"/> | ||
<lineToCover lineNumber="8" covered="true"/> | ||
<lineToCover lineNumber="9" covered="true"/> | ||
<lineToCover lineNumber="10" covered="true"/> | ||
<lineToCover lineNumber="11" covered="true"/> | ||
<lineToCover lineNumber="12" covered="true"/> | ||
<lineToCover lineNumber="13" covered="true"/> | ||
<lineToCover lineNumber="14" covered="true"/> | ||
<lineToCover lineNumber="15" covered="true"/> | ||
<lineToCover lineNumber="16" covered="true"/> | ||
<lineToCover lineNumber="17" covered="true"/> | ||
<lineToCover lineNumber="18" covered="true"/> | ||
<lineToCover lineNumber="19" covered="true"/> | ||
<lineToCover lineNumber="20" covered="true"/> | ||
<lineToCover lineNumber="21" covered="true"/> | ||
<lineToCover lineNumber="22" covered="true"/> | ||
<lineToCover lineNumber="23" covered="true"/> | ||
<lineToCover lineNumber="24" covered="true"/> | ||
<lineToCover lineNumber="25" covered="true"/> | ||
<lineToCover lineNumber="26" covered="true"/> | ||
<lineToCover lineNumber="27" covered="true"/> | ||
</file> | ||
<file path="force-app\main\default\classes\AccountProfile.cls"> | ||
<lineToCover lineNumber="52" covered="false"/> | ||
<lineToCover lineNumber="53" covered="false"/> | ||
<lineToCover lineNumber="59" covered="false"/> | ||
<lineToCover lineNumber="60" covered="false"/> | ||
<lineToCover lineNumber="54" covered="true"/> | ||
<lineToCover lineNumber="55" covered="true"/> | ||
<lineToCover lineNumber="56" covered="true"/> | ||
<lineToCover lineNumber="57" covered="true"/> | ||
<lineToCover lineNumber="58" covered="true"/> | ||
<lineToCover lineNumber="61" covered="true"/> | ||
<lineToCover lineNumber="62" covered="true"/> | ||
<lineToCover lineNumber="63" covered="true"/> | ||
<lineToCover lineNumber="64" covered="true"/> | ||
<lineToCover lineNumber="65" covered="true"/> | ||
<lineToCover lineNumber="66" covered="true"/> | ||
<lineToCover lineNumber="67" covered="true"/> | ||
<lineToCover lineNumber="68" covered="true"/> | ||
<lineToCover lineNumber="69" covered="true"/> | ||
<lineToCover lineNumber="70" covered="true"/> | ||
<lineToCover lineNumber="71" covered="true"/> | ||
<lineToCover lineNumber="72" covered="true"/> | ||
<lineToCover lineNumber="1" covered="true"/> | ||
<lineToCover lineNumber="2" covered="true"/> | ||
<lineToCover lineNumber="3" covered="true"/> | ||
<lineToCover lineNumber="4" covered="true"/> | ||
<lineToCover lineNumber="5" covered="true"/> | ||
<lineToCover lineNumber="6" covered="true"/> | ||
<lineToCover lineNumber="7" covered="true"/> | ||
<lineToCover lineNumber="8" covered="true"/> | ||
<lineToCover lineNumber="9" covered="true"/> | ||
<lineToCover lineNumber="10" covered="true"/> | ||
</file> | ||
<file path="packaged/triggers/AccountTrigger.trigger"> | ||
<lineToCover lineNumber="52" covered="false"/> | ||
<lineToCover lineNumber="53" covered="false"/> | ||
<lineToCover lineNumber="59" covered="false"/> | ||
<lineToCover lineNumber="60" covered="false"/> | ||
<lineToCover lineNumber="1" covered="true"/> | ||
<lineToCover lineNumber="2" covered="true"/> | ||
<lineToCover lineNumber="3" covered="true"/> | ||
<lineToCover lineNumber="4" covered="true"/> | ||
<lineToCover lineNumber="5" covered="true"/> | ||
<lineToCover lineNumber="6" covered="true"/> | ||
<lineToCover lineNumber="7" covered="true"/> | ||
<lineToCover lineNumber="8" covered="true"/> | ||
<lineToCover lineNumber="9" covered="true"/> | ||
<lineToCover lineNumber="10" covered="true"/> | ||
<lineToCover lineNumber="11" covered="true"/> | ||
<lineToCover lineNumber="12" covered="true"/> | ||
<lineToCover lineNumber="13" covered="true"/> | ||
<lineToCover lineNumber="14" covered="true"/> | ||
<lineToCover lineNumber="15" covered="true"/> | ||
<lineToCover lineNumber="16" covered="true"/> | ||
<lineToCover lineNumber="17" covered="true"/> | ||
<lineToCover lineNumber="18" covered="true"/> | ||
<lineToCover lineNumber="19" covered="true"/> | ||
<lineToCover lineNumber="20" covered="true"/> | ||
<lineToCover lineNumber="21" covered="true"/> | ||
<lineToCover lineNumber="22" covered="true"/> | ||
<lineToCover lineNumber="23" covered="true"/> | ||
<lineToCover lineNumber="24" covered="true"/> | ||
<lineToCover lineNumber="25" covered="true"/> | ||
<lineToCover lineNumber="26" covered="true"/> | ||
<lineToCover lineNumber="27" covered="true"/> | ||
</file> | ||
<file path="force-app/main/default/classes/AccountProfile.cls"> | ||
<lineToCover lineNumber="52" covered="false"/> | ||
<lineToCover lineNumber="53" covered="false"/> | ||
<lineToCover lineNumber="59" covered="false"/> | ||
<lineToCover lineNumber="60" covered="false"/> | ||
<lineToCover lineNumber="54" covered="true"/> | ||
<lineToCover lineNumber="55" covered="true"/> | ||
<lineToCover lineNumber="56" covered="true"/> | ||
<lineToCover lineNumber="57" covered="true"/> | ||
<lineToCover lineNumber="58" covered="true"/> | ||
<lineToCover lineNumber="61" covered="true"/> | ||
<lineToCover lineNumber="62" covered="true"/> | ||
<lineToCover lineNumber="63" covered="true"/> | ||
<lineToCover lineNumber="64" covered="true"/> | ||
<lineToCover lineNumber="65" covered="true"/> | ||
<lineToCover lineNumber="66" covered="true"/> | ||
<lineToCover lineNumber="67" covered="true"/> | ||
<lineToCover lineNumber="68" covered="true"/> | ||
<lineToCover lineNumber="69" covered="true"/> | ||
<lineToCover lineNumber="70" covered="true"/> | ||
<lineToCover lineNumber="71" covered="true"/> | ||
<lineToCover lineNumber="72" covered="true"/> | ||
<lineToCover lineNumber="1" covered="true"/> | ||
<lineToCover lineNumber="2" covered="true"/> | ||
<lineToCover lineNumber="3" covered="true"/> | ||
<lineToCover lineNumber="4" covered="true"/> | ||
<lineToCover lineNumber="5" covered="true"/> | ||
<lineToCover lineNumber="6" covered="true"/> | ||
<lineToCover lineNumber="7" covered="true"/> | ||
<lineToCover lineNumber="8" covered="true"/> | ||
<lineToCover lineNumber="9" covered="true"/> | ||
<lineToCover lineNumber="10" covered="true"/> | ||
</file> | ||
</coverage> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
# summary | ||
|
||
Transforms the Code Coverage JSON into the Generic Test Data Format (XML). | ||
Transforms the Code Coverage JSON into the Generic Test Coverage Format (XML). | ||
|
||
# description | ||
|
||
This plugin will convert the JSON file created by the Salesforce CLI during Apex deployments | ||
This plugin will convert the code coverage JSON file created by the Salesforce CLI during Apex deployments into an XML accepted by tools like SonarQube. | ||
|
||
# examples | ||
|
||
- `sf apex-code-coverage transformer transform --coverage-json "path-to-cli-coverage.json"` | ||
- `sf apex-code-coverage transformer transform -j "coverage.json" -x "coverage.xml" -c "sfdx-project.json"` | ||
|
||
# flags.sfdx-configuration.summary | ||
|
||
Path to your project's Salesforce DX configuration file (`sfdx-project.json`). By default, it will look for `sfdx-project.json` in the same directory you're running this plugin in. | ||
Path to your project's Salesforce DX configuration file. | ||
|
||
# flags.coverage-json.summary | ||
|
||
Path to the JSON file created by the Salesforce CLI deployment command. | ||
Path to the code coverage JSON file created by the Salesforce CLI deployment command. | ||
|
||
# flags.xml.summary | ||
|
||
XML file created by this plugin (default: `coverage.xml`). | ||
Path to code coverage XML file that will be created by this plugin. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.