Skip to content

Commit

Permalink
fix: update the hook to allow 2 different JSON paths based on command
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarvin8 committed Jun 10, 2024
1 parent 34718f0 commit f6159be
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ The `.apexcodecovtransformer.config.json` should look like this:

```json
{
"coverageJsonPath": "coverage/coverage/coverage.json",
"deployCoverageJsonPath": "coverage/coverage/coverage.json",
"testCoverageJsonPath": "coverage/test-coverage.json",
"coverageXmlPath": "coverage.xml"
}
```

- `coverageJsonPath` is required and should be the path to the code coverage JSON created by the Salesforce CLI. Recommend using a relative path.
- `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.
- `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.
- `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.

If the `.apexcodecovtransformer.config.json` file isn't found, the hook will be skipped.
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface CoverageObject {
}

export interface ConfigFile {
coverageJsonPath: string;
deployCoverageJsonPath: string;
testCoverageJsonPath: string;
coverageXmlPath: string;
}
8 changes: 7 additions & 1 deletion src/hooks/postrun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getRepoRoot } from '../helpers/getRepoRoot.js';

export const postrun: Hook<'postrun'> = async function (options) {
let commandType: string;
let coverageJson: string;
if (
['project:deploy:validate', 'project:deploy:start', 'project:deploy:report', 'project:deploy:resume'].includes(
options.Command.id
Expand All @@ -33,9 +34,14 @@ export const postrun: Hook<'postrun'> = async function (options) {
return;
}

const coverageJson: string = configFile.coverageJsonPath || '.';
const coverageXml: string = configFile.coverageXmlPath || 'coverage.xml';

if (commandType === 'deploy') {
coverageJson = configFile.deployCoverageJsonPath || '.';
} else {
coverageJson = configFile.testCoverageJsonPath || '.';
}

if (coverageJson.trim() === '.') {
return;
}
Expand Down

0 comments on commit f6159be

Please sign in to comment.