@@ -17,7 +17,7 @@ import detectPort from "detect-port";
17
17
import { spawn } from "node:child_process" ;
18
18
import { hideBin } from "yargs/helpers" ;
19
19
import { run } from "node:test" ;
20
- import { tap } from "node:test/reporters" ;
20
+ import { junit , tap } from "node:test/reporters" ;
21
21
import { styleText } from "node:util" ;
22
22
import { killPortProcess } from "kill-port-process" ;
23
23
import { dirname , extname , join } from "node:path" ;
@@ -184,7 +184,7 @@ yargs(hideBin(process.argv))
184
184
185
185
process . stdout . write ( "\n" ) ;
186
186
187
- await killPortIfRunning ( readPort ( argv . graphql ) ) . catch ( ( ) => { } ) ;
187
+ await killPortIfRunning ( readPort ( argv . graphql ) ) . catch ( ( ) => { } ) ;
188
188
189
189
const gatewayExit = Promise . withResolvers < void > ( ) ;
190
190
let gatewayExited = false ;
@@ -245,6 +245,10 @@ yargs(hideBin(process.argv))
245
245
choices : [ "dot" , "tap" ] ,
246
246
default : "tap" ,
247
247
} )
248
+ . option ( "junit" , {
249
+ describe : "Write test results to a JUnit XML file" ,
250
+ type : "boolean" ,
251
+ } )
248
252
. demandOption ( "test" )
249
253
. demandOption ( "graphql" )
250
254
. demandOption ( "healthcheck" )
@@ -274,7 +278,7 @@ yargs(hideBin(process.argv))
274
278
mkdirSync ( resolvePath ( argv , "./logs" ) ) ;
275
279
}
276
280
277
- await killPortIfRunning ( readPort ( argv . graphql ) ) . catch ( ( ) => { } ) ;
281
+ await killPortIfRunning ( readPort ( argv . graphql ) ) . catch ( ( ) => { } ) ;
278
282
const logStream = createWriteStream (
279
283
resolvePath ( argv , `./logs/${ argv . test } -gateway.log` ) ,
280
284
{
@@ -301,6 +305,7 @@ yargs(hideBin(process.argv))
301
305
const result = await runTest ( {
302
306
...argv ,
303
307
reporter : argv . reporter === "tap" ? "tap" : "dot" ,
308
+ junit : argv . junit ,
304
309
port,
305
310
} ) ;
306
311
@@ -348,6 +353,10 @@ yargs(hideBin(process.argv))
348
353
choices : [ "dot" , "tap" ] ,
349
354
default : "dot" ,
350
355
} )
356
+ . option ( "junit" , {
357
+ describe : "Write test results to a JUnit XML file" ,
358
+ type : "boolean" ,
359
+ } )
351
360
. option ( "write" , {
352
361
describe : "Write test results to a file" ,
353
362
type : "string" ,
@@ -398,7 +407,7 @@ yargs(hideBin(process.argv))
398
407
399
408
process . stdout . write ( "\n" ) ;
400
409
for await ( const id of ids ) {
401
- await killPortIfRunning ( readPort ( argv . graphql ) ) . catch ( ( ) => { } ) ;
410
+ await killPortIfRunning ( readPort ( argv . graphql ) ) . catch ( ( ) => { } ) ;
402
411
const logStream = createWriteStream (
403
412
resolvePath ( argv , `./logs/${ id } -gateway.log` ) ,
404
413
{
@@ -428,6 +437,7 @@ yargs(hideBin(process.argv))
428
437
healthcheck : argv . healthcheck ,
429
438
port : argv . port ,
430
439
reporter : argv . reporter === "tap" ? "tap" : "dot" ,
440
+ junit : argv . junit ,
431
441
cwd : argv . cwd ,
432
442
} ) ;
433
443
results . push ( { id, result } ) ;
@@ -507,11 +517,13 @@ async function runTest(args: {
507
517
healthcheck ? : string ;
508
518
port: number ;
509
519
reporter ? : "dot" | "tap" ;
520
+ junit ? : boolean ;
510
521
cwd: string ;
511
522
} ) : Promise < Array < "." | "X" >> {
512
523
process. stdout . write ( `${ args . test } \n` ) ;
513
524
process . env . TESTS_ENDPOINT = `http://localhost:${ args . port } /${ args . test } /tests` ;
514
525
process . env . GRAPHQL_ENDPOINT = args . graphql ;
526
+ process . env . TEST_SUITE = args . test ;
515
527
516
528
const logStream = createWriteStream (
517
529
resolvePath ( { cwd : args . cwd } , `./logs/${ args . test } -tests.log` ) ,
@@ -543,13 +555,34 @@ async function runTest(args: {
543
555
testStream . compose ( tap ) . pipe ( logStream ) ;
544
556
testStream . compose ( dotan ) ;
545
557
558
+ if ( args . junit ) {
559
+ const reportsDir = resolvePath ( { cwd : args . cwd } , "reports" ) ;
560
+ if ( ! existsSync ( reportsDir ) ) {
561
+ mkdirSync ( reportsDir , { recursive : true } ) ;
562
+ }
563
+ const junitPath = join (
564
+ reportsDir ,
565
+ `${ args . test } .xml`
566
+ ) ;
567
+ const junitStream = createWriteStream (
568
+ junitPath ,
569
+ {
570
+ flags : "w+" ,
571
+ }
572
+ ) ;
573
+ testStream . compose ( junit ) . pipe ( junitStream ) ;
574
+ }
575
+
546
576
return promise ;
547
577
}
548
578
549
579
function createDotReporter ( resolve : ( value : Array < "." | "X" > ) => void ) {
550
580
const report : Array < "." | "X" > = [ ] ;
551
581
return async function * dot ( source : Parameters < typeof tap > [ 0 ] ) {
552
- for await ( const { type } of source ) {
582
+ for await ( const { type, data } of source ) {
583
+ if ( data != null && 'details' in data && data . details ?. type === "suite" ) {
584
+ continue ;
585
+ }
553
586
if ( type === "test:pass" ) {
554
587
report . push ( "." ) ;
555
588
}
@@ -561,11 +594,14 @@ function createDotReporter(resolve: (value: Array<"." | "X">) => void) {
561
594
} ;
562
595
}
563
596
564
- async function * dot ( source : any ) {
597
+ async function * dot ( source : Parameters < typeof tap > [ 0 ] ) {
565
598
let count = 0 ;
566
599
let columns = getLineLength ( ) ;
567
600
const failedTests = [ ] ;
568
601
for await ( const { type, data } of source ) {
602
+ if ( data != null && 'details' in data && data . details ?. type === "suite" ) {
603
+ continue ;
604
+ }
569
605
if ( type === "test:pass" ) {
570
606
yield styleText ( "green" , "." ) ;
571
607
}
0 commit comments