From f6159be3fe12801a00c06f44a5304cab2d02697e Mon Sep 17 00:00:00 2001 From: Matt Carvin <90224411+mcarvin8@users.noreply.github.com> Date: Sun, 9 Jun 2024 20:17:51 -0400 Subject: [PATCH] fix: update the hook to allow 2 different JSON paths based on command --- README.md | 6 ++++-- src/helpers/types.ts | 3 ++- src/hooks/postrun.ts | 8 +++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fd148ba..ddab978 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/helpers/types.ts b/src/helpers/types.ts index e2db154..bda6178 100644 --- a/src/helpers/types.ts +++ b/src/helpers/types.ts @@ -49,6 +49,7 @@ export interface CoverageObject { } export interface ConfigFile { - coverageJsonPath: string; + deployCoverageJsonPath: string; + testCoverageJsonPath: string; coverageXmlPath: string; } diff --git a/src/hooks/postrun.ts b/src/hooks/postrun.ts index 7ea6afd..0b8e43a 100644 --- a/src/hooks/postrun.ts +++ b/src/hooks/postrun.ts @@ -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 @@ -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; }