title: koa/supertest - server.close is not a function
body: <p>I've seen previous posts where the issue was that you need to export the instance to be able to call <code>close()</code> on the server. I have tried that however I am still getting that error</p>
  
  <h3>index.ts</h3>
  
  <pre class="lang-js prettyprint-override"><code>import * as Koa from "koa"
  import * as logger from "koa-logger"
  import * as json from "koa-json"
  import * as bodyParser from "koa-bodyparser"
  import * as cors from "koa-cors"
  import errorHandler from "./middlewares/errorhandler.middleware"
  import router from "./routes"
  
  const PORT = process.env.PORT || 3000;
  const ENV = process.env.NODE_ENV || 'development';
  const app = new Koa()
  
  app
      .use(logger())
      .use(bodyParser())
      .use(errorHandler)
      .use(router.routes())
      .use(router.allowedMethods())
      .use(json())
      .use(cors())
  
  
      export const server = app.listen(PORT, (): void =&gt; console.log(` Server listening on port ${PORT} - ${ENV} environment`))
  
  </code></pre>
  
  <p>I have also tried different ways of exporting</p>
  
  <pre><code>const appServer = app.listen(...)
  export default appServer
  </code></pre>
  
  <h3>test file</h3>
  
  <pre class="lang-js prettyprint-override"><code>const request = require('supertest');
  const server = require('../index');
  beforeAll(async () =&gt; {
   // do something before anything else runs
   console.log('Jest starting!');
  });
  // close the server after each test
  afterAll(() =&gt; {
   server.close();
   console.log('server closed!');
  });
  describe('basic route tests', () =&gt; {
   test('get home route GET /', async () =&gt; {
   const response = await request(server).get('/');
   expect(response.status).toEqual(200);
   expect(response.text).toContain('Hello World!');
   });
  });
  </code></pre>
  
  <p>also, if I change the <code>const server = require("../index.ts")</code> statement into an import then I get the error : <code>Property 'close' does not exist on type 'typeof import("/Users/path/to/file/")</code></p>
  
  <p>So that might be part of the issue as well.</p>