apex-code-coverage-transformer 1.7.3 → 1.7.4

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/README.md CHANGED
@@ -10,16 +10,17 @@ This plugin supports code coverage metrics created for Apex Classes and Apex Tri
10
10
 
11
11
  This plugin is intended for users who deploy their Apex codebase from a git-based repository and use SonarQube for code quality. This plugin will work if you run local tests or run all tests in an org, including tests that originate from installed managed and unlocked packages. SonarQube relies on file-paths to map code coverage to the files in their file explorer interface. Since files from managed and unlocked packages aren't retrieved into git-based Salesforce repositories, these files cannot be included in your SonarQube scans. If your Apex code coverage JSON output includes managed/unlocked package files, they will not be added to the coverage XML created by this plugin. A warning will be printed for each file not found in a package directory in your git repository. See [Errors and Warnings](https://github.com/mcarvin8/apex-code-coverage-transformer?tab=readme-ov-file#errors-and-warnings) for more information.
12
12
 
13
- 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. This will create a coverage JSON in this relative path - `coverage/coverage/coverage.json`.
13
+ 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. This will create a coverage JSON in this relative path - `coverage/coverage/coverage.json`.
14
14
 
15
15
  ```
16
- sf project deploy [start/validate] -x manifest/package.xml -l RunSpecifiedTests -t {testclasses} --verbose --coverage-formatters json --results-dir coverage
16
+ sf project deploy [start/validate] --coverage-formatters json --results-dir "coverage"
17
17
  ```
18
18
 
19
- To create the code coverage JSON when running tests directly in the org, append `-c -r json` to the `sf apex run test` command.
19
+ 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 the a folder named "coverage".
20
20
 
21
21
  ```
22
- sf apex run test -c -r json
22
+ sf apex run test --code-coverage --result-format json --output-dir "coverage"
23
+ sf apex get test --test-run-id <test run id> --code-coverage --result-format json --output-dir "coverage"
23
24
  ```
24
25
 
25
26
  The code coverage JSONs created by the Salesforce CLI aren't accepted by SonarQube automatically for git-based Salesforce repositories and needs to be converted using this plugin.
@@ -65,7 +66,7 @@ EXAMPLES
65
66
 
66
67
  A post-run hook has been configured if you elect to use it.
67
68
 
68
- The post-run hook will automatically transform the code coverage JSON file into a generic test coverage report XML 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` command) if the JSON is found.
69
+ The post-run hook will automatically transform the code coverage JSON file into a generic test coverage report XML 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.
69
70
 
70
71
  The hook requires you to create this file in the root of your repo: `.apexcodecovtransformer.config.json`
71
72
 
@@ -73,12 +74,14 @@ The `.apexcodecovtransformer.config.json` should look like this:
73
74
 
74
75
  ```json
75
76
  {
76
- "coverageJsonPath": "coverage/coverage/coverage.json",
77
+ "deployCoverageJsonPath": "coverage/coverage/coverage.json",
78
+ "testCoverageJsonPath": "coverage/test-coverage.json",
77
79
  "coverageXmlPath": "coverage.xml"
78
80
  }
79
81
  ```
80
82
 
81
- - `coverageJsonPath` is required and should be the path to the code coverage JSON created by the Salesforce CLI. Recommend using a relative path.
83
+ - `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.
84
+ - `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.
82
85
  - `coverageXmlPath` is optional and should be the path to the code coverage XML created by this plugin. Recommend using a relative path. If this isn't provided, it will default to `coverage.xml` in the working directory.
83
86
 
84
87
  If the `.apexcodecovtransformer.config.json` file isn't found, the hook will be skipped.
@@ -3,16 +3,9 @@
3
3
  import { existsSync } from 'node:fs';
4
4
  import { readFile } from 'node:fs/promises';
5
5
  import { resolve } from 'node:path';
6
- import { simpleGit } from 'simple-git';
6
+ import { getRepoRoot } from './getRepoRoot.js';
7
7
  export async function getPackageDirectories() {
8
- const options = {
9
- baseDir: process.cwd(),
10
- binary: 'git',
11
- maxConcurrentProcesses: 6,
12
- trimmed: true,
13
- };
14
- const git = simpleGit(options);
15
- const repoRoot = (await git.revparse('--show-toplevel')).trim();
8
+ const repoRoot = await getRepoRoot();
16
9
  const dxConfigPath = resolve(repoRoot, 'sfdx-project.json');
17
10
  if (!existsSync(dxConfigPath)) {
18
11
  throw Error(`Salesforce DX Config File does not exist in this path: ${dxConfigPath}`);
@@ -1 +1 @@
1
- {"version":3,"file":"getPackageDirectories.js","sourceRoot":"","sources":["../../src/helpers/getPackageDirectories.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,qCAAqC;AAErC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAA+B,MAAM,YAAY,CAAC;AAIpE,MAAM,CAAC,KAAK,UAAU,qBAAqB;IACzC,MAAM,OAAO,GAA8B;QACzC,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE;QACtB,MAAM,EAAE,KAAK;QACb,sBAAsB,EAAE,CAAC;QACzB,OAAO,EAAE,IAAI;KACd,CAAC;IACF,MAAM,GAAG,GAAc,SAAS,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,QAAQ,GAAG,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAChE,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC;IAC5D,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QAC9B,MAAM,KAAK,CAAC,0DAA0D,YAAY,EAAE,CAAC,CAAC;IACx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AAE,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IAChH,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,CAAC;AAC1C,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function getRepoRoot(): Promise<string>;
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+ import { simpleGit } from 'simple-git';
3
+ export async function getRepoRoot() {
4
+ const gitOptions = {
5
+ baseDir: process.cwd(),
6
+ binary: 'git',
7
+ maxConcurrentProcesses: 6,
8
+ trimmed: true,
9
+ };
10
+ const git = simpleGit(gitOptions);
11
+ const repoRoot = (await git.revparse('--show-toplevel')).trim();
12
+ return repoRoot;
13
+ }
14
+ //# sourceMappingURL=getRepoRoot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRepoRoot.js","sourceRoot":"","sources":["../../src/helpers/getRepoRoot.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,SAAS,EAA+B,MAAM,YAAY,CAAC;AAEpE,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,MAAM,UAAU,GAA8B;QAC5C,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE;QACtB,MAAM,EAAE,KAAK;QACb,sBAAsB,EAAE,CAAC;QACzB,OAAO,EAAE,IAAI;KACd,CAAC;IAEF,MAAM,GAAG,GAAc,SAAS,CAAC,UAAU,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAChE,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -46,7 +46,8 @@ export interface CoverageObject {
46
46
  };
47
47
  }
48
48
  export interface ConfigFile {
49
- coverageJsonPath: string;
49
+ deployCoverageJsonPath: string;
50
+ testCoverageJsonPath: string;
50
51
  coverageXmlPath: string;
51
52
  }
52
53
  export {};
@@ -2,28 +2,22 @@
2
2
  import { existsSync } from 'node:fs';
3
3
  import { readFile } from 'node:fs/promises';
4
4
  import { resolve } from 'node:path';
5
- import { simpleGit } from 'simple-git';
6
5
  import TransformerTransform from '../commands/apex-code-coverage/transformer/transform.js';
6
+ import { getRepoRoot } from '../helpers/getRepoRoot.js';
7
7
  export const postrun = async function (options) {
8
8
  let commandType;
9
+ let coverageJson;
9
10
  if (['project:deploy:validate', 'project:deploy:start', 'project:deploy:report', 'project:deploy:resume'].includes(options.Command.id)) {
10
11
  commandType = 'deploy';
11
12
  }
12
- else if (['apex:run:test'].includes(options.Command.id)) {
13
+ else if (['apex:run:test', 'apex:get:test'].includes(options.Command.id)) {
13
14
  commandType = 'test';
14
15
  }
15
16
  else {
16
17
  return;
17
18
  }
18
19
  let configFile;
19
- const gitOptions = {
20
- baseDir: process.cwd(),
21
- binary: 'git',
22
- maxConcurrentProcesses: 6,
23
- trimmed: true,
24
- };
25
- const git = simpleGit(gitOptions);
26
- const repoRoot = (await git.revparse('--show-toplevel')).trim();
20
+ const repoRoot = await getRepoRoot();
27
21
  const configPath = resolve(repoRoot, '.apexcodecovtransformer.config.json');
28
22
  try {
29
23
  const jsonString = await readFile(configPath, 'utf-8');
@@ -32,8 +26,13 @@ export const postrun = async function (options) {
32
26
  catch (error) {
33
27
  return;
34
28
  }
35
- const coverageJson = configFile.coverageJsonPath || '.';
36
29
  const coverageXml = configFile.coverageXmlPath || 'coverage.xml';
30
+ if (commandType === 'deploy') {
31
+ coverageJson = configFile.deployCoverageJsonPath || '.';
32
+ }
33
+ else {
34
+ coverageJson = configFile.testCoverageJsonPath || '.';
35
+ }
37
36
  if (coverageJson.trim() === '.') {
38
37
  return;
39
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"postrun.js","sourceRoot":"","sources":["../../src/hooks/postrun.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,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IAED,MAAM,WAAW,GAAa,EAAE,CAAC;IACjC,WAAW,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACpC,WAAW,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACnC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1B,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAClC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC9B,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC9B,MAAM,oBAAoB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AAC9C,CAAC,CAAC"}
@@ -77,5 +77,5 @@
77
77
  ]
78
78
  }
79
79
  },
80
- "version": "1.7.3"
80
+ "version": "1.7.4"
81
81
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "apex-code-coverage-transformer",
3
- "description": "Transforms the Apex code coverage JSON created during Salesforce deployments into the Generic Test Coverage Format (XML).",
4
- "version": "1.7.3",
3
+ "description": "Transforms the Apex code coverage JSON created during Salesforce deployments and test runs into the Generic Test Coverage Format (XML) for SonarQube.",
4
+ "version": "1.7.4",
5
5
  "dependencies": {
6
6
  "@oclif/core": "^3.18.1",
7
7
  "@salesforce/core": "^6.4.7",