GithubHelp home page GithubHelp logo

Comments (16)

zeppelin avatar zeppelin commented on July 20, 2024 2

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.

ryanto avatar ryanto commented on July 20, 2024 1

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.

ryanto avatar ryanto commented on July 20, 2024 1

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.

ryanto avatar ryanto commented on July 20, 2024 1

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.

ryanto avatar ryanto commented on July 20, 2024

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.

ryanto avatar ryanto commented on July 20, 2024

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.

CvX avatar CvX commented on July 20, 2024

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.

ryanto avatar ryanto commented on July 20, 2024

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.

williamweckl avatar williamweckl commented on July 20, 2024

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.

williamweckl avatar williamweckl commented on July 20, 2024

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.

samselikoff avatar samselikoff commented on July 20, 2024

@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.

williamweckl avatar williamweckl commented on July 20, 2024

@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.

samselikoff avatar samselikoff commented on July 20, 2024

@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.

ryanto avatar ryanto commented on July 20, 2024

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.

williamweckl avatar williamweckl commented on July 20, 2024

@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.

ryanto avatar ryanto commented on July 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.