import { CLI } from '../../CLI' ; import { jestConsoleContext , jestContext } from '@prisma/sdk' ; import { MigrateCommand , MigrateDev , MigrateResolve , MigrateStatus , MigrateReset , MigrateDeploy , DbPush , DbPull , DbSeed , DbCommand , handlePanic , } from '@prisma/migrate' ; const ctx = jestContext . new ( ) . add ( jestConsoleContext ( ) ) . assemble ( ) ; const cliInstance = CLI . new ( { deprecated introspect : DbPull . new ( ) , } , [ 'version' , 'init' , 'migrate' , 'db' , 'introspect' , 'dev' , 'studio' , 'generate' , 'validate' , 'format' , 'doctor' , 'telemetry' , ] ) ; it ( 'no params should return help' , async ( ) => { const spy = jest . spyOn ( cliInstance , 'help' ) . mockImplementation ( ( ) => 'Help Me' ) ; await cliInstance . parse ( [ ] ) ; expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ; spy . mockRestore ( ) ; } ) ; it ( 'wrong flag' , async ( ) => { const spy = jest . spyOn ( cliInstance , 'help' ) . mockImplementation ( ( ) => 'Help Me' ) ; await cliInstance . parse ( [ '--something' ] ) ; expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ; spy . mockRestore ( ) ; } ) ; it ( 'help flag' , async ( ) => { const spy = jest . spyOn ( cliInstance , 'help' ) . mockImplementation ( ( ) => 'Help Me' ) ; await cliInstance . parse ( [ '--help' ] ) ; expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ; spy . mockRestore ( ) ; } ) ; it ( 'unknown command' , async ( ) => { await expect ( cliInstance . parse ( [ 'doesnotexist' ] ) ) . resolves . toThrowError ( ) ; } ) ; it ( 'introspect should include deprecation warning' , async ( ) => { const result = cliInstance . parse ( [ 'introspect' ] ) ; await expect ( result ) . rejects . toMatchInlineSnapshot ( `
          Could not find a schema.prisma file that is required for this command.
          You can either provide it with --schema, set it as \`prisma.schema\` in your package.json or put it into the default location ./prisma/schema.prisma https://pris.ly/d/prisma-schema-location
        ` ) ; expect ( ctx . mocked [ 'console.log' ] . mock . calls ) . toHaveLength ( 0 ) ; expect ( ctx . mocked [ 'console.info' ] . mock . calls ) . toHaveLength ( 0 ) ; expect ( ctx . mocked [ 'console.warn' ] . mock . calls . join ( '\n' ) ) . toMatchInlineSnapshot ( `
    prisma:warn 
    prisma:warn The prisma introspect command is deprecated. Please use prisma db pull instead.
    prisma:warn 
  ` ) ; expect ( ctx . mocked [ 'console.error' ] . mock . calls ) . toHaveLength ( 0 ) ; } ) ;