Api calls getting redirected (Moved Temporarily) using Ember-cli, ember test --server, and http-mock


#1

I have some http-mock request/responses I’d like to use only in a testing environment. Our API is completely built out, so I’d only like to use the mocks when running ‘ember test --server’ or ‘ember test’ (CI mode). I’m running into a few issues setting this up and was hoping someone had a solution.

When I run 'ember test --server ', tests run at an url that’s like http://localhost:7357/7150/tests/index.html

However, any time a request to the backend is made I get a 302 Moved Temporarily response. For example, when the client does a GET to what I would expect would be my data endpoint url in this testing mode: http://localhost:7357/brands/1, I get the 302 response and the url is redirected to http://localhost:7357/brands/1/test/index.html (which does not exists)

the mock works fine when I run tests in a browser using port 4200, ie http://0.0.0.0:4200/tests

I think I’m missing some magic configuration somewhere. Anyone know how I can get my ‘ember test --server’ to utilize my mocked out backend using ember-cli’s http-mocks?


#2

I’m getting the same, did you have any luck working this out?


#3

This SO post had the answer: http://stackoverflow.com/questions/24053248/how-to-get-test-to-access-ember-cli-server-when-run-in-ci-mode

And this commit demonstrates it: https://github.com/voluspa/vilive/commit/948962e2e0cfd1a11c4f47bd9438007d505c8d77

You need to tell ember test to hit a running Ember server (which you have made accept CORS), which proxies the request to your test server (e.g. Rails).

Or you could get your test server to accept CORS directly instead.


#4

thanks. we ended up using Pretender to always stub out api calls in our tests instead


#5

Have a look at https://github.com/samselikoff/ember-cli-mirage/.

We were also using http-mock + Pretender combo earlier. Recently moved to ember-cli-mirage, which works flawlessly and gives you best of both.