@@ -283,6 +283,24 @@ describe('action', () => {
283283 }
284284 } ) ;
285285
286+ it ( 'fails if schema missing $schema key' , async ( ) => {
287+ mockGetBooleanInput ( { } ) ;
288+ mockGetInput ( { schema } ) ;
289+ mockGetMultilineInput ( { files } ) ;
290+
291+ jest
292+ . mocked ( fs . readFile )
293+ . mockResolvedValueOnce ( schemaContents . replace ( '$schema' , '_schema' ) ) ;
294+
295+ await main . run ( ) ;
296+ expect ( runSpy ) . toHaveReturned ( ) ;
297+ expect ( process . exitCode ) . not . toBeDefined ( ) ;
298+
299+ expect ( core . setFailed ) . toHaveBeenLastCalledWith (
300+ 'JSON schema missing $schema key'
301+ ) ;
302+ } ) ;
303+
286304 it ( 'fails if no files to validate' , async ( ) => {
287305 mockGetBooleanInput ( { } ) ;
288306 mockGetInput ( { schema } ) ;
@@ -377,4 +395,28 @@ describe('action', () => {
377395 expect ( core . debug ) . toHaveBeenCalledWith ( `𐄂 ${ paths [ 0 ] } is not valid` ) ;
378396 expect ( core . debug ) . toHaveBeenCalledWith ( `✓ ${ paths [ 1 ] } is valid` ) ;
379397 } ) ;
398+
399+ it ( 'supports JSON Schema draft-04' , async ( ) => {
400+ mockGetBooleanInput ( { } ) ;
401+ mockGetInput ( { schema } ) ;
402+ mockGetMultilineInput ( { files } ) ;
403+
404+ jest
405+ . mocked ( fs . readFile )
406+ . mockResolvedValueOnce (
407+ schemaContents . replace (
408+ 'http://json-schema.org/draft-07/schema#' ,
409+ 'http://json-schema.org/draft-04/schema#'
410+ )
411+ )
412+ . mockResolvedValueOnce ( instanceContents ) ;
413+ mockGlobGenerator ( [ '/foo/bar/baz/config.yml' ] ) ;
414+
415+ await main . run ( ) ;
416+ expect ( runSpy ) . toHaveReturned ( ) ;
417+ expect ( process . exitCode ) . not . toBeDefined ( ) ;
418+
419+ expect ( core . setOutput ) . toHaveBeenCalledTimes ( 1 ) ;
420+ expect ( core . setOutput ) . toHaveBeenLastCalledWith ( 'valid' , true ) ;
421+ } ) ;
380422} ) ;
0 commit comments