@@ -419,15 +419,42 @@ describe('SARIF processing', () => {
419419 expectResultParsingError ( result . errors [ 0 ] ) ;
420420 } ) ;
421421
422- it ( 'should return errors for result locations with no context region' , ( ) => {
422+ it ( 'should not return errors for result locations with no snippet' , ( ) => {
423+ const sarif = buildValidSarifLog ( ) ;
424+ sarif . runs ! [ 0 ] ! . results ! [ 0 ] ! . locations ! [ 0 ] ! . physicalLocation ! . contextRegion ! . snippet = undefined ;
425+
426+ const result = extractAnalysisAlerts ( sarif , fakefileLinkPrefix ) ;
427+
428+ const expectedCodeSnippet = {
429+ startLine : result . alerts [ 0 ] . codeSnippet ! . startLine ,
430+ endLine : result . alerts [ 0 ] . codeSnippet ! . endLine ,
431+ text : ''
432+ } ;
433+
434+ const actualCodeSnippet = result . alerts [ 0 ] . codeSnippet ;
435+
436+ expect ( result ) . to . be . ok ;
437+ expectNoParsingError ( result ) ;
438+ expect ( actualCodeSnippet ) . to . deep . equal ( expectedCodeSnippet ) ;
439+ } ) ;
440+
441+ it ( 'should use highlightedRegion for result locations with no contextRegion' , ( ) => {
423442 const sarif = buildValidSarifLog ( ) ;
424443 sarif . runs ! [ 0 ] ! . results ! [ 0 ] ! . locations ! [ 0 ] ! . physicalLocation ! . contextRegion = undefined ;
425444
426445 const result = extractAnalysisAlerts ( sarif , fakefileLinkPrefix ) ;
427446
447+ const expectedCodeSnippet = {
448+ startLine : result . alerts [ 0 ] . highlightedRegion ! . startLine ,
449+ endLine : result . alerts [ 0 ] . highlightedRegion ! . endLine ,
450+ text : ''
451+ } ;
452+
453+ const actualCodeSnippet = result . alerts [ 0 ] . codeSnippet ;
454+
428455 expect ( result ) . to . be . ok ;
429- expect ( result . errors . length ) . to . equal ( 1 ) ;
430- expectResultParsingError ( result . errors [ 0 ] ) ;
456+ expectNoParsingError ( result ) ;
457+ expect ( actualCodeSnippet ) . to . deep . equal ( expectedCodeSnippet ) ;
431458 } ) ;
432459
433460 it ( 'should not return errors for result locations with no region' , ( ) => {
@@ -438,6 +465,7 @@ describe('SARIF processing', () => {
438465
439466 expect ( result ) . to . be . ok ;
440467 expect ( result . alerts . length ) . to . equal ( 1 ) ;
468+ expectNoParsingError ( result ) ;
441469 } ) ;
442470
443471 it ( 'should return errors for result locations with no physical location' , ( ) => {
@@ -537,9 +565,9 @@ describe('SARIF processing', () => {
537565 expect ( result ) . to . be . ok ;
538566 expect ( result . errors . length ) . to . equal ( 0 ) ;
539567 expect ( result . alerts . length ) . to . equal ( 3 ) ;
540- expect ( result . alerts . find ( a => getMessageText ( a . message ) === 'msg1' && a . codeSnippet . text === 'foo' ) ) . to . be . ok ;
541- expect ( result . alerts . find ( a => getMessageText ( a . message ) === 'msg1' && a . codeSnippet . text === 'bar' ) ) . to . be . ok ;
542- expect ( result . alerts . find ( a => getMessageText ( a . message ) === 'msg2' && a . codeSnippet . text === 'baz' ) ) . to . be . ok ;
568+ expect ( result . alerts . find ( a => getMessageText ( a . message ) === 'msg1' && a . codeSnippet ! . text === 'foo' ) ) . to . be . ok ;
569+ expect ( result . alerts . find ( a => getMessageText ( a . message ) === 'msg1' && a . codeSnippet ! . text === 'bar' ) ) . to . be . ok ;
570+ expect ( result . alerts . find ( a => getMessageText ( a . message ) === 'msg2' && a . codeSnippet ! . text === 'baz' ) ) . to . be . ok ;
543571 expect ( result . alerts . every ( a => a . severity === 'Warning' ) ) . to . be . true ;
544572 } ) ;
545573
@@ -595,9 +623,14 @@ describe('SARIF processing', () => {
595623 expect ( msg . startsWith ( 'Error when processing SARIF result' ) ) . to . be . true ;
596624 }
597625
626+ function expectNoParsingError ( result : { errors : string [ ] } ) {
627+ const array = result . errors ;
628+ expect ( array . length , array . join ( ) ) . to . equal ( 0 ) ;
629+ }
630+
598631 function buildValidSarifLog ( ) : sarif . Log {
599632 return {
600- version : '0.0.1' as sarif . Log . version ,
633+ version : '2.1.0' ,
601634 runs : [
602635 {
603636 results : [
0 commit comments