0
votes

I have an Ember addon which is supposed to handle a request to return some data. The main app needs to use this addon, so that requests to retrieve this data are retrieved from mirage. At some point in the future this needs to be disabled in live environments (but not for the time being)

My question is where the mirage directory (and its subdirectories such as factories, fixtures, models, routes etc) should be located in an addon. Should it be in the project root or elsewhere, such as in the app or addon subdirectory?

I have run:

ember install ember-cli-mirage

which creates some files in \tests\dummy\mirage

Creating the files in this directory doesn't seem to work:

/tests/dummy/fixtures/mydata.js

export default [{
"title": "Some data here"
}]

/tests/dummy/routes/mydata.js

class MyDataRoutes {

constructor(routerFnc, route, db) {
    routerFnc(route + '/', ({db}) => {
        return db.mydata;
    });
}
}

export default MyDataRoutes;

/tests/mirage/config.js:

export default function() {

// this.urlPrefix = '';    // make this `http://localhost:8080`, for example, if your API is on a different server
this.namespace = 'api';    // make this `api`, for example, if your API is namespaced
this.timing = 100;      // delay for each request, automatically set to 0 during testing

new MyDataRoutes(this.get, '/content/mydata', this.db);

}
1

1 Answers

0
votes

This is the right place. You will then be able to use your mirage endpoints either in your tests or in the dummy app directly.

If you want an example of how that would all work together, you can have a look at the repo for ember-power-select https://github.com/cibernox/ember-power-select. They have mirage as well as nice tests in place.