@@ -679,10 +679,18 @@ describe('lint yaml content', () => {
679679 if ( ymlToLint . length < 1 ) return
680680 describe . each ( ymlToLint ) ( '%s' , ( yamlRelPath , yamlAbsPath ) => {
681681 let dictionary , isEarlyAccess , ifversionConditionals , ifConditionals
682+ // This variable is used to determine if the file was parsed successfully.
683+ // When `yaml.load()` fails to parse the file, it is overwritten with the error message.
684+ // `false` is intentionally chosen since `null` and `undefined` are valid return values.
685+ let dictionaryError = false
682686
683687 beforeAll ( async ( ) => {
684688 const fileContents = await readFileAsync ( yamlAbsPath , 'utf8' )
685- dictionary = yaml . load ( fileContents , { filename : yamlRelPath } )
689+ try {
690+ dictionary = yaml . load ( fileContents , { filename : yamlRelPath } )
691+ } catch ( error ) {
692+ dictionaryError = error
693+ }
686694
687695 isEarlyAccess = yamlRelPath . split ( '/' ) . includes ( 'early-access' )
688696
@@ -691,6 +699,10 @@ describe('lint yaml content', () => {
691699 ifConditionals = getLiquidConditionals ( fileContents , 'if' )
692700 } )
693701
702+ test ( 'it can be parsed as a single yaml document' , ( ) => {
703+ expect ( dictionaryError ) . toBe ( false )
704+ } )
705+
694706 test ( 'ifversion conditionals are valid in yaml' , async ( ) => {
695707 const errors = validateIfversionConditionals ( ifversionConditionals )
696708 expect ( errors . length , errors . join ( '\n' ) ) . toBe ( 0 )
@@ -907,10 +919,19 @@ describe('lint GHES release notes', () => {
907919 if ( ghesReleaseNotesToLint . length < 1 ) return
908920 describe . each ( ghesReleaseNotesToLint ) ( '%s' , ( yamlRelPath , yamlAbsPath ) => {
909921 let dictionary
922+ let dictionaryError = false
910923
911924 beforeAll ( async ( ) => {
912925 const fileContents = await readFileAsync ( yamlAbsPath , 'utf8' )
913- dictionary = yaml . load ( fileContents , { filename : yamlRelPath } )
926+ try {
927+ dictionary = yaml . load ( fileContents , { filename : yamlRelPath } )
928+ } catch ( error ) {
929+ dictionaryError = error
930+ }
931+ } )
932+
933+ it ( 'can be parsed as a single yaml document' , ( ) => {
934+ expect ( dictionaryError ) . toBe ( false )
914935 } )
915936
916937 it ( 'matches the schema' , ( ) => {
@@ -954,10 +975,19 @@ describe('lint GHAE release notes', () => {
954975 const currentWeeksFound = [ ]
955976 describe . each ( ghaeReleaseNotesToLint ) ( '%s' , ( yamlRelPath , yamlAbsPath ) => {
956977 let dictionary
978+ let dictionaryError = false
957979
958980 beforeAll ( async ( ) => {
959981 const fileContents = await readFileAsync ( yamlAbsPath , 'utf8' )
960- dictionary = yaml . load ( fileContents , { filename : yamlRelPath } )
982+ try {
983+ dictionary = yaml . load ( fileContents , { filename : yamlRelPath } )
984+ } catch ( error ) {
985+ dictionaryError = error
986+ }
987+ } )
988+
989+ it ( 'can be parsed as a single yaml document' , ( ) => {
990+ expect ( dictionaryError ) . toBe ( false )
961991 } )
962992
963993 it ( 'matches the schema' , ( ) => {
@@ -1008,10 +1038,19 @@ describe('lint learning tracks', () => {
10081038 if ( learningTracksToLint . length < 1 ) return
10091039 describe . each ( learningTracksToLint ) ( '%s' , ( yamlRelPath , yamlAbsPath ) => {
10101040 let dictionary
1041+ let dictionaryError = false
10111042
10121043 beforeAll ( async ( ) => {
10131044 const fileContents = await readFileAsync ( yamlAbsPath , 'utf8' )
1014- dictionary = yaml . load ( fileContents , { filename : yamlRelPath } )
1045+ try {
1046+ dictionary = yaml . load ( fileContents , { filename : yamlRelPath } )
1047+ } catch ( error ) {
1048+ dictionaryError = error
1049+ }
1050+ } )
1051+
1052+ it ( 'can be parsed as a single yaml document' , ( ) => {
1053+ expect ( dictionaryError ) . toBe ( false )
10151054 } )
10161055
10171056 it ( 'matches the schema' , ( ) => {
@@ -1083,10 +1122,19 @@ describe('lint feature versions', () => {
10831122 if ( featureVersionsToLint . length < 1 ) return
10841123 describe . each ( featureVersionsToLint ) ( '%s' , ( yamlRelPath , yamlAbsPath ) => {
10851124 let dictionary
1125+ let dictionaryError = false
10861126
10871127 beforeAll ( async ( ) => {
10881128 const fileContents = await readFileAsync ( yamlAbsPath , 'utf8' )
1089- dictionary = yaml . load ( fileContents , { filename : yamlRelPath } )
1129+ try {
1130+ dictionary = yaml . load ( fileContents , { filename : yamlRelPath } )
1131+ } catch ( error ) {
1132+ dictionaryError = error
1133+ }
1134+ } )
1135+
1136+ it ( 'can be parsed as a single yaml document' , ( ) => {
1137+ expect ( dictionaryError ) . toBe ( false )
10901138 } )
10911139
10921140 it ( 'matches the schema' , ( ) => {
0 commit comments