import test from "ava" ; import * as path from "path" ; import Kost from "./index" ; import * as request from "supertest" ; import { paths , setCurrentWorkingDir } from "./src/path" ; test ( "index" , async ( t ) => { t . deepEqual ( process . env . NODE_ENV , "test" ) ; } ) ; test ( "basic" , async ( t ) => { setCurrentWorkingDir ( path . join ( process . cwd ( ) , "build" , "__test__" , "controller-test-example" ) ) ; const app = new Kost ( ) ; await ( < any > app ) . init ( ) ; const server = request ( app . callback ( ) ) ; const res1 = await new Promise ( ( resolve , reject ) => { server . get ( "/" ) . end ( ( err , res ) => ( err ? reject ( err ) : resolve ( res ) ) ) ; } ) ; t . deepEqual ( res1 . text , "hello world" ) ; const res2 = await new Promise ( ( resolve , reject ) => { server . get ( "/name" ) . end ( ( err , res ) => ( err ? reject ( err ) : resolve ( res ) ) ) ; } ) ; t . deepEqual ( res2 . text , "axetroy" ) ; } ) ; test ( "invalid middleware" , async ( t ) => { let app ; t . notThrows ( function ( ) { app = new Kost ( ) . use ( "hello" ) ; } ) ; try { await app . init ( ) ; } catch ( err ) { t . true ( err instanceof Error ) ; } } ) ;