@@ -3,7 +3,7 @@ import { promises as fs } from 'fs';
33import path from 'path' ;
44import { ConformanceCheck } from '../types' ;
55import { getScenario } from '../scenarios' ;
6- import { ensureResultsDir , createResultDir , formatPrettyChecks } from './utils' ;
6+ import { createResultDir , formatPrettyChecks } from './utils' ;
77
88export interface ClientExecutionResult {
99 exitCode : number ;
@@ -91,15 +91,19 @@ async function executeClient(
9191export async function runConformanceTest (
9292 clientCommand : string ,
9393 scenarioName : string ,
94- timeout : number = 30000
94+ timeout : number = 30000 ,
95+ outputDir ?: string
9596) : Promise < {
9697 checks : ConformanceCheck [ ] ;
9798 clientOutput : ClientExecutionResult ;
98- resultDir : string ;
99+ resultDir ? : string ;
99100} > {
100- await ensureResultsDir ( ) ;
101- const resultDir = createResultDir ( scenarioName ) ;
102- await fs . mkdir ( resultDir , { recursive : true } ) ;
101+ let resultDir : string | undefined ;
102+
103+ if ( outputDir ) {
104+ resultDir = createResultDir ( outputDir , scenarioName ) ;
105+ await fs . mkdir ( resultDir , { recursive : true } ) ;
106+ }
103107
104108 // Scenario is guaranteed to exist by CLI validation
105109 const scenario = getScenario ( scenarioName ) ! ;
@@ -138,16 +142,24 @@ export async function runConformanceTest(
138142
139143 const checks = scenario . getChecks ( ) ;
140144
141- await fs . writeFile (
142- path . join ( resultDir , 'checks.json' ) ,
143- JSON . stringify ( checks , null , 2 )
144- ) ;
145+ if ( resultDir ) {
146+ await fs . writeFile (
147+ path . join ( resultDir , 'checks.json' ) ,
148+ JSON . stringify ( checks , null , 2 )
149+ ) ;
145150
146- await fs . writeFile ( path . join ( resultDir , 'stdout.txt' ) , clientOutput . stdout ) ;
151+ await fs . writeFile (
152+ path . join ( resultDir , 'stdout.txt' ) ,
153+ clientOutput . stdout
154+ ) ;
147155
148- await fs . writeFile ( path . join ( resultDir , 'stderr.txt' ) , clientOutput . stderr ) ;
156+ await fs . writeFile (
157+ path . join ( resultDir , 'stderr.txt' ) ,
158+ clientOutput . stderr
159+ ) ;
149160
150- console . error ( `Results saved to ${ resultDir } ` ) ;
161+ console . error ( `Results saved to ${ resultDir } ` ) ;
162+ }
151163
152164 return {
153165 checks,
@@ -244,11 +256,15 @@ export function printClientResults(
244256
245257export async function runInteractiveMode (
246258 scenarioName : string ,
247- verbose : boolean = false
259+ verbose : boolean = false ,
260+ outputDir ?: string
248261) : Promise < void > {
249- await ensureResultsDir ( ) ;
250- const resultDir = createResultDir ( scenarioName ) ;
251- await fs . mkdir ( resultDir , { recursive : true } ) ;
262+ let resultDir : string | undefined ;
263+
264+ if ( outputDir ) {
265+ resultDir = createResultDir ( outputDir , scenarioName ) ;
266+ await fs . mkdir ( resultDir , { recursive : true } ) ;
267+ }
252268
253269 // Scenario is guaranteed to exist by CLI validation
254270 const scenario = getScenario ( scenarioName ) ! ;
@@ -257,23 +273,29 @@ export async function runInteractiveMode(
257273 const urls = await scenario . start ( ) ;
258274
259275 console . log ( `Server URL: ${ urls . serverUrl } ` ) ;
260- console . log ( 'Press Ctrl+C to stop and save checks ...' ) ;
276+ console . log ( 'Press Ctrl+C to stop...' ) ;
261277
262278 const handleShutdown = async ( ) => {
263279 console . log ( '\nShutting down...' ) ;
264280
265281 const checks = scenario . getChecks ( ) ;
266- await fs . writeFile (
267- path . join ( resultDir , 'checks.json' ) ,
268- JSON . stringify ( checks , null , 2 )
269- ) ;
282+
283+ if ( resultDir ) {
284+ await fs . writeFile (
285+ path . join ( resultDir , 'checks.json' ) ,
286+ JSON . stringify ( checks , null , 2 )
287+ ) ;
288+ }
270289
271290 if ( verbose ) {
272291 console . log ( `\nChecks:\n${ JSON . stringify ( checks , null , 2 ) } ` ) ;
273292 } else {
274293 console . log ( `\nChecks:\n${ formatPrettyChecks ( checks ) } ` ) ;
275294 }
276- console . log ( `\nChecks saved to ${ resultDir } /checks.json` ) ;
295+
296+ if ( resultDir ) {
297+ console . log ( `\nChecks saved to ${ resultDir } /checks.json` ) ;
298+ }
277299
278300 await scenario . stop ( ) ;
279301 process . exit ( 0 ) ;
0 commit comments