ember-cli-mirage: Server is undefined while in test environment

First and foremost, thanks for writing up this addon! It is such a great addition to the community.

Problem When running tests at http://localhost:4200/tests I’m getting ReferenceError: server is not defined. Not sure exactly how this might be happening since I’ve enabled ember-cli-mirage for testing mode only.

Note: This error does not occur when running ember test

config/environment.js

module.exports = function(environment) {
  var ENV = {
    modulePrefix: 'cio',
    environment: environment,
    baseURL: '/',
    locationType: 'auto',
    EmberENV: {
      FEATURES: {}
    },

    APP: {}
  };

  ENV.APP.FORCE_REST_ADAPTER = false
  ENV.APP.PROFILE_RENDERS = false
  // Disable ember-cli-mirage by default, we want to use our local api for development
  ENV['ember-cli-mirage'] = {
    enabled: false
  };

  if (environment === 'development') {}

  if (environment === 'production') {}

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

    // Root Element
    ENV.APP.rootElement = '#ember-testing';

    // Testem prefers this...
    ENV.baseURL = '/';
    ENV.locationType = 'none';

    // keep test console output quieter
    ENV.APP.LOG_ACTIVE_GENERATION = false;
    ENV.APP.LOG_VIEW_LOOKUPS = false;

    ENV.APP.rootElement = '#ember-testing';
  }

  return ENV;
};

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 24 (12 by maintainers)

Most upvoted comments

I do see the logic in index.js is wrong, I need to include Mirage during development build even if enabled: false is specified, precisely for this reason.

To get around this for now, remove the enabled: false option from your default config, and either use ember test --server, or add a blank file under /server/proxies or pass the --proxy option. (You can remove the enabled: true line as well, it’s enabled by default).