diff --git a/.github/workflows/non-release-build.yml b/.github/workflows/non-release-build.yml index 0b51cbd..e289529 100644 --- a/.github/workflows/non-release-build.yml +++ b/.github/workflows/non-release-build.yml @@ -8,3 +8,13 @@ on: 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: [ubuntu-latest, windows-latest] + fail-fast: false + with: + os: ${{ matrix.os }} diff --git a/test/commands/transformer/transform.nuts.ts b/test/commands/transformer/transform.nuts.ts new file mode 100644 index 0000000..f5bde39 --- /dev/null +++ b/test/commands/transformer/transform.nuts.ts @@ -0,0 +1,81 @@ +'use strict'; + +import { copyFile, readFile, writeFile, 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('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 sfdxConfigFile = resolve('sfdx-project.json'); + + 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 () => { + 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'); + await writeFile(sfdxConfigFile, configJsonString); + session = await TestSession.create({ devhubAuthStrategy: 'NONE' }); + }); + + after(async () => { + await session?.clean(); + 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); + await rm(sfdxConfigFile); + }); + + it('runs transform on the 1st coverage JSON', async () => { + const command = `apex-code-coverage 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 2nd coverage JSON', async () => { + const command = `apex-code-coverage 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('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}` + ); + }); +});