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

Describe how to use Shot Request/Response mocks #760

Closed
2 tasks
bajtos opened this issue Nov 21, 2017 · 6 comments
Closed
2 tasks

Describe how to use Shot Request/Response mocks #760

bajtos opened this issue Nov 21, 2017 · 6 comments
Assignees
Labels

Comments

@bajtos
Copy link
Member

bajtos commented Nov 21, 2017

See strongloop-archive/loopback4-example-rpc-server#1 (comment) for background information.

We should improve testlab's README to show how to use Shot and mockResponse for mocking/stubbing HTTP request and response objects.

Acceptance criteria

Expand the shot section of testlab's README (packages/testlab/README.md#shot) to explain users:

  • How to create a mocked/stubbed HTTP request and use it in places that require only the request object (without the response object; these places are typically dealing with request parsing).
  • How to create a mocked/stubbed HTTP request and response, how to await the response (wait until the request is handled) and how to inspect the response returned by the server.

Each topic should include a short code snippet to illustrate the intended usage.

@dhmlau
Copy link
Member

dhmlau commented Apr 11, 2018

@bajtos , assigned this to you for grooming. Could you please add the acceptance criteria? thanks.

@bajtos
Copy link
Member Author

bajtos commented Apr 16, 2018

assigned this to you for grooming. Could you please add the acceptance criteria? thanks.

@dhmlau done

@b-admike
Copy link
Contributor

b-admike commented Apr 17, 2018

Based on our meeting today, we think it's good for us to decide the http library we are going to use going forward from #1071 (comment) and #1255 and whether or not it's compatible with Shot.

@bajtos
Copy link
Member Author

bajtos commented Apr 18, 2018

FWIW, Shot is a stub for the HTTP request/response objects as provided by Node.js core. I'd expect any framework-specific request/response objects to extend these builtin objects, therefore Shot stubs may be still useful. We'll see!

@b-admike
Copy link
Contributor

Yeah I think we all agree that they'd be useful, it's just the compatibility we'd like to figure out (which, like you said, should not be an issue since they extend from the core).

@b-admike
Copy link
Contributor

I was looking around and it looks like Shot has 8 dependents looking from npmjs. One of its dependents, artificial, ports it to work with Express:

Inject fake HTTP request/response into an Express server. This is a port of hapi's shot module, adapted to work with Express. artificial allows fake responses to be injected into a server without first binding to a port. This simplifies testing.

link: https://www.npmjs.com/package/artificial
So it might not work right off the bat with Koa as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants