import { spawnSync } from 'child_process' ; import { REPO_ROOT } from '@kbn/utils' ; const INVALID_CONFIG_PATH = require . resolve ( './__fixtures__/invalid_config.yml' ) ; interface LogEntry { message : string ; log : { level : string ; } ; } describe ( 'cli invalid config support' , ( ) => { it ( 'exits with statusCode 64 and logs an error when config is invalid' , ( ) => { const { error , status , stdout , stderr } = spawnSync ( process . execPath , [ 'scripts/kibana' , '--config' , INVALID_CONFIG_PATH , '--migrations.skip=true' ] , { cwd : REPO_ROOT , } ) ; expect ( error ) . toBe ( undefined ) ; let fatalLogEntries ; try { fatalLogEntries = stdout . toString ( 'utf8' ) . split ( '\n' ) . filter ( Boolean ) . map ( ( line ) => JSON . parse ( line ) as LogEntry ) . filter ( ( line ) => line . log . level === 'FATAL' ) ; } catch ( e ) { throw new Error ( `error parsing log output:\n\n${ e . stack }\n\nstdout: \n${ stdout }\n\nstderr:\n${ stderr }` ) ; } expect ( fatalLogEntries ) . toHaveLength ( 1 ) ; expect ( fatalLogEntries [ 0 ] . message ) . toContain ( 'Unknown configuration key(s): "unknown.key", "other.unknown.key", "other.third", "some.flat.key", ' + '"some.array". Check for spelling errors and ensure that expected plugins are installed.' ) ; expect ( status ) . toBe ( 64 ) ; } , 20 * 1000 ) ; } ) ;