Nest: Test e2e gets 404 when using fastify

Created on 23 Mar 2019  路  6Comments  路  Source: nestjs/nest

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior


All the e2e tests get 404 error when fastify.

Expected behavior


The test should work as expected.

Minimal reproduction of the problem with instructions


Create base project with fasfify adapter, and add it to tests too:

app = module.createNestApplication(new FastifyAdapter());

What is the motivation / use case for changing the behavior?


The tests can run with express and the app with fastify but I think is a good point to test with the same adapter that the app will use.

Environment


Nest version: 6.0.2


For Tooling issues:
- Node version: v11.12.0
- Platform:  Mac

Others:
yarn 1.15.2
npm 6.4.1

needs clarification

Most helpful comment

@kamilmysliwiec your recommendation implies change all tests, to use supertest you only need to put await app.getHttpAdapter().getInstance().ready(); after call await app.init()... Check this file https://gitlab.com/gperdomor/todo-backend-nestjs/blob/master/test/app.e2e-spec.ts

@yostools @xavi-dev FYI

All 6 comments

Please, provide a minimal repository which reproduces your issue.

debug-fastify.zip

Just run yarnand then npm test

Fastify mounts routes on listen() call which means that init() is not enough. With fastify you basically don't have to use supertest at all, simply simulate request instead using inject() method, see example here: https://github.com/nestjs/nest/blob/master/integration/hello-world/e2e/fastify-adapter.spec.ts. I have to clarify this in the documentation

@kamilmysliwiec your recommendation implies change all tests, to use supertest you only need to put await app.getHttpAdapter().getInstance().ready(); after call await app.init()... Check this file https://gitlab.com/gperdomor/todo-backend-nestjs/blob/master/test/app.e2e-spec.ts

@yostools @xavi-dev FYI

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cdiaz picture cdiaz  路  3Comments

mishelashala picture mishelashala  路  3Comments

tronginc picture tronginc  路  3Comments

menme95 picture menme95  路  3Comments

artaommahe picture artaommahe  路  3Comments