@@ -499,13 +499,20 @@ describe('isTestFile', () => {
499
499
500
500
describe ( 'shouldStringifyContent' , ( ) => {
501
501
it ( 'should return correct value is defined' , ( ) => {
502
- const cs = createConfigSet ( { tsJestConfig : { tsconfig : false , stringifyContentPathRegex : '\\.str$' } as any } )
503
- expect ( cs . shouldStringifyContent ( '/foo/bar.ts' ) ) . toBe ( false )
504
- expect ( cs . shouldStringifyContent ( '/foo/bar.str' ) ) . toBe ( true )
502
+ const cs1 = createConfigSet ( { tsJestConfig : { tsconfig : false , stringifyContentPathRegex : '\\.str$' } as any } )
503
+
504
+ expect ( cs1 . shouldStringifyContent ( '/foo/bar.ts' ) ) . toBe ( false )
505
+ expect ( cs1 . shouldStringifyContent ( '/foo/bar.str' ) ) . toBe ( true )
506
+
507
+ const cs2 = createConfigSet ( { tsJestConfig : { tsconfig : false , stringifyContentPathRegex : / \. s t r $ / } as any } )
508
+
509
+ expect ( cs2 . shouldStringifyContent ( '/foo/bar.ts' ) ) . toBe ( false )
510
+ expect ( cs2 . shouldStringifyContent ( '/foo/bar.str' ) ) . toBe ( true )
505
511
} )
506
512
507
513
it ( 'should return correct value when stringifyContentPathRegex is undefined' , ( ) => {
508
514
const cs = createConfigSet ( { tsJestConfig : { tsconfig : false } as any } )
515
+
509
516
expect ( cs . shouldStringifyContent ( '/foo/bar.ts' ) ) . toBe ( false )
510
517
} )
511
518
} ) // shouldStringifyContent
@@ -554,8 +561,19 @@ describe('raiseDiagnostics', () => {
554
561
code = 9999 ,
555
562
category = ts . DiagnosticCategory . Warning ,
556
563
} : Partial < ts . Diagnostic > = { } ) : ts . Diagnostic => ( { messageText, code, category } as any )
557
- it ( 'should throw when diagnostics contains file path and pathRegex config matches file path' , ( ) => {
558
- const cs = createConfigSet ( {
564
+
565
+ it ( 'should throw when diagnostics contains file path and exclude config matches file path' , ( ) => {
566
+ let cs = createConfigSet ( {
567
+ logger,
568
+ tsJestConfig : { diagnostics : { exclude : [ 'src/__mocks__/index.ts' ] , pretty : false } } ,
569
+ } )
570
+ logger . target . clear ( )
571
+
572
+ expect ( ( ) =>
573
+ cs . raiseDiagnostics ( [ makeDiagnostic ( ) ] , 'src/__mocks__/index.ts' , logger ) ,
574
+ ) . toThrowErrorMatchingInlineSnapshot ( `"warning TS9999: foo"` )
575
+
576
+ cs = createConfigSet ( {
559
577
logger,
560
578
tsJestConfig : { diagnostics : { pathRegex : 'src/__mocks__/index.ts' , pretty : false } } ,
561
579
} )
@@ -566,8 +584,16 @@ describe('raiseDiagnostics', () => {
566
584
) . toThrowErrorMatchingInlineSnapshot ( `"warning TS9999: foo"` )
567
585
} )
568
586
569
- it ( "should not throw when diagnostics contains file path and pathRegex config doesn't match file path" , ( ) => {
570
- const cs = createConfigSet ( {
587
+ it ( "should not throw when diagnostics contains file path and exclude config doesn't match file path" , ( ) => {
588
+ let cs = createConfigSet ( {
589
+ logger,
590
+ tsJestConfig : { diagnostics : { warnOnly : true , exclude : [ '/bar/' ] , pretty : false } } ,
591
+ } )
592
+ logger . target . clear ( )
593
+
594
+ expect ( ( ) => cs . raiseDiagnostics ( [ makeDiagnostic ( ) ] , 'src/__mocks__/index.ts' , logger ) ) . not . toThrow ( )
595
+
596
+ cs = createConfigSet ( {
571
597
logger,
572
598
tsJestConfig : { diagnostics : { warnOnly : true , pathRegex : '/bar/' , pretty : false } } ,
573
599
} )
@@ -591,38 +617,106 @@ describe('raiseDiagnostics', () => {
591
617
file = program . getSourceFiles ( ) . find ( ( sourceFile ) => sourceFile . fileName === 'src/__mocks__/index.ts' ) ,
592
618
} : Partial < ts . Diagnostic > = { } ) : ts . Diagnostic => ( { messageText, code, category, file } as any )
593
619
594
- it ( "should not throw when pathRegex config doesn't match source file path" , ( ) => {
620
+ it ( "should not throw when exclude config doesn't match source file path" , ( ) => {
595
621
const cs = createConfigSet ( {
596
622
logger,
597
- tsJestConfig : { diagnostics : { pathRegex : '/foo/' , pretty : false , ignoreCodes : [ 1111 ] } } ,
623
+ tsJestConfig : { diagnostics : { exclude : [ '/foo/' ] , pretty : false , ignoreCodes : [ 1111 ] } } ,
598
624
} )
599
625
logger . target . clear ( )
600
626
601
627
expect ( ( ) => cs . raiseDiagnostics ( [ makeDiagnostic ( ) ] ) ) . not . toThrow ( )
628
+
629
+ const cs1 = createConfigSet ( {
630
+ logger,
631
+ tsJestConfig : { diagnostics : { pathRegex : '/foo/' , pretty : false , ignoreCodes : [ 1111 ] } } ,
632
+ } )
633
+ logger . target . clear ( )
634
+
635
+ expect ( ( ) => cs1 . raiseDiagnostics ( [ makeDiagnostic ( ) ] ) ) . not . toThrow ( )
602
636
} )
603
637
604
- it ( "should throw when pathRegex config doesn't match source file path" , ( ) => {
638
+ it ( "should throw when exclude config doesn't match source file path" , ( ) => {
605
639
const cs = createConfigSet ( {
606
640
logger,
607
- tsJestConfig : { diagnostics : { pathRegex : 'src/__mocks__/index.ts' , pretty : false } } ,
641
+ tsJestConfig : { diagnostics : { exclude : [ 'src/__mocks__/index.ts' ] , pretty : false } } ,
608
642
} )
609
643
logger . target . clear ( )
610
644
611
645
expect ( ( ) => cs . raiseDiagnostics ( [ makeDiagnostic ( ) ] ) ) . toThrowErrorMatchingInlineSnapshot (
612
646
`"Debug Failure. False expression: position cannot precede the beginning of the file"` ,
613
647
)
648
+
649
+ const cs1 = createConfigSet ( {
650
+ logger,
651
+ tsJestConfig : { diagnostics : { pathRegex : 'src/__mocks__/index.ts' , pretty : false } } ,
652
+ } )
653
+ logger . target . clear ( )
654
+
655
+ expect ( ( ) => cs1 . raiseDiagnostics ( [ makeDiagnostic ( ) ] ) ) . toThrowErrorMatchingInlineSnapshot (
656
+ `"Debug Failure. False expression: position cannot precede the beginning of the file"` ,
657
+ )
614
658
} )
615
659
} )
616
660
} ) // raiseDiagnostics
617
661
618
662
describe ( 'shouldReportDiagnostics' , ( ) => {
619
- it ( 'should return correct value' , ( ) => {
620
- let cs = createConfigSet ( { tsJestConfig : { tsconfig : false , diagnostics : { pathRegex : '/foo/' } } as any } )
663
+ it ( 'should return correct value for ts/tsx files' , ( ) => {
664
+ let cs = createConfigSet ( {
665
+ tsJestConfig : {
666
+ tsconfig : false ,
667
+ diagnostics : { exclude : [ '**/foo/*.ts' , '**/foo/*.tsx' ] } ,
668
+ } as any ,
669
+ } )
670
+
671
+ expect ( cs . shouldReportDiagnostics ( '/foo/index.ts' ) ) . toBe ( true )
672
+ expect ( cs . shouldReportDiagnostics ( '/bar/index.tsx' ) ) . toBe ( false )
673
+
674
+ cs = createConfigSet ( {
675
+ tsJestConfig : {
676
+ tsconfig : false ,
677
+ diagnostics : { pathRegex : '/foo/' } ,
678
+ } as any ,
679
+ } )
680
+
621
681
expect ( cs . shouldReportDiagnostics ( '/foo/index.ts' ) ) . toBe ( true )
622
- expect ( cs . shouldReportDiagnostics ( '/bar/index.ts' ) ) . toBe ( false )
682
+ expect ( cs . shouldReportDiagnostics ( '/bar/index.tsx' ) ) . toBe ( false )
683
+
623
684
cs = createConfigSet ( { tsJestConfig : { tsconfig : false } as any } )
685
+
624
686
expect ( cs . shouldReportDiagnostics ( '/foo/index.ts' ) ) . toBe ( true )
625
- expect ( cs . shouldReportDiagnostics ( '/bar/index.ts' ) ) . toBe ( true )
687
+ expect ( cs . shouldReportDiagnostics ( '/bar/index.tsx' ) ) . toBe ( true )
688
+ } )
689
+
690
+ test ( 'should return correct value for js/jsx files with checkJs compiler option' , ( ) => {
691
+ let cs = createConfigSet ( {
692
+ tsJestConfig : {
693
+ tsconfig : { checkJs : false } ,
694
+ diagnostics : { exclude : [ 'foo/*' ] } ,
695
+ } ,
696
+ } )
697
+
698
+ expect ( cs . shouldReportDiagnostics ( '/foo/index.js' ) ) . toBe ( false )
699
+ expect ( cs . shouldReportDiagnostics ( '/foo/index.jsx' ) ) . toBe ( false )
700
+
701
+ cs = createConfigSet ( {
702
+ tsJestConfig : {
703
+ tsconfig : { checkJs : false } ,
704
+ diagnostics : { pathRegex : '/bar/' } ,
705
+ } ,
706
+ } )
707
+
708
+ expect ( cs . shouldReportDiagnostics ( '/foo/index.js' ) ) . toBe ( false )
709
+ expect ( cs . shouldReportDiagnostics ( '/foo/index.jsx' ) ) . toBe ( false )
710
+
711
+ cs = createConfigSet ( {
712
+ tsJestConfig : {
713
+ tsconfig : { checkJs : true } ,
714
+ diagnostics : { exclude : [ '**/foo/*.js' , '**/foo/*.jsx' ] } ,
715
+ } ,
716
+ } )
717
+
718
+ expect ( cs . shouldReportDiagnostics ( '/foo/index.js' ) ) . toBe ( true )
719
+ expect ( cs . shouldReportDiagnostics ( '/foo/index.jsx' ) ) . toBe ( true )
626
720
} )
627
721
} ) // shouldReportDiagnostics
628
722
@@ -979,15 +1073,15 @@ describe('diagnostics', () => {
979
1073
{
980
1074
diagnostics : {
981
1075
ignoreCodes : '10, 25' ,
982
- pathRegex : '\\.test\\.ts' ,
1076
+ exclude : [ '\\.test\\.ts' ] ,
983
1077
pretty : false ,
984
1078
} ,
985
1079
} ,
986
1080
{
987
1081
diagnostics : {
988
1082
ignoreCodes : [ '10' , 25 ] ,
989
1083
pretty : false ,
990
- pathRegex : RegExp ( '\\.test\\.ts' ) ,
1084
+ exclude : [ '\\.test\\.ts' ] ,
991
1085
} ,
992
1086
} ,
993
1087
{ diagnostics : { warnOnly : true } } ,
0 commit comments