Turn off ember-cli-mirage

Hi all,

It’s possible to use ember mirage only for tests? Currently I set another namespace variable in test environment.

http://localhost:4202/tokens       >>> Called in the running application
http://localhost:4202/test/tokens  >>> Namespace "/test" is set for test environment only

After installing ember-cli-mirage ALL requests are redirected by ember mirage. For our application we have real requests to a gateway. We only need ember mirage for testing. Is this possible?

Best regards, Mario

Check the official documentation link

Basically you can specify in the environment.js when do you want ember-cli-mirage to be enabled:

example:

if (environment === 'production') {
  ENV['ember-cli-mirage'] = {
    enabled: true
  };
}

Ah… very thanks to you. In the same moment I found this documentation too. :slight_smile:

Greetings Mario

Ok… still not all fine. :slight_smile:

In my environment “development” ( in my Application ) the defined mirage rules will used correctly. But in my acceptance test mirage writes an error:

'Mirage: Your Ember app tried to POST \'http://localhost:4202/tokens\',\n         but there was no route defined to handle             this request.\n         Define a route the at matches this path in your\n         mirage/config.js file. Did you forget to add your namespace?' { description: 'Mirage: undefined',  message: 'Mirage: Your Ember app tried to POST 'http://localhost:4202/tokens\',\n         but there was no route defined to handle this request.\n         Define  a route that matches this path in your\n         mirage/config.js file. Did you forget to add your namespace?',   name: 'Error',   stack: 'Mirage: Error: Your Ember app tried to POST \'http://localhost:4202/tokens\',\n         but there was no route defined to handle this request.\n         D efine a route that matches this path in your\n         mirage/config.js file. Did you forget to add your namespace?\n    at new MirageError (http://localhost:4203/a ssets/vendor.js:132407:21)\n    at assert  http://localhost:4203/assets/vendor.js:132394:13)\n    at Pretender.unhandledRequest (http://localhost:4203/assets/vendor [Press ENTER to run tests; q to quit; p to pause]

Currently in both use cases I used no different namespace. ( both the same ) In the app all is fine. In the test mirage do not find my defined mirage routes.

Any ideas?

[EDIT] In my acceptance test there is this route definition set on first line:

server.post('/tokens', () => {
    return new Mirage.Response(200, {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'authentication-token': generateToken()
    }, {});
});

Greetings Mario

Are you sure that’s the only test that access to that route? In the documentation says that the handler server.post only works for that specific test:

This route handler definition is only in effect for the duration of this test, so as soon as it’s over any handler you have defined for POST to /questions in your config.js file will be used again.

Problem solved. The problem was the host. Mirge do not tells me in the log whether the host is set relative or absolute.

After setting the host in the mirage/config.js, the test could use the defined route too. My test route definition in my test was removed before…

:slight_smile: