I'm trying to setup supertest with my Hapi.js server. I'm not sure if this is the correct way. Please advise me on what is..
in my server.js,
const const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({
// host: '0.0.0.0',
port: process.env.PORT || 8080,
routes: { cors: true }
});
server.route([
{
method: 'GET',
path:'/',
handler: (request, reply) => {
return reply('hello world');
},
config: { auth: false }
}
]);
module.exports = server;
then in my server.test.js
const request = require('supertest');
const server = require('./server');
it('gets a response', () => {
request(server)
.get('/')
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200, done);
});
am I exporting the wrong thing?
Use server.listener
same issue with fastify
Regarding fastify:
fixed with request(app.server)
you might also want to use a specific port / depending on how complex your tests are...
app.listen('3001');
Most helpful comment
Use
server.listener