Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm supertest intercepts middleware and does not run boot scripts #298

Closed
varunj90 opened this issue Nov 18, 2015 · 3 comments
Closed

npm supertest intercepts middleware and does not run boot scripts #298

varunj90 opened this issue Nov 18, 2015 · 3 comments

Comments

@varunj90
Copy link

We are registering our middleware handler in server/middleware.json like the following:

image

When performing integration tests using supertest :

image

the code does not go through our middleware which contains the error handler because of which we get errors like

here11111111111111111111111111111111111111111111:
{ [Error: Parse Error] bytesParsed: 9, code: 'HPE_INVALID_STATUS', response: undefined }

OR
here11111111111111111111111111111111111111111111:
[TypeError: Cannot read property 'header' of undefined]

We suspect that we have a missing configuration with supertest ;
or
We might need some code that starts up in server.js that links supertest properly using loopback.

Can you advice us on getting this to work as it is a major roadblock.

Thank you !

@varunj90
Copy link
Author

image

image

image

Anything that is other than code 2xx ; example in this case 500; fails with 'res' being undefined?

@varunj90
Copy link
Author

@raymondfeng

Latest Finding: if we add the following code snippet for the unit tests, they actually pass

image

Reference in server.js : start function

image

Reference in server.js : stopServer function

image

Although, we shouldn't be required to start and stop a server since that's the job of supertest; but this to some extent confirms the issue of 'res' being undefined because the supertest server shuts down early? Is this a bug in supertest? Thoughts?

@mikelax
Copy link
Contributor

mikelax commented Jan 6, 2016

Although, we shouldn't be required to start and stop a server since that's the job of supertest; but this to some extent confirms the issue of 'res' being undefined because the supertest server shuts down early? Is this a bug in supertest? Thoughts?

@varunj90 I actually don't think that supertest is responsible for setting up and tearing down an api server. The few examples in the README.md include express and set up a quick express server for the sake of a quick demo. supertest is a wrapper around superagent and handles making requests and evaluating responses, but not the actual server.

@mikelax mikelax closed this as completed Jan 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants