-
Notifications
You must be signed in to change notification settings - Fork 3
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
Dynamic response #1
Dynamic response #1
Conversation
This is a really powerful feature and definitely a missing piece. I have a feeling that it would be more flexible to expose it by letting the function generating the response take Since |
With your kind explanation and that link the penny has dropped - I see what you were getting at. Leave this with me :) |
Great, looking forward to see what you'll come up with! And to using it. |
Make is possible to supply a resultProperties function that calculates the response based on the request that was supplied.
Right, I've just force pushed this branch again. This time it passes down req/res objects, intercepts the responses, arranges for the request assertion to run and then completes the underlying response and asserts that. Am very curious to see what you think :) |
request: { | ||
method: 'GET', | ||
url: '/404' | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shorthand: request: 'GET /404'
or even request: '/404'
Ahh yes, cool. I think they may read like that now as a result of being fiddled with during some quality node-inspector time. Will look at another cleanup pass. |
This looks really great! I'll be happy to merge it in its current state. I have a couple of follow-up feature requests: Capturing the low-level responseI recently changed unexpected-express to capture the response generated by the express app by looking at what's written to the socket rather than into the That enables us to assert things about the chunked encoding. The original usecase was a one we ran into at the ol' company where an express handler had to write bogus into the socket in order to force a browser downloading a big file to consider the download to have failed. Once a certain amount of data had been streamed, Chrome simply refused to realize that the download had failed unless we did that, otherwise it would leave a truncated file on disc and allow the user to open it. To test this piece of code we needed to assert that the raw response body ( Also, node.js (0.12+ I think) plays some tricks when you provide non-ASCII chars in a header. If the chars can be represented in iso-8859-1, it will output them like that. This happens right before the bytes are written into the socket, so you need to listen the raw socket output in order to know what actually happened, neither Longer conversations with a dynamic responseCould there be some kind of shorthand for saying that a series of requests is to be processed by the same app? |
I've invited you to be a collaborator on the project here on github and added you as an owner of the npm package. You're welcome to merge the PR yourself and release a new version. |
Thanks very much @papandreou, will gladly accept :) Re your feature requests:
|
I don't have any marking conventions, except for the conversation here :). Let's make this a minor release unless we suspect it'll break backwards compatibility. |
Can I get an initial review for this?
This pull request makes it it possible to supply a function as the response property which will generate a dynamic response based upon the request object.
This version allows an generating the response to be an asynchronous operation. It comes with tests of the success and failure cases.