license import * as child_process from 'child_process' ; import * as path from 'path' ; describe ( 'rpc_ts' , ( ) => { describe ( 'examples' , ( ) => { for ( const exampleName of [ 'context' , 'server_stream' ] ) { it ( exampleName , async ( ) => { await run ( path . resolve ( __dirname , '..' , exampleName ) ) ; } ) . timeout ( 10000 ) ; } it ( 'the code in the README.md compiles and runs' , async ( ) => { const projectRoot = path . resolve ( __dirname , '../../..' ) ; await run ( path . resolve ( projectRoot , 'readme_code.ts' ) , path . resolve ( __dirname , '../../../tsconfig.doc.json' ) ) ; } ) . timeout ( 10000 ) ; } ) ; } ) ; async function run ( script , tsNodeProject ? ) { return new Promise < void > ( ( resolve , reject ) => { child_process . spawn ( 'yarn' , [ 'ts-node' , '-r' , 'tsconfig-paths/register' , script ] , { stdio : 'inherit' , env : ! tsNodeProject ? undefined : { ... process . env , TS_NODE_PROJECT : tsNodeProject } , } ) . on ( 'close' , code => { if ( code === 0 ) resolve ( ) ; else reject ( `non-zero exit code ${ code }` ) ; } ) ; } ) ; }