-
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.
Merge pull request #38 from salesforcecli/mdonnalley/junit
feat: support junit test formatter
- Loading branch information
Showing
9 changed files
with
204 additions
and
30 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 |
---|---|---|
@@ -1,3 +1,11 @@ | ||
# flags.result-format.summary | ||
|
||
Format of the test run results. | ||
|
||
# flags.output-dir.summary | ||
|
||
Directory to write the test results to. | ||
|
||
# flags.output-dir.description | ||
|
||
If test run is complete, write the results to the specified directory. If the tests are still running, the test results will not be written. |
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
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
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,62 @@ | ||
/* | ||
* Copyright (c) 2024, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import { join } from 'node:path'; | ||
import { writeFile, mkdir } from 'node:fs/promises'; | ||
import { AgentTestDetailsResponse, jsonFormat, humanFormat, junitFormat } from '@salesforce/agents'; | ||
import { Ux } from '@salesforce/sf-plugins-core/Ux'; | ||
|
||
async function writeFileToDir(outputDir: string, fileName: string, content: string): Promise<void> { | ||
// if directory doesn't exist, create it | ||
await mkdir(outputDir, { recursive: true }); | ||
|
||
await writeFile(join(outputDir, fileName), content); | ||
} | ||
|
||
export async function handleTestResults({ | ||
id, | ||
format, | ||
results, | ||
jsonEnabled, | ||
outputDir, | ||
}: { | ||
id: string; | ||
format: 'human' | 'json' | 'junit'; | ||
results: AgentTestDetailsResponse | undefined; | ||
jsonEnabled: boolean; | ||
outputDir?: string; | ||
}): Promise<void> { | ||
if (!results) { | ||
// do nothing since there are no results to handle | ||
return; | ||
} | ||
|
||
const ux = new Ux({ jsonEnabled }); | ||
|
||
if (format === 'human') { | ||
const formatted = await humanFormat(results); | ||
ux.log(formatted); | ||
if (outputDir) { | ||
await writeFileToDir(outputDir, `test-result-${id}.txt`, formatted); | ||
} | ||
} | ||
|
||
if (format === 'json') { | ||
const formatted = await jsonFormat(results); | ||
ux.log(formatted); | ||
if (outputDir) { | ||
await writeFileToDir(outputDir, `test-result-${id}.json`, formatted); | ||
} | ||
} | ||
|
||
if (format === 'junit') { | ||
const formatted = await junitFormat(results); | ||
ux.log(formatted); | ||
if (outputDir) { | ||
await writeFileToDir(outputDir, `test-result-${id}.xml`, formatted); | ||
} | ||
} | ||
} |
Oops, something went wrong.