-
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
Add notice for testing with fake servers #2
Comments
Thanks for the report! I don't think this should be needed, since in the fastboot test you should not be starting the mirage server. Is your fastboot test turning on mirage? cc @samselikoff |
Just wanted to follow up on this. Mind sharing your fastboot test with me that's requiring you to do this? |
I had the same "issue", i.e. had to define the passthrough path in mirage config. Here's my test: import { module, test } from 'qunit';
import { setup, visit } from 'ember-cli-fastboot-testing/test-support';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
module('FastBoot | product list test', function(hooks) {
setup(hooks);
setupMirage(hooks);
hooks.beforeEach(function() {
this.server.create('home');
});
test('it has the correct page title', async function(assert) {
let { htmlDocument } = await visit('/some/path');
assert.dom('head title', htmlDocument).hasText('The title');
});
}); |
Ah I see. You should remove Mirage runs in the browser. It works by intercepting XHR requests and returning the data you've created with factories. Fastboot testing runs inside of ember-cli. When you run fastboot testing's That means any factory data you create will inside of these tests cannot be use, since the browser cannot intercept XHR requests made by node. There's currently some work being done to get mirage running inside of fastboot. When that happens we'll make sure this addon and mirage play nicely together! I'm going to close this issue, but feel free to reopen with any questions. |
Yes, so it's not about mocking HTTP requests, but if Mirage is started automatically (which is likely the case with older Mirage & testing setups), it'll prevent ECFT from accessing the middleware from the browser. |
Yup, good point. I would recommend using the generator to create the fastboot tests, they'll ensure the new style test that won't autostart mirage. it works great, even inside of 2.x apps. I'm a little torn on adding direct knowledge of mirage into this addon. Not everyone uses mirage and having this addon aware of all the ways XHR requests get intercepted could be tricky, that's mainly where my pushback is coming from. At the end of the day if it helps users get unstuck then you can convince me it's good for the project. Would having this in the docs have helped you to find the issue faster? |
Ok after discussing this with Sam I think we can detect the XHR request failing and log an error that tells the user they might be running a fake server. That allows us to not worry about detecting mirage, but gives the user valuable info on why the test is failing. I'll get a few test cases wired up that use mirage and make sure an error is shown. |
Is there a way to mock http requests when testing fastboot? Tried using mirage, pretender, factory guy and had no success... |
Now I've tried to use ember-fetch AdapterFetch mixin at application adapter too... |
@williamweckl It's on Mirage's roadmap for sure, but hasn't been built yet. Focused on shipping Mirage 1.0 first. |
@samselikoff but is there a way to work this out yet? I don't think I can use this lib if I can not mock http requests... Any uggly way works for me now until mirage don't release this feature. |
@ryanto Isn't there an ugly way that we mock HTTP requests in fastboot during tests? Any code we can share? |
Hi @williamweckl - Since fastboot runs in a node process, it's best to use a node http mocking library like nock to accomplish this. There's currently work in #36 that's attempting to wire all this up for you. It's unfinished, but you can poke around that branch. We're pretty happy with where we landed, but since it hasn't been merged the API might change. Also, I created a new issue to discuss network mocking here. This original issue was opened to discuss mirage intercepting ECFT's call to ember-cli when it shouldn't be. I'd like to keep this issue focused on that. |
@ryanto thanks for answering this! I'll probably wait for the feature release, tried to use nock but I don't know how to import non ember dependencies to my project, sorry but I'm a beginner in this kind of stuff. I'm using ember for a wile but never had to do that. If someone have some examples to show me how to use nock with this lib would be great, if not I can wait for the release. Thanks a lot for the amazing job done so far! |
Sounds good @williamweckl. I'd say if you can, wait for the release. I don't have a timeline for it, but it's a high priority for me since I need it in one of my apps :) |
For example, Mirage needs this, otherwise requesting
/__fastboot-testing
fails:The text was updated successfully, but these errors were encountered: