All files / src/run listRoutes.ts

91.67% Statements 11/12
100% Branches 0/0
66.67% Functions 2/3
90.91% Lines 10/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 333x   3x   3x 2x           2x               2x 2x         2x   2x     2x    
import Restapify from 'restapify'
 
import { getRoutesListOutput, onRestapifyInstanceError } from '../utils'
 
export const listRoutes = (rootDir: string): void => {
  const RestapifyInstance = new Restapify({
    rootDir,
    openDashboard: false,
    hotWatch: false
  })
 
  RestapifyInstance.onError(({ error }) => {
    onRestapifyInstanceError(error, {
      rootDir: RestapifyInstance.rootDir,
      apiBaseUrl: RestapifyInstance.apiBaseUrl,
      port: RestapifyInstance.port
    })
  })
 
  RestapifyInstance.on('start', () => {
    const servedRoutesOutput = getRoutesListOutput(
      RestapifyInstance.getServedRoutes(),
      RestapifyInstance.apiBaseUrl
    )
 
    console.log(servedRoutesOutput)
 
    RestapifyInstance.close()
  })
 
  RestapifyInstance.run({ startServer: false })
}