Comments (16)
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.
from ember-cli-fastboot-testing.
Ah I see. You should remove setupMirage(hooks)
from this test because it's not doing what you think it's doing... let me explain why.
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 visit('/some/path')
, you're asking ember-cli's node instance to generate the fastboot html for /some/path
. Since this request runs inside of node, and not the browser, there's no way mirage can intercept and serve those AJAX requests.
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.
from ember-cli-fastboot-testing.
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.
from ember-cli-fastboot-testing.
Hey @zeppelin @CvX - This has been fixed and released as 0.0.13
. For now I'm only printing a nice error message when we detect a fake server. Maybe we can improve this with some better docs in the future.
from ember-cli-fastboot-testing.
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
from ember-cli-fastboot-testing.
Just wanted to follow up on this. Mind sharing your fastboot test with me that's requiring you to do this?
from ember-cli-fastboot-testing.
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');
});
});
from ember-cli-fastboot-testing.
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?
from ember-cli-fastboot-testing.
Is there a way to mock http requests when testing fastboot? Tried using mirage, pretender, factory guy and had no success...
from ember-cli-fastboot-testing.
Now I've tried to use ember-fetch AdapterFetch mixin at application adapter too...
Is there any instructions to mock http requests? Could be added to readme?
Thank you.
from ember-cli-fastboot-testing.
@williamweckl It's on Mirage's roadmap for sure, but hasn't been built yet. Focused on shipping Mirage 1.0 first.
from ember-cli-fastboot-testing.
@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.
from ember-cli-fastboot-testing.
@ryanto Isn't there an ugly way that we mock HTTP requests in fastboot during tests? Any code we can share?
from ember-cli-fastboot-testing.
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.
from ember-cli-fastboot-testing.
@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!
from ember-cli-fastboot-testing.
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 :)
from ember-cli-fastboot-testing.
Related Issues (20)
- Does not work with path=dist HOT 5
- Allow user to access fastboot instance in fastboot-testing.js config HOT 5
- Allow user to pass functions inside the `options` parameter while calling `visit` HOT 1
- Support for ember projects with a rootURL containing a subdirectory HOT 3
- Deprecation Warning in Ember 3.9+ HOT 2
- Visit helper not returning correct content upon using `this.replaceWith` for redirection HOT 4
- FastBoot.distPath returns deleted path upon running `ember test` HOT 2
- Allow for custom host in mockServer calls HOT 2
- mockServer.get not working HOT 6
- Error messages are not escaped
- Build fails with latest Babel.js
- A future for this repo. HOT 4
- najax not present when using jQuery in v0.4/v0.5 HOT 1
- Add ability to specify response headers in mocked responses HOT 1
- Use config/fastboot.js instead of separate config/fastboot-testing.js HOT 2
- Config not working HOT 5
- [0.6.0] req.headers.origin undefined in CLI mode
- Skip outputReady in production builds HOT 4
- Cut new release v0.6.1 HOT 4
- Monorepo support HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ember-cli-fastboot-testing.