From aff7b5b77aa403a3f4d309304122ebae7f774408 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Fri, 13 Dec 2024 10:19:46 -0700 Subject: [PATCH] feat: add TAP format --- src/flags.ts | 7 +------ src/handleTestResults.ts | 12 ++++++++++-- ...-evaluations_runs_4KBSM000000003F4AQ_details.json | 2 ++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/flags.ts b/src/flags.ts index 0478cbf..1695172 100644 --- a/src/flags.ts +++ b/src/flags.ts @@ -11,12 +11,7 @@ Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); const messages = Messages.loadMessages('@salesforce/plugin-agent', 'shared'); export const resultFormatFlag = Flags.option({ - options: [ - 'json', - 'human', - 'junit', - // 'tap', - ] as const, + options: ['json', 'human', 'junit', 'tap'] as const, default: 'human', summary: messages.getMessage('flags.result-format.summary'), }); diff --git a/src/handleTestResults.ts b/src/handleTestResults.ts index 0352916..1a6cceb 100644 --- a/src/handleTestResults.ts +++ b/src/handleTestResults.ts @@ -6,7 +6,7 @@ */ import { join } from 'node:path'; import { writeFile, mkdir } from 'node:fs/promises'; -import { AgentTestDetailsResponse, jsonFormat, humanFormat, junitFormat } from '@salesforce/agents'; +import { AgentTestDetailsResponse, jsonFormat, humanFormat, junitFormat, tapFormat } from '@salesforce/agents'; import { Ux } from '@salesforce/sf-plugins-core/Ux'; async function writeFileToDir(outputDir: string, fileName: string, content: string): Promise { @@ -24,7 +24,7 @@ export async function handleTestResults({ outputDir, }: { id: string; - format: 'human' | 'json' | 'junit'; + format: 'human' | 'json' | 'junit' | 'tap'; results: AgentTestDetailsResponse | undefined; jsonEnabled: boolean; outputDir?: string; @@ -59,4 +59,12 @@ export async function handleTestResults({ await writeFileToDir(outputDir, `test-result-${id}.xml`, formatted); } } + + if (format === 'tap') { + const formatted = await tapFormat(results); + ux.log(formatted); + if (outputDir) { + await writeFileToDir(outputDir, `test-result-${id}.txt`, formatted); + } + } } diff --git a/test/mocks/einstein_ai-evaluations_runs_4KBSM000000003F4AQ_details.json b/test/mocks/einstein_ai-evaluations_runs_4KBSM000000003F4AQ_details.json index b895af0..5309372 100644 --- a/test/mocks/einstein_ai-evaluations_runs_4KBSM000000003F4AQ_details.json +++ b/test/mocks/einstein_ai-evaluations_runs_4KBSM000000003F4AQ_details.json @@ -3,6 +3,8 @@ "startTime": "2024-11-28T12:00:00Z", "endTime": "2024-11-28T12:05:00Z", "errorMessage": null, + "subjectName": "Copilot_for_Salesforce", + "testSetName": "CRM_Sanity_v1", "testCases": [ { "status": "COMPLETED",