diff --git a/.github/workflows/non-release-build.yml b/.github/workflows/non-release-build.yml deleted file mode 100644 index 0b51cbd..0000000 --- a/.github/workflows/non-release-build.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: Build - Non-Release - -on: - push: - branches-ignore: - - main - -jobs: - unit-tests: - uses: salesforcecli/github-workflows/.github/workflows/unitTest.yml@main diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fffa30a..05ce9de 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,9 +10,18 @@ permissions: jobs: unit-tests: uses: salesforcecli/github-workflows/.github/workflows/unitTest.yml@main - + nuts: + needs: unit-tests + uses: salesforcecli/github-workflows/.github/workflows/nut.yml@main + secrets: inherit + strategy: + matrix: + os: [windows-latest] + fail-fast: false + with: + os: ${{ matrix.os }} release: - needs: [unit-tests] + needs: [unit-tests, nuts] name: Release runs-on: ubuntu-latest steps: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..318ab31 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,20 @@ +name: Test + +on: + push: + branches-ignore: + - main + +jobs: + unit-tests: + uses: salesforcecli/github-workflows/.github/workflows/unitTest.yml@main + nuts: + needs: unit-tests + uses: salesforcecli/github-workflows/.github/workflows/nut.yml@main + secrets: inherit + strategy: + matrix: + os: [windows-latest] + fail-fast: false + with: + os: ${{ matrix.os }} diff --git a/README.md b/README.md index f595070..1b9d279 100644 --- a/README.md +++ b/README.md @@ -35,15 +35,15 @@ sf plugins install apex-code-coverage-transformer@x.y.z The `apex-code-coverage-transformer` has 1 command: -- `sf apex-code-coverage transformer transform` +- `sf acc-transformer transform` This command needs to be ran somewhere inside your Salesforce DX git repository, whether in the root folder (recommended) or in a subfolder. This plugin will determine the root folder of this repository and read the `sfdx-project.json` file in the root folder. All package directories listed in the `sfdx-project.json` file will be processed when running this plugin. -## `sf apex-code-coverage transformer transform` +## `sf acc-transformer transform` ``` USAGE - $ sf apex-code-coverage transformer transform -j -x -c [--json] + $ sf acc-transformer transform -j -x -c [--json] FLAGS -j, --coverage-json= Path to the code coverage JSON file created by the Salesforce CLI deployment or test command. @@ -57,7 +57,7 @@ DESCRIPTION This plugin will convert the code coverage JSON file created by the Salesforce CLI during Apex deployments and test runs into an XML accepted by tools like SonarQube. EXAMPLES - $ sf apex-code-coverage transformer transform -j "coverage.json" -x "coverage.xml" -c "deploy" + $ sf acc-transformer transform -j "coverage.json" -x "coverage.xml" -c "deploy" ``` ## Hook diff --git a/messages/transformer.transform.md b/messages/transformer.transform.md index 5c8b1ad..c4fdc9e 100644 --- a/messages/transformer.transform.md +++ b/messages/transformer.transform.md @@ -8,7 +8,7 @@ This plugin will convert the code coverage JSON file created by the Salesforce C # examples -- `sf apex-code-coverage transformer transform -j "coverage.json" -x "coverage.xml" -c "deploy"` +- `sf acc-transformer transform -j "coverage.json" -x "coverage.xml" -c "deploy"` # flags.coverage-json.summary diff --git a/package.json b/package.json index ecd6449..695e514 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,11 @@ "commands": "./lib/commands", "bin": "sf", "topicSeparator": " ", + "topics": { + "acc-transformer": { + "description": "description for acc-transformer" + } + }, "hooks": { "postrun": "./lib/hooks/postrun" }, @@ -65,7 +70,7 @@ "clean": "sf-clean", "clean-all": "sf-clean all", "clean:lib": "shx rm -rf lib && shx rm -rf coverage && shx rm -rf .nyc_output && shx rm -f oclif.manifest.json oclif.lock", - "compile": "sf-compile", + "compile": "wireit", "docs": "sf-docs", "format": "sf-format", "lint": "wireit", diff --git a/src/commands/apex-code-coverage/transformer/transform.ts b/src/commands/acc-transformer/transform.ts similarity index 88% rename from src/commands/apex-code-coverage/transformer/transform.ts rename to src/commands/acc-transformer/transform.ts index 2229454..55877ec 100644 --- a/src/commands/apex-code-coverage/transformer/transform.ts +++ b/src/commands/acc-transformer/transform.ts @@ -5,10 +5,9 @@ import { writeFile, readFile } from 'node:fs/promises'; import { SfCommand, Flags } from '@salesforce/sf-plugins-core'; import { Messages } from '@salesforce/core'; -import { DeployCoverageData, TestCoverageData } from '../../../helpers/types.js'; -import { transformDeployCoverageReport } from '../../../helpers/transformDeployCoverageReport.js'; -import { transformTestCoverageReport } from '../../../helpers/transformTestCoverageReport.js'; -import { TransformerTransformResult } from '../../../helpers/types.js'; +import { DeployCoverageData, TestCoverageData, TransformerTransformResult } from '../../helpers/types.js'; +import { transformDeployCoverageReport } from '../../helpers/transformDeployCoverageReport.js'; +import { transformTestCoverageReport } from '../../helpers/transformTestCoverageReport.js'; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); const messages = Messages.loadMessages('apex-code-coverage-transformer', 'transformer.transform'); diff --git a/src/hooks/postrun.ts b/src/hooks/postrun.ts index 0b8e43a..f890f0c 100644 --- a/src/hooks/postrun.ts +++ b/src/hooks/postrun.ts @@ -5,7 +5,7 @@ import { readFile } from 'node:fs/promises'; import { resolve } from 'node:path'; import { Hook } from '@oclif/core'; -import TransformerTransform from '../commands/apex-code-coverage/transformer/transform.js'; +import TransformerTransform from '../commands/acc-transformer/transform.js'; import { ConfigFile } from '../helpers/types.js'; import { getRepoRoot } from '../helpers/getRepoRoot.js'; diff --git a/test/commands/acc-transformer/transform.nut.ts b/test/commands/acc-transformer/transform.nut.ts new file mode 100644 index 0000000..d66300b --- /dev/null +++ b/test/commands/acc-transformer/transform.nut.ts @@ -0,0 +1,86 @@ +'use strict'; + +import { copyFile, writeFile, readFile, rm, mkdir } from 'node:fs/promises'; +import { strictEqual } from 'node:assert'; +import { resolve } from 'node:path'; + +import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; +import { expect } from 'chai'; + +describe('acc-transformer transform NUTs', () => { + let session: TestSession; + const baselineClassPath = resolve('test/baselines/classes/AccountProfile.cls'); + const baselineTriggerPath = resolve('test/baselines/triggers/AccountTrigger.trigger'); + const deployCoverageNoExts = resolve('test/deploy_coverage_no_file_exts.json'); + const deployCoverageWithExts = resolve('test/deploy_coverage_with_file_exts.json'); + const testCoverage = resolve('test/test_coverage.json'); + const baselineXmlPath = resolve('test/coverage_baseline.xml'); + const testXmlPath1 = resolve('coverage1.xml'); + const testXmlPath2 = resolve('coverage2.xml'); + const testXmlPath3 = resolve('coverage3.xml'); + + const configFile = { + packageDirectories: [{ path: 'force-app', default: true }, { path: 'packaged' }], + namespace: '', + sfdcLoginUrl: 'https://login.salesforce.com', + sourceApiVersion: '58.0', + }; + const configJsonString = JSON.stringify(configFile, null, 2); + + before(async () => { + session = await TestSession.create({ devhubAuthStrategy: 'NONE' }); + await writeFile('sfdx-project.json', configJsonString); + await mkdir('force-app/main/default/classes', { recursive: true }); + await mkdir('packaged/triggers', { recursive: true }); + await copyFile(baselineClassPath, 'force-app/main/default/classes/AccountProfile.cls'); + await copyFile(baselineTriggerPath, 'packaged/triggers/AccountTrigger.trigger'); + }); + + after(async () => { + await session?.clean(); + await rm('sfdx-project.json'); + await rm('force-app/main/default/classes/AccountProfile.cls'); + await rm('packaged/triggers/AccountTrigger.trigger'); + await rm('force-app', { recursive: true }); + await rm('packaged', { recursive: true }); + await rm(testXmlPath1); + await rm(testXmlPath2); + await rm(testXmlPath3); + }); + + it('runs transform on the deploy coverage file without file extensions.', async () => { + const command = `acc-transformer transform --coverage-json "${deployCoverageNoExts}" --xml "${testXmlPath1}"`; + const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout; + + expect(output.replace('\n', '')).to.equal(`The coverage XML has been written to ${testXmlPath1}`); + }); + + it('runs transform on the deploy coverage file with file extensions.', async () => { + const command = `acc-transformer transform --coverage-json "${deployCoverageWithExts}" --xml "${testXmlPath2}"`; + const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout; + + expect(output.replace('\n', '')).to.equal(`The coverage XML has been written to ${testXmlPath2}`); + }); + + it('runs transform on the test coverage file.', async () => { + const command = `acc-transformer transform --coverage-json "${testCoverage}" --xml "${testXmlPath3}"`; + const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout; + + expect(output.replace('\n', '')).to.equal(`The coverage XML has been written to ${testXmlPath3}`); + }); + it('confirm the 2 XML files created in the previous tests are the same as the baseline.', async () => { + const xmlContent1 = await readFile(testXmlPath1, 'utf-8'); + const xmlContent2 = await readFile(testXmlPath2, 'utf-8'); + const baselineXmlContent = await readFile(baselineXmlPath, 'utf-8'); + strictEqual( + xmlContent1, + baselineXmlContent, + `File content is different between ${testXmlPath1} and ${baselineXmlPath}` + ); + strictEqual( + xmlContent2, + baselineXmlContent, + `File content is different between ${testXmlPath2} and ${baselineXmlPath}` + ); + }); +}); diff --git a/test/commands/transformer/unit.test.ts b/test/commands/acc-transformer/transform.test.ts similarity index 97% rename from test/commands/transformer/unit.test.ts rename to test/commands/acc-transformer/transform.test.ts index 9e6ff73..eede321 100644 --- a/test/commands/transformer/unit.test.ts +++ b/test/commands/acc-transformer/transform.test.ts @@ -7,7 +7,7 @@ import { resolve } from 'node:path'; import { TestContext } from '@salesforce/core/lib/testSetup.js'; import { expect } from 'chai'; import { stubSfCommandUx } from '@salesforce/sf-plugins-core'; -import TransformerTransform from '../../../src/commands/apex-code-coverage/transformer/transform.js'; +import TransformerTransform from '../../../src/commands/acc-transformer/transform.js'; describe('main', () => { const $$ = new TestContext();