-
Notifications
You must be signed in to change notification settings - Fork 18
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
Allow more customization of network mocking urls #53
Comments
Nice, totally agree! There's some work being done in #51 that exposes a better API for post requests. We can do something similar for gets as well. I thinking we should have Do you have an example of how you'd like to use |
Awesome that this is getting worked on, @ryanto!
As far customizing the path, the best example I can think of is dynamic segments. So something like And for the query string, maybe something where we're checking for a certain key, but don't care what the value is. Maybe: Ideally, we'd have the ability to use the function syntax in the reply and access the original request for these dynamic scenarios. But that may be out of scope for this. |
I've finally fixed the fastboot tests in my app, and the I could also use the "disabling real http requests" (with This made me wonder if it wouldn't be better to expose the whole nock functionality, via comlink-like interface: import { nock } from 'ember-cli-fastboot-testing/test-support';
test('…', async function() {
await nock.disableNetConnect();
await nock('https://api.example.com')
.get('/posts)
.reply(200, …);
}); This would allow to use every feature nock has to offer, without having to patch it in, one by one, to the ECFT. The downside is the tight coupling to |
Having direct access to the nock object would be awesome. @ryanto - thoughts? would that even be possible? |
Hey! Sorry for the late reply. One of the reasons I didn't give direct access to the nock object is because the tests are written in the browser, but nock runs in a node process. I was unsure of how to serialize all those object and function calls across the browser/server boundary. That's the short of why the mocking API is so limited. @CvX it sounds like comlink will give us a nice API for crossing that boundary? If so, I'm all for this! Giving full access to nock seems like it will solve a whole lot of these recent issues, and I'm not so worried about the tight coupling at this point since I don't really see the need for us needing to support multiple node mocking libraries. Thoughts? |
Alright, I initially thought I can get a proof-of-concept done in a single evening, but it took me a bit over two days. 😅 Comlink, in its current state, doesn't support the builder pattern (e.g. In the mean time, I have some other minor changes to ecft. I'll also start the PR with this new mocking interface to get things rolling. |
Wow, awesome! |
Comlink PR is ready: GoogleChromeLabs/comlink#311 And here's a preview of ember-cli-fastboot-testing changes: master...CvX:nock-proxy |
nock
has several customization options that would be nice to implement in ember-cli-fastboot-testing's network mocking. Just to mention a few:includes
option..query(true)
option to ignore the query string altogether. Otherwise, it's only a match if the query string is appended to the url with the exact full string.We also have this issue: https://github.com/embermap/ember-cli-fastboot-testing/issues
It seems like we either need a way to use nock's syntax when creating these mocks, or expand the API to allow several different customization options. Maybe something like:
(we'd have to move the status code into an option, and maybe deprecate the string as a 3rd param)
I'd be happy to work on a PR for this once we land on the approach.
The text was updated successfully, but these errors were encountered: