Echo JS 0.11.0

<~>
faceyspacey 2690 days ago. link parent 1 point
So it's another way to accomplish what you might do with supertest right:

*server/index.js:*
```
export default function startServer() {
  const app = express()

  // ... regular app.use stuff etc

  const server = http.createServer(app)

  if (process.env.NODE_ENV !== 'test') {
    server.listen(process.env.PORT || 80, () => {
      console.log('Listening on %j', server.address())
  })

  return server
}
```

*__tests__/server.js:*
```
import request from 'supertest'
import startServer from '../server'

it('REQUEST: /', async () => {
    const server = startServer()
    const path = '/'
    const res = await request(server).get(path)
    expect(res.status).toEqual(200)
})
```

??

Replies

tracker1 2687 days ago. link 1 point
No, it's a way to do unit tests without actually starting a server.  but could work for your supertest example for more integration like testing.