-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}` | ||
); | ||
}); | ||
}); |