embermap / ember-cli-fastboot-testing

Test your FastBoot-rendered HTML alongside your application's tests.
https://embermap.github.io/ember-cli-fastboot-testing
MIT License
39 stars 18 forks source link

Support for ember projects with a rootURL containing a subdirectory #180

Open jordanbyron opened 5 years ago

jordanbyron commented 5 years ago

Hi Ya'll!

Unless I am mistaken, it doesn't appear this library supports ember projects hosted from within a subdirectory: rootURL: "/my-ember-app/" for example.

mockServer and visit all assume the ember project is being hosted at the bare root and as a result requests are missing the ember app.

I've poked around the code and see a few places I think would need to be changed to respect the host app's rootURL configuration. Let me know if this is something you plan on supporting or think would be easy to add support for.

Excellent work on the project. I was really excited to get this up and running and the documentation is stellar!

ryanto commented 5 years ago

Hey @jordanbyron! Glad to hear you're liking the addon.

I think this is something we would be interested in supporting, I have two quick questions.

  1. What's the work around today? If the rootUrl = "/my-ember-app", Are you able to use visit('/my-ember-app/page1')? Or does visit not work with any URL?

  2. How does rootUrl work with Ember's acceptance tests?

Thanks!

jordanbyron commented 5 years ago

Hey @ryanto,

What's the work around today?

Right now I don't have one.

If the rootUrl = "/my-ember-app", Are you able to use visit('/my-ember-app/page1')? Or does visit not work with any URL?

It does not work with fastboot tests, even if we prepend our sub directory to the visit string, as you did in your example. It appears all of the requests from fastboot-testing are hitting the server directly at the bare root url, not the sub directory, so they are missing the ember server entirely. Here is an example from our rails log which lives at the root:

Started GET "/__cleanup-mocks"
Started POST "/__fastboot-testing"

Obviously rails does not know how to respond to those requests, and they should instead be hitting /${config.rootURL}/__fastboot-testing.

The end result in our ember tests being:

Ember CLI FastBoot Testing: We were unable to render PATH. Is your test suite blocking or intercepting HTTP requests?

How does rootUrl work with Ember's acceptance tests?

Excellent question. In our acceptance tests we don't have to specify the rootURL when we call visit. I'm not sure what is happening under the hood, but regardless of what we have set for rootURL it seems to work as expected.

It may be worth pointing out that depending on our environment we do have different values in our config for rootURL, which is used by ember in the index.html file among other places, and EmberRouter#rootURL. I don't think those differences should matter as they are just a side effect for how our ember app is deployed, but I wanted to point them out just in case.

Hopefully that helps clarify what we are seeing. I'm happy to answer any more questions or spin up an example app if that would help illustrate what we are seeing.

ryanto commented 4 years ago

Hey @jordanbyron

Sorry - this totally fell off my radar!

Thanks so much for doing all the research and writing all this up, it's super helpful!

I won't have time in the next few months to implement this, but this should be something fastboot-testing supports out of the box!

I think the best bet is for us to copy the same API that acceptance testing follows. Switching between acceptance tests and fastboot tests shouldn't require knowledge of inner workings, in fact I think visit should pretty much be copy & pasteable :) So let's do what they're doing.

Thanks again for writing all this up, really appreciate it!