@@ -50,8 +50,12 @@ describe('Single report', function () {
50
50
return {
51
51
rest : {
52
52
repos : {
53
- compareCommits : jest . fn ( ( ) => {
54
- return compareCommitsResponse
53
+ compareCommits : jest . fn ( ( { base, head} ) => {
54
+ if ( base !== head ) {
55
+ return compareCommitsResponse
56
+ } else {
57
+ return { data : { files : [ ] } }
58
+ }
55
59
} ) ,
56
60
listPullRequestsAssociatedWithCommit : jest . fn ( ( ) => {
57
61
return { data : [ ] }
@@ -70,6 +74,7 @@ describe('Single report', function () {
70
74
} )
71
75
core . summary . addRaw = addRaw
72
76
core . summary . write = write
77
+ github . context . sha = 'guasft7asdtf78asfd87as6df7y2u3'
73
78
} )
74
79
75
80
const compareCommitsResponse = {
@@ -366,6 +371,7 @@ describe('Single report', function () {
366
371
} )
367
372
368
373
describe ( 'Pull Request Target event' , function ( ) {
374
+ const eventName = 'pull_request_target'
369
375
const payload = {
370
376
pull_request : {
371
377
number : '45' ,
@@ -378,8 +384,15 @@ describe('Single report', function () {
378
384
} ,
379
385
}
380
386
387
+ it ( 'publish proper comment' , async ( ) => {
388
+ initContext ( eventName , payload )
389
+ await action . action ( )
390
+
391
+ expect ( createComment . mock . calls [ 0 ] [ 0 ] . body ) . toEqual ( PROPER_COMMENT )
392
+ } )
393
+
381
394
it ( 'set overall coverage output' , async ( ) => {
382
- initContext ( 'pull_request_target' , payload )
395
+ initContext ( eventName , payload )
383
396
core . setOutput = output
384
397
385
398
await action . action ( )
@@ -526,13 +539,128 @@ describe('Single report', function () {
526
539
} )
527
540
} )
528
541
529
- describe ( 'Other than push or pull_request or pull_request_target event' , function ( ) {
542
+ describe ( 'Schedule event' , function ( ) {
543
+ const eventName = 'schedule'
544
+ const payload = { }
545
+
546
+ it ( 'publish project coverage comment' , async ( ) => {
547
+ core . getInput = jest . fn ( key => {
548
+ switch ( key ) {
549
+ case 'comment-type' :
550
+ return 'summary'
551
+ default :
552
+ return getInput ( key )
553
+ }
554
+ } )
555
+ initContext ( eventName , payload )
556
+
557
+ await action . action ( )
558
+
559
+ expect ( addRaw . mock . calls [ 0 ] [ 0 ] ) . toEqual ( ONLY_PROJECT_COMMENT )
560
+ expect ( write ) . toHaveBeenCalledTimes ( 1 )
561
+ } )
562
+
563
+ it ( 'set overall coverage output' , async ( ) => {
564
+ initContext ( eventName , payload )
565
+ core . setOutput = output
566
+
567
+ await action . action ( )
568
+
569
+ const out = output . mock . calls [ 0 ]
570
+ expect ( out ) . toEqual ( [ 'coverage-overall' , 35.25 ] )
571
+ } )
572
+ } )
573
+
574
+ describe ( 'Workflow Dispatch event' , function ( ) {
575
+ const eventName = 'workflow_dispatch'
576
+ const payload = { }
577
+
578
+ it ( 'publish project coverage comment' , async ( ) => {
579
+ core . getInput = jest . fn ( key => {
580
+ switch ( key ) {
581
+ case 'comment-type' :
582
+ return 'summary'
583
+ default :
584
+ return getInput ( key )
585
+ }
586
+ } )
587
+ initContext ( eventName , payload )
588
+
589
+ await action . action ( )
590
+
591
+ expect ( addRaw . mock . calls [ 0 ] [ 0 ] ) . toEqual ( ONLY_PROJECT_COMMENT )
592
+ expect ( write ) . toHaveBeenCalledTimes ( 1 )
593
+ } )
594
+
595
+ it ( 'set overall coverage output' , async ( ) => {
596
+ initContext ( eventName , payload )
597
+ core . setOutput = output
598
+
599
+ await action . action ( )
600
+
601
+ const out = output . mock . calls [ 0 ]
602
+ expect ( out ) . toEqual ( [ 'coverage-overall' , 35.25 ] )
603
+ } )
604
+ } )
605
+
606
+ describe ( 'Workflow Run event' , function ( ) {
607
+ const eventName = 'workflow_run'
608
+ const payload = {
609
+ workflow_run : {
610
+ pull_requests : [
611
+ {
612
+ base : {
613
+ sha : 'guasft7asdtf78asfd87as6df7y2u3' ,
614
+ } ,
615
+ head : {
616
+ sha : 'aahsdflais76dfa78wrglghjkaghkj' ,
617
+ } ,
618
+ number : 45 ,
619
+ } ,
620
+ ] ,
621
+ } ,
622
+ }
623
+
624
+ it ( 'when proper payload present, publish proper comment' , async ( ) => {
625
+ initContext ( eventName , payload )
626
+
627
+ await action . action ( )
628
+
629
+ expect ( createComment . mock . calls [ 0 ] [ 0 ] . body ) . toEqual ( PROPER_COMMENT )
630
+ } )
631
+
632
+ it ( 'when payload does not have pull_requests, publish project coverage comment' , async ( ) => {
633
+ initContext ( eventName , { } )
634
+ core . getInput = jest . fn ( key => {
635
+ switch ( key ) {
636
+ case 'pr-number' :
637
+ return 45
638
+ default :
639
+ return getInput ( key )
640
+ }
641
+ } )
642
+
643
+ await action . action ( )
644
+
645
+ expect ( createComment . mock . calls [ 0 ] [ 0 ] . body ) . toEqual ( ONLY_PROJECT_COMMENT )
646
+ } )
647
+
648
+ it ( 'set overall coverage output' , async ( ) => {
649
+ initContext ( eventName , payload )
650
+ core . setOutput = output
651
+
652
+ await action . action ( )
653
+
654
+ const out = output . mock . calls [ 0 ]
655
+ expect ( out ) . toEqual ( [ 'coverage-overall' , 35.25 ] )
656
+ } )
657
+ } )
658
+
659
+ describe ( 'Unsupported events' , function ( ) {
530
660
it ( 'Fail by throwing appropriate error' , async ( ) => {
531
661
initContext ( 'pr_review' , { } )
532
662
core . setFailed = jest . fn ( c => {
533
- expect ( c ) . toEqual (
534
- 'Only pull requests and pushes are supported, pr_review not supported.'
535
- )
663
+ expect ( c ) . toEqual ( 'The event pr_review is not supported.' )
536
664
} )
537
665
core . setOutput = output
538
666
@@ -561,3 +689,9 @@ const PROPER_COMMENT = `### JaCoCo Report
561
689
|:-|:-|:-:|
562
690
|[Math.kt](https://github.com/thsaravana/jacoco-playground/blob/14a554976c0e5909d8e69bc8cce72958c49a7dc5/src/main/kotlin/com/madrapps/jacoco/Math.kt)|42% **\`-42%\`**|:x:|
563
691
|[Utility.java](https://github.com/thsaravana/jacoco-playground/blob/14a554976c0e5909d8e69bc8cce72958c49a7dc5/src/main/java/com/madrapps/jacoco/Utility.java)|18.03%|:green_apple:|`
692
+
693
+ const ONLY_PROJECT_COMMENT = `### JaCoCo Report
694
+ |Overall Project|35.25%|:x:|
695
+ |:-|:-|:-:|
696
+
697
+ > There is no coverage information present for the Files changed`
0 commit comments