apex-code-coverage-transformer 2.16.0 → 2.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@
5
5
 
6
6
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
7
7
 
8
+ ## [2.16.1](https://github.com/mcarvin8/apex-code-coverage-transformer/compare/v2.16.0...v2.16.1) (2026-02-02)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **deps:** bump @salesforce/core from 8.24.0 to 8.25.0 ([#256](https://github.com/mcarvin8/apex-code-coverage-transformer/issues/256)) ([06ab8ea](https://github.com/mcarvin8/apex-code-coverage-transformer/commit/06ab8ead5d92dc1024fc6de5d6c2b78e78cfdcd7))
14
+
8
15
  ## [2.16.0](https://github.com/mcarvin8/apex-code-coverage-transformer/compare/v2.15.2...v2.16.0) (2026-01-26)
9
16
 
10
17
 
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # `apex-code-coverage-transformer`
1
+ # apex-code-coverage-transformer
2
2
 
3
3
  [![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)
4
4
  [![Downloads/week](https://img.shields.io/npm/dw/apex-code-coverage-transformer.svg)](https://npmjs.org/package/apex-code-coverage-transformer)
@@ -7,34 +7,41 @@
7
7
  [![Code Coverage](https://qlty.sh/badges/11057a07-84da-41af-91fb-b3476e404242/test_coverage.svg)](https://qlty.sh/gh/mcarvin8/projects/apex-code-coverage-transformer)
8
8
  [![Known Vulnerabilities](https://snyk.io//test/github/mcarvin8/apex-code-coverage-transformer/badge.svg?targetFile=package.json)](https://snyk.io//test/github/mcarvin8/apex-code-coverage-transformer?targetFile=package.json)
9
9
 
10
+ A Salesforce CLI plugin that converts Apex code coverage JSON (from deploy or test runs) into formats used by SonarQube, Codecov, GitHub, GitLab, Azure DevOps, Bitbucket, and other tools. Use it to keep coverage in sync with your CI/CD and code quality pipelines.
11
+
12
+ > Missing an output format via `--format`? Open an [issue](https://github.com/mcarvin8/apex-code-coverage-transformer/issues) or submit a [pull request](https://github.com/mcarvin8/apex-code-coverage-transformer/blob/main/CONTRIBUTING.md).
13
+
10
14
  <!-- TABLE OF CONTENTS -->
11
15
  <details>
12
16
  <summary>Table of Contents</summary>
13
17
 
18
+ - [Prerequisites](#prerequisites)
14
19
  - [Install](#install)
15
20
  - [Quick Start](#quick-start)
16
21
  - [Usage](#usage)
17
22
  - [Salesforce CLI](#salesforce-cli)
18
23
  - [SFDX Hardis](#sfdx-hardis)
19
- - [Fixes and Enhancements](#fixes-and-enhancements)
20
- - [Command](#command)
21
- - [`sf acc-transformer transform`](#sf-acc-transformer-transform)
24
+ - [What This Plugin Fixes and Adds](#what-this-plugin-fixes-and-adds)
25
+ - [Command Reference](#command-reference)
26
+ - [sf acc-transformer transform](#sf-acc-transformer-transform)
22
27
  - [Coverage Report Formats](#coverage-report-formats)
23
- - [CI/CD Integration Examples](#cicd-integration-examples)
28
+ - [CI/CD Integration](#cicd-integration)
24
29
  - [Codecov](#codecov)
25
30
  - [SonarQube](#sonarqube)
26
31
  - [GitHub Actions](#github-actions)
27
32
  - [GitLab CI](#gitlab-ci)
28
- - [Hook](#hook)
33
+ - [Automatic Transformation (Hook)](#automatic-transformation-hook)
29
34
  - [Troubleshooting](#troubleshooting)
30
- - [Issues](#issues)
31
35
  - [Contributing](#contributing)
32
36
  - [License](#license)
33
37
  </details>
34
38
 
35
- Transform the Salesforce Apex code coverage JSON files created during deployments and test runs into other [formats](#coverage-report-formats) accepted by SonarQube, Codecov, GitHub, GitLab, Azure, Bitbucket, etc.
39
+ ## Prerequisites
36
40
 
37
- > 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.
41
+ - [Salesforce CLI](https://developer.salesforce.com/tools/sfdxcli) (`sf`) installed
42
+ - Node.js 20.x or later
43
+ - A Salesforce DX project with `sfdx-project.json` and package directories
44
+ - Use only the **json** coverage formatter from the Salesforce CLI; other formatters are not supported
38
45
 
39
46
  ## Install
40
47
 
@@ -44,226 +51,144 @@ sf plugins install apex-code-coverage-transformer@x.y.z
44
51
 
45
52
  ## Quick Start
46
53
 
47
- 1. **Generate Salesforce code coverage in JSON format**:
48
-
49
- **Option A - Run Apex tests directly**:
54
+ 1. **Generate Apex code coverage (JSON)**
55
+ From tests:
50
56
 
51
57
  ```bash
52
58
  sf apex run test --code-coverage --output-dir "coverage"
53
59
  ```
54
60
 
55
- **Option B - Deploy/validate with coverage**:
61
+ Or from deploy/validate:
56
62
 
57
63
  ```bash
58
64
  sf project deploy start --coverage-formatters json --results-dir "coverage"
59
- # or for validation
60
- sf project deploy validate --coverage-formatters json --results-dir "coverage"
65
+ # or: sf project deploy validate --coverage-formatters json --results-dir "coverage"
61
66
  ```
62
67
 
63
- 2. **Transform the coverage to your desired format**:
64
-
65
- **For test command** (creates `coverage/test-result-codecoverage.json`):
68
+ 2. **Transform to your target format**
69
+ Test output → `coverage/test-result-codecoverage.json`. Deploy output → `coverage/coverage/coverage.json`.
66
70
 
67
71
  ```bash
68
- # For SonarQube
72
+ # SonarQube
69
73
  sf acc-transformer transform -j "coverage/test-result-codecoverage.json" -r "coverage.xml" -f "sonar"
70
74
 
71
- # For Codecov
75
+ # Codecov (Cobertura)
72
76
  sf acc-transformer transform -j "coverage/test-result-codecoverage.json" -r "coverage.xml" -f "cobertura"
73
77
 
74
- # For multiple formats at once
78
+ # Multiple formats
75
79
  sf acc-transformer transform -j "coverage/test-result-codecoverage.json" -f "sonar" -f "cobertura" -f "jacoco"
76
80
  ```
77
81
 
78
- **For deploy command** (creates `coverage/coverage/coverage.json`):
79
-
80
- ```bash
81
- # For SonarQube
82
- sf acc-transformer transform -j "coverage/coverage/coverage.json" -r "coverage.xml" -f "sonar"
83
-
84
- # For Codecov
85
- sf acc-transformer transform -j "coverage/coverage/coverage.json" -r "coverage.xml" -f "cobertura"
86
- ```
87
-
88
- 3. **Upload to your coverage tool** (see [CI/CD Integration Examples](#cicd-integration-examples) for platform-specific instructions).
82
+ 3. **Upload to your tool**
83
+ See [CI/CD Integration](#cicd-integration) for Codecov, SonarQube, GitHub Actions, and GitLab.
89
84
 
90
85
  ## Usage
91
86
 
92
- 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.
87
+ This plugin is for Salesforce DX projects (`sfdx-project.json`). It maps Apex names in the CLI coverage JSON to file paths in your package directories and only includes files that exist in those directories. Apex from managed or unlocked packages (not in your repo) is excluded and reported with a [warning](#troubleshooting).
93
88
 
94
- 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](#troubleshooting).
95
-
96
- To automate coverage transformation after deployments or test executions, see [Hook](#hook).
89
+ To run transformation automatically after deploy or test commands, use the [Hook](#automatic-transformation-hook).
97
90
 
98
91
  ### Salesforce CLI
99
92
 
100
- > This plugin will only support the "json" coverage format from the Salesforce CLI. Do not use other coverage formats from the Salesforce CLI.
101
-
102
- 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`.
93
+ **Deploy/validate** coverage path: `coverage/coverage/coverage.json`
103
94
 
104
- ```
105
- sf project deploy [start/validate/report/resume] --coverage-formatters json --results-dir "coverage"
95
+ ```bash
96
+ sf project deploy [start|validate|report|resume] --coverage-formatters json --results-dir "coverage"
106
97
  ```
107
98
 
108
- 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`
99
+ **Run tests** coverage path: `coverage/test-result-codecoverage.json`
109
100
 
110
- ```
101
+ ```bash
111
102
  sf apex run test --code-coverage --output-dir "coverage"
112
- sf apex get test --test-run-id <test run id> --code-coverage --output-dir "coverage"
103
+ sf apex get test --test-run-id <id> --code-coverage --output-dir "coverage"
113
104
  ```
114
105
 
115
106
  ### SFDX Hardis
116
107
 
117
- This plugin can be used after running the below [sfdx-hardis](https://github.com/hardisgroupcom/sfdx-hardis) commands:
108
+ Works with [sfdx-hardis](https://github.com/hardisgroupcom/sfdx-hardis):
118
109
 
119
- - `sf hardis project deploy smart` (only if `COVERAGE_FORMATTER_JSON=true` environment variable is defined)
110
+ - `sf hardis project deploy smart` (when `COVERAGE_FORMATTER_JSON=true`)
120
111
  - `sf hardis org test apex`
121
112
 
122
- Both hardis commands will create the code coverage JSON to transform here: `hardis-report/apex-coverage-results.json`.
123
-
124
- ## Fixes and Enhancements
113
+ Coverage file: `hardis-report/apex-coverage-results.json`.
125
114
 
126
- - **Maps Apex file names** in the original coverage report (e.g., `no-map/AccountTriggerHandler`) to their corresponding relative file paths in the Salesforce DX project (e.g., `force-app/main/default/classes/AccountTriggerHandler.cls`).
127
- - **Normalizes coverage reports** across both deploy and test commands, improving compatibility with external tools.
128
- - **Adds additional coverage formats** not available in the default Salesforce CLI deploy and test commands.
129
- - **"Fixes" inaccuracies** in Salesforce CLI deploy command coverage reports, such as out-of-range covered lines (e.g., line 100 reported as "covered" in a 98-line Apex class) and incorrect total line counts (e.g., 120 lines reported for a 100-line Apex class).
130
- - To address these inaccuracies, the plugin includes a **re-numbering function** that only applies to deploy coverage reports. This function reassigns out-of-range `covered` lines to unused lines, ensuring reports are accepted by external tools.
131
- - The `uncovered` lines are always correctly reported by the deploy command.
132
- - Once Salesforce resolves the issue with the API that affects deploy command coverage reports, the re-numbering function will be removed in a future **breaking** release.
133
- - See issues [5511](https://github.com/forcedotcom/salesforcedx-vscode/issues/5511) and [1568](https://github.com/forcedotcom/cli/issues/1568) for more details.
134
- - **Note**: This does not affect coverage reports generated by the Salesforce CLI test commands.
115
+ ## What This Plugin Fixes and Adds
135
116
 
136
- ## Command
117
+ - **File mapping** — Maps names like `no-map/AccountTriggerHandler` to paths like `force-app/main/default/classes/AccountTriggerHandler.cls`.
118
+ - **Normalization** — Aligns deploy and test coverage structures so external tools can consume them.
119
+ - **Extra formats** — Outputs Sonar, Cobertura, JaCoCo, LCOV, Clover, and more (see [Coverage Report Formats](#coverage-report-formats)).
120
+ - **Deploy-coverage fixes** — Corrects known CLI issues (e.g. out-of-range covered lines, wrong line counts) by re-numbering covered lines in deploy reports. Uncovered lines are already correct. This workaround will be removed in a future **breaking** release once Salesforce fixes the API; see [forcedotcom/salesforcedx-vscode#5511](https://github.com/forcedotcom/salesforcedx-vscode/issues/5511) and [forcedotcom/cli#1568](https://github.com/forcedotcom/cli/issues/1568). Test-command coverage is unaffected.
137
121
 
138
- The `apex-code-coverage-transformer` has 1 command:
122
+ ## Command Reference
139
123
 
140
- - `sf acc-transformer transform`
124
+ Single command: `sf acc-transformer transform`.
141
125
 
142
- ## `sf acc-transformer transform`
126
+ ### sf acc-transformer transform
143
127
 
144
128
  ```
145
129
  USAGE
146
130
  $ sf acc-transformer transform -j <value> [-r <value>] [-f <value>] [-i <value>] [--json]
147
131
 
148
132
  FLAGS
149
- -j, --coverage-json=<value> Path to the code coverage JSON file created by the Salesforce CLI deploy or test command.
150
- -r, --output-report=<value> Path to the code coverage file that will be created by this plugin.
151
- [default: "coverage.[xml/info]"]
152
- -f, --format=<value> Output format for the code coverage format.
153
- Can be declared multiple times.
154
- If declared multiple times, the output report will have the format appended to the file-name, i.e. `coverage-sonar.xml`
155
- [default: "sonar"]
156
- -i, --ignore-package-directory=<value> Package directory to ignore when looking for matching files in the coverage report.
157
- Should be as they appear in the "sfdx-project.json".
158
- Can be declared multiple times.
133
+ -j, --coverage-json=<value> Path to the code coverage JSON from deploy or test.
134
+ -r, --output-report=<value> Output path (e.g. coverage.xml). Default: coverage.[xml|info] by format.
135
+ -f, --format=<value> Output format (repeat for multiple). Default: sonar.
136
+ Multiple formats append to filename, e.g. coverage-sonar.xml.
137
+ -i, --ignore-package-directory=<value> Package directory to ignore (as in sfdx-project.json). Repeatable.
159
138
 
160
139
  GLOBAL FLAGS
161
- --json Format output as json.
162
-
163
- EXAMPLES
164
- Transform the JSON into Sonar format:
165
-
166
- $ sf acc-transformer transform -j "coverage.json" -r "coverage.xml" -f "sonar"
167
-
168
- Transform the JSON into Cobertura format:
169
-
170
- $ sf acc-transformer transform -j "coverage.json" -r "coverage.xml" -f "cobertura"
171
-
172
- Transform the JSON into Clover format:
173
-
174
- $ sf acc-transformer transform -j "coverage.json" -r "coverage.xml" -f "clover"
175
-
176
- Transform the JSON into LCovOnly format:
177
-
178
- $ sf acc-transformer transform -j "coverage.json" -r "coverage.info" -f "lcovonly"
179
-
180
- Transform the JSON into JSON Summary format:
181
-
182
- $ sf acc-transformer transform -j "coverage.json" -r "coverage.json" -f "json-summary"
183
-
184
- Transform the JSON into SimpleCov format:
185
-
186
- $ sf acc-transformer transform -j "coverage.json" -r "coverage.json" -f "simplecov"
187
-
188
- Transform the JSON into OpenCover format:
189
-
190
- $ sf acc-transformer transform -j "coverage.json" -r "coverage.xml" -f "opencover"
191
-
192
- Transform the JSON into HTML format:
193
-
194
- $ sf acc-transformer transform -j "coverage.json" -r "coverage.html" -f "html"
195
-
196
- Transform the JSON into Sonar format, ignoring Apex in the "force-app" directory:
197
-
198
- $ sf acc-transformer transform -j "coverage.json" -i "force-app"
140
+ --json Output as JSON.
199
141
  ```
200
142
 
201
143
  ## Coverage Report Formats
202
144
 
203
- The `-f`/`--format` flag allows you to specify the format of the transformed coverage report.
145
+ Use `-f` / `--format` to choose the output format. Multiple `-f` values produce multiple files with the format in the name (e.g. `coverage-sonar.xml`, `coverage-cobertura.xml`).
204
146
 
205
- You can provide multiple `--format` flags in a single command to create multiple reports. If multiple `--format` flags are provided, each output report will have the format appended to the name. For example, if `--output-report` is set `coverage.xml` and you supply `--format sonar --format cobertura` to the command, the output reports will be `coverage-sonar.xml` and `coverage-cobertura.xml`.
147
+ | Format | Description | Typical use | Example |
148
+ | ------------ | -------------------------- | --------------------------------------- | -------------------------------------------------------------------------------------- |
149
+ | sonar | SonarQube generic coverage | SonarQube, SonarCloud | `sf acc-transformer transform -j "coverage.json" -r "coverage.xml" -f "sonar"` |
150
+ | cobertura | Cobertura XML | Codecov, Azure, Jenkins, GitLab, GitHub | `sf acc-transformer transform -j "coverage.json" -r "coverage.xml" -f "cobertura"` |
151
+ | jacoco | JaCoCo XML | Codecov, Jenkins, Maven, Gradle | `sf acc-transformer transform -j "coverage.json" -r "coverage.xml" -f "jacoco"` |
152
+ | lcovonly | LCOV | Codecov, Coveralls, GitHub | `sf acc-transformer transform -j "coverage.json" -r "coverage.info" -f "lcovonly"` |
153
+ | clover | Clover XML | Bamboo, Bitbucket, Jenkins | `sf acc-transformer transform -j "coverage.json" -r "coverage.xml" -f "clover"` |
154
+ | json | Istanbul JSON | Istanbul/NYC, Codecov | `sf acc-transformer transform -j "coverage.json" -r "coverage.json" -f "json"` |
155
+ | json-summary | JSON summary | Badges, PR comments | `sf acc-transformer transform -j "coverage.json" -r "coverage.json" -f "json-summary"` |
156
+ | simplecov | SimpleCov JSON | Codecov, Ruby tools | `sf acc-transformer transform -j "coverage.json" -r "coverage.json" -f "simplecov"` |
157
+ | opencover | OpenCover XML | Azure DevOps, VS, Codecov | `sf acc-transformer transform -j "coverage.json" -r "coverage.xml" -f "opencover"` |
158
+ | html | HTML report | Browsers, CI artifacts | `sf acc-transformer transform -j "coverage.json" -r "coverage.html" -f "html"` |
206
159
 
207
- | Format | Description | Compatible Platforms/Tools |
208
- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | ---------------------------------------------------------- |
209
- | [sonar](https://raw.githubusercontent.com/mcarvin8/apex-code-coverage-transformer/main/baselines/sonar_baseline.xml) | Generates a SonarQube-compatible coverage report. This is the default option. | SonarQube, SonarCloud |
210
- | [cobertura](https://raw.githubusercontent.com/mcarvin8/apex-code-coverage-transformer/main/baselines/cobertura_baseline.xml) | Creates a Cobertura XML report, a widely used format for coverage reporting. | **Codecov**, Azure DevOps, Jenkins, GitLab, GitHub Actions |
211
- | [jacoco](https://raw.githubusercontent.com/mcarvin8/apex-code-coverage-transformer/main/baselines/jacoco_baseline.xml) | Creates a JaCoCo XML report, the standard for Java projects. | **Codecov**, Jenkins, Maven, Gradle |
212
- | [lcovonly](https://raw.githubusercontent.com/mcarvin8/apex-code-coverage-transformer/main/baselines/lcov_baseline.info) | Outputs coverage data in LCOV format, useful for integrating with LCOV-based tools. | Codecov, Coveralls, GitHub Actions |
213
- | [clover](https://raw.githubusercontent.com/mcarvin8/apex-code-coverage-transformer/main/baselines/clover_baseline.xml) | Produces a Clover XML report format, commonly used with Atlassian tools. | Bamboo, Bitbucket, Jenkins |
214
- | [json](https://raw.githubusercontent.com/mcarvin8/apex-code-coverage-transformer/main/baselines/json_baseline.json) | Generates a Istanbul JSON report compatible with Node.js tooling and coverage visualizers. | Istanbul/NYC, Codecov, custom tools |
215
- | [json-summary](https://raw.githubusercontent.com/mcarvin8/apex-code-coverage-transformer/main/baselines/json-summary_baseline.json) | Generates a concise JSON summary ideal for badges, PR comments, and quick analysis. | GitHub Actions, GitLab CI, Custom Dashboards |
216
- | [simplecov](https://raw.githubusercontent.com/mcarvin8/apex-code-coverage-transformer/main/baselines/simplecov_baseline.json) | Generates SimpleCov JSON format compatible with Ruby coverage tools. | Codecov, SimpleCov, Ruby Tools |
217
- | [opencover](https://raw.githubusercontent.com/mcarvin8/apex-code-coverage-transformer/main/baselines/opencover_baseline.xml) | Generates OpenCover XML format for .NET and Azure DevOps integration. | Azure DevOps, Visual Studio, Codecov, JetBrains Tools |
218
- | html | Generates a human-readable HTML report with interactive file-by-file coverage details. | Web Browsers, CI/CD Artifacts, Local Development |
219
-
220
- ## CI/CD Integration Examples
160
+ ## CI/CD Integration
221
161
 
222
162
  ### Codecov
223
163
 
224
- Codecov accepts multiple formats including Cobertura, JaCoCo, and LCOV. Cobertura is recommended for its wide compatibility.
225
-
226
- **Using Codecov CLI**:
164
+ Cobertura is a good default. **CLI upload:**
227
165
 
228
166
  ```bash
229
- # Generate Salesforce coverage
230
167
  sf apex run test --code-coverage --output-dir "coverage"
231
-
232
- # Transform to Cobertura format
233
168
  sf acc-transformer transform -j "coverage/test-result-codecoverage.json" -r "coverage.xml" -f "cobertura"
234
-
235
- # Upload to Codecov
236
169
  codecovcli upload-process --file coverage.xml
237
170
  ```
238
171
 
239
- **Using Codecov GitHub Action**:
172
+ **GitHub Action:**
240
173
 
241
174
  ```yaml
242
175
  name: Salesforce CI with Codecov
243
-
244
176
  on: [push, pull_request]
245
-
246
177
  jobs:
247
178
  test:
248
179
  runs-on: ubuntu-latest
249
180
  steps:
250
181
  - uses: actions/checkout@v4
251
-
252
182
  - name: Install Salesforce CLI
253
183
  run: npm install -g @salesforce/cli
254
-
255
184
  - name: Install Coverage Transformer Plugin
256
185
  run: sf plugins install apex-code-coverage-transformer
257
-
258
186
  - name: Authenticate to Salesforce
259
187
  run: sf org login sfdx-url --sfdx-url-file ${{ secrets.SFDX_AUTH_URL }} --alias ci-org
260
-
261
188
  - name: Run Apex Tests
262
189
  run: sf apex run test --code-coverage --output-dir coverage --target-org ci-org
263
-
264
190
  - name: Transform Coverage to Cobertura
265
191
  run: sf acc-transformer transform -j "coverage/test-result-codecoverage.json" -r "coverage.xml" -f "cobertura"
266
-
267
192
  - name: Upload to Codecov
268
193
  uses: codecov/codecov-action@v4
269
194
  with:
@@ -274,33 +199,28 @@ jobs:
274
199
 
275
200
  ### SonarQube
276
201
 
277
- SonarQube requires its own Generic Coverage format (Sonar format).
202
+ Use the **sonar** format and upload using SonarQube's generic test coverage report formatter, `sonar.coverageReportPaths`.
278
203
 
279
- **SonarQube Scanner Example**:
204
+ **Scanner:**
280
205
 
281
206
  ```bash
282
- # Generate and transform coverage
283
207
  sf apex run test --code-coverage --output-dir "coverage"
284
208
  sf acc-transformer transform -j "coverage/test-result-codecoverage.json" -r "coverage.xml" -f "sonar"
285
-
286
- # Run SonarQube scanner
287
209
  sonar-scanner \
288
210
  -Dsonar.projectKey=your-project-key \
289
211
  -Dsonar.sources=force-app \
290
212
  -Dsonar.tests=force-app \
291
213
  -Dsonar.test.inclusions=**/*Test.cls \
292
- -Dsonar.apex.coverage.reportPath=coverage.xml \
214
+ -Dsonar.coverageReportPaths=coverage.xml \
293
215
  -Dsonar.host.url=https://sonarqube.example.com \
294
216
  -Dsonar.login=$SONAR_TOKEN
295
217
  ```
296
218
 
297
- **SonarCloud GitHub Action**:
219
+ **SonarCloud GitHub Action:**
298
220
 
299
221
  ```yaml
300
222
  name: SonarCloud Analysis
301
-
302
223
  on: [push, pull_request]
303
-
304
224
  jobs:
305
225
  sonarcloud:
306
226
  runs-on: ubuntu-latest
@@ -308,22 +228,16 @@ jobs:
308
228
  - uses: actions/checkout@v4
309
229
  with:
310
230
  fetch-depth: 0
311
-
312
231
  - name: Install Salesforce CLI
313
232
  run: npm install -g @salesforce/cli
314
-
315
233
  - name: Install Coverage Transformer Plugin
316
234
  run: sf plugins install apex-code-coverage-transformer
317
-
318
235
  - name: Authenticate to Salesforce
319
236
  run: sf org login sfdx-url --sfdx-url-file ${{ secrets.SFDX_AUTH_URL }} --alias ci-org
320
-
321
237
  - name: Run Apex Tests
322
238
  run: sf apex run test --code-coverage --output-dir coverage --target-org ci-org
323
-
324
239
  - name: Transform Coverage to Sonar Format
325
240
  run: sf acc-transformer transform -j "coverage/test-result-codecoverage.json" -r "coverage.xml" -f "sonar"
326
-
327
241
  - name: SonarCloud Scan
328
242
  uses: SonarSource/sonarcloud-github-action@master
329
243
  env:
@@ -336,41 +250,31 @@ jobs:
336
250
  -Dsonar.sources=force-app
337
251
  -Dsonar.tests=force-app
338
252
  -Dsonar.test.inclusions=**/*Test.cls
339
- -Dsonar.apex.coverage.reportPath=coverage.xml
253
+ -Dsonar.coverageReportPaths=coverage.xml
340
254
  ```
341
255
 
342
256
  ### GitHub Actions
343
257
 
344
- GitHub Actions can display coverage using various formats. Use Cobertura or LCOV for best compatibility.
345
-
346
- **With Coverage Report Action**:
258
+ Use Cobertura (or LCOV) with a coverage summary action:
347
259
 
348
260
  ```yaml
349
261
  name: Salesforce CI with Coverage Report
350
-
351
262
  on: [push, pull_request]
352
-
353
263
  jobs:
354
264
  test:
355
265
  runs-on: ubuntu-latest
356
266
  steps:
357
267
  - uses: actions/checkout@v4
358
-
359
268
  - name: Install Salesforce CLI
360
269
  run: npm install -g @salesforce/cli
361
-
362
270
  - name: Install Coverage Transformer Plugin
363
271
  run: sf plugins install apex-code-coverage-transformer
364
-
365
272
  - name: Authenticate to Salesforce
366
273
  run: sf org login sfdx-url --sfdx-url-file ${{ secrets.SFDX_AUTH_URL }} --alias ci-org
367
-
368
274
  - name: Run Apex Tests
369
275
  run: sf apex run test --code-coverage --output-dir coverage --target-org ci-org
370
-
371
276
  - name: Transform Coverage to Cobertura
372
277
  run: sf acc-transformer transform -j "coverage/test-result-codecoverage.json" -r "coverage.xml" -f "cobertura"
373
-
374
278
  - name: Code Coverage Report
375
279
  uses: irongut/CodeCoverageSummary@v1.3.0
376
280
  with:
@@ -378,7 +282,6 @@ jobs:
378
282
  badge: true
379
283
  format: markdown
380
284
  output: both
381
-
382
285
  - name: Add Coverage PR Comment
383
286
  uses: marocchino/sticky-pull-request-comment@v2
384
287
  if: github.event_name == 'pull_request'
@@ -389,9 +292,7 @@ jobs:
389
292
 
390
293
  ### GitLab CI
391
294
 
392
- GitLab supports Cobertura format natively for coverage visualization.
393
-
394
- **`.gitlab-ci.yml` Example**:
295
+ Cobertura for coverage in the UI:
395
296
 
396
297
  ```yaml
397
298
  stages:
@@ -418,75 +319,62 @@ apex-tests:
418
319
  expire_in: 30 days
419
320
  ```
420
321
 
421
- ## Hook
322
+ ## Automatic Transformation (Hook)
422
323
 
423
- To enable automatic transformation after the below `sf` commands complete, create a `.apexcodecovtransformer.config.json` in your project’s root directory.
324
+ Create `.apexcodecovtransformer.config.json` in the project root to transform coverage automatically after:
424
325
 
425
- - `sf project deploy [start/validate/report/resume]`
326
+ - `sf project deploy [start|validate|report|resume]`
426
327
  - `sf apex run test`
427
328
  - `sf apex get test`
428
- - `sf hardis project deploy smart`
429
- - only if `sfdx-hardis` is installed
430
- - `COVERAGE_FORMATTER_JSON=true` must be set in the environment variables
431
- - `sf hardis org test apex`
432
- - only if `sfdx-hardis` is installed
433
-
434
- You can copy & update 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".
329
+ - `sf hardis project deploy smart` (if sfdx-hardis installed and `COVERAGE_FORMATTER_JSON=true`)
330
+ - `sf hardis org test apex` (if sfdx-hardis installed)
435
331
 
436
- You can copy & update 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.
332
+ Sample configs: [Salesforce CLI](https://raw.githubusercontent.com/mcarvin8/apex-code-coverage-transformer/main/defaults/salesforce-cli/.apexcodecovtransformer.config.json), [SFDX Hardis](https://raw.githubusercontent.com/mcarvin8/apex-code-coverage-transformer/main/defaults/sfdx-hardis/.apexcodecovtransformer.config.json).
437
333
 
438
- **`.apexcodecovtransformer.config.json` structure**
439
-
440
- | JSON Key | Required | Description |
441
- | -------------------------- | -------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
442
- | `deployCoverageJsonPath` | Yes (for deploy command) | Code coverage JSON created by the Salesforce CLI deploy commands. |
443
- | `testCoverageJsonPath` | Yes (for test command) | Code coverage JSON created by the Salesforce CLI test commands. |
444
- | `outputReportPath` | No (defaults to `coverage.[xml/info]`) | Transformed code coverage report path. |
445
- | `format` | No (defaults to `sonar`) | Transformed code coverage report [format(s)](#coverage-report-formats). If you're providing multiple formats, provide a comma-separated list, i.e. `sonar,cobertura,jacoco` |
446
- | `ignorePackageDirectories` | No | Comma-separated string of package directories to ignore when looking for matching Apex files. |
334
+ | Key | Required | Description |
335
+ | -------------------------- | ---------- | -------------------------------------------------------- |
336
+ | `deployCoverageJsonPath` | For deploy | Path to deploy coverage JSON. |
337
+ | `testCoverageJsonPath` | For test | Path to test coverage JSON. |
338
+ | `outputReportPath` | No | Output path (default: `coverage.[xml/info/json]` by format). |
339
+ | `format` | No | Format(s), comma-separated (default: `sonar`). |
340
+ | `ignorePackageDirectories` | No | Comma-separated package directories to ignore. |
447
341
 
448
342
  ## Troubleshooting
449
343
 
450
- 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:
344
+ **File not in package directory** File is omitted from the report and a warning is shown:
451
345
 
452
346
  ```
453
347
  Warning: The file name AccountTrigger was not found in any package directory.
454
348
  ```
455
349
 
456
- 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:
350
+ **No files matched** Report will be empty:
457
351
 
458
352
  ```
459
- Warning: The file name AccountTrigger was not found in any package directory.
460
- Warning: The file name AccountProfile was not found in any package directory.
461
353
  Warning: None of the files listed in the coverage JSON were processed. The coverage report will be empty.
462
354
  ```
463
355
 
464
- 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:
356
+ **Unknown JSON structure** Input is not from deploy or test coverage:
465
357
 
466
358
  ```
467
359
  Error (1): The provided JSON does not match a known coverage data format from the Salesforce deploy or test command.
468
360
  ```
469
361
 
470
- If `sfdx-project.json` file is missing from the project root, the plugin will fail with:
362
+ **Missing project config** Run from a directory that has (or has a parent with) `sfdx-project.json`:
471
363
 
472
364
  ```
473
365
  Error (1): sfdx-project.json not found in any parent directory.
474
366
  ```
475
367
 
476
- If a package directory listed in `sfdx-project.json` cannot be found, the plugin will encounter a **ENOENT** error:
368
+ **Missing package directory** A path in `sfdx-project.json` does not exist:
477
369
 
478
370
  ```
479
371
  Error (1): ENOENT: no such file or directory: {packageDir}
480
372
  ```
481
373
 
482
- ## Issues
483
-
484
- If you encounter any issues or would like to suggest features, please create an [issue](https://github.com/mcarvin8/apex-code-coverage-transformer/issues).
485
-
486
374
  ## Contributing
487
375
 
488
- Contributions are welcome! See [Contributing](https://github.com/mcarvin8/apex-code-coverage-transformer/blob/main/CONTRIBUTING.md).
376
+ Contributions are welcome. See [CONTRIBUTING.md](https://github.com/mcarvin8/apex-code-coverage-transformer/blob/main/CONTRIBUTING.md) for setup, testing, and how to add new coverage formats.
489
377
 
490
378
  ## License
491
379
 
492
- This project is licensed under the MIT license. Please see the [LICENSE](https://raw.githubusercontent.com/mcarvin8/apex-code-coverage-transformer/main/LICENSE.md) file for details.
380
+ MIT. See [LICENSE](https://raw.githubusercontent.com/mcarvin8/apex-code-coverage-transformer/main/LICENSE.md).