Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can mirage be used for testing? #316

Open
RobbieTheWagner opened this issue Nov 30, 2019 · 10 comments
Open

Can mirage be used for testing? #316

RobbieTheWagner opened this issue Nov 30, 2019 · 10 comments

Comments

@RobbieTheWagner
Copy link

I'm using the ember-data adapters from this addon, and I would like to write tests now. I setup some mirage fixtures, and loaded them, and it seems that the data is not loaded in. I am guessing because of the magic of the adapters. Is there any way to use this with mirage?

@RobbieTheWagner
Copy link
Author

It seems like something like this works:

import DS from 'ember-data';
import EmberLocalStorageAdapter from 'ember-local-storage/adapters/local';
import ENV from 'swach/config/environment';

let Adapter = EmberLocalStorageAdapter;

if (ENV.environment === 'test') {
  Adapter = DS.JSONAPIAdapter;
}

export default Adapter;

We should decide how we want to best support Mirage and document it.

@fsmanuel
Copy link
Member

fsmanuel commented Dec 1, 2019

Hey @rwwagner90,
interesting question. I never tried to run mirage with ELS. As far as I understand, the goal of mirage is to mock your server. As ELS never talks to the server it’s kind of confusing to use mirage. But I get your point that testing has no story, yet.

A comment about your approach from above: That would just test the JSONAPIAdapter which is not too different to ELS Adapter but not the same thing.

I’ll need to think about it more but here is a quick suggestion. You can create some records in your app and use the export feature to export it to a JSON file. Then in your tests you can import that file and use it as fixtures.

@RobbieTheWagner
Copy link
Author

@fsmanuel I have it working with Mirage currently. I would love if we could get a more official Mirage solution in place though.

@RobbieTheWagner
Copy link
Author

@fsmanuel have you given this any more thought? We're hitting some issues now where running the tests against a mirage setup that doesn't use ELS is causing issues.

@fsmanuel
Copy link
Member

Hey @rwwagner90, as I said I don't think we can use Mirage for the tests as ELS never issues a network request that Mirage can intercept. What you are doing is testing JSONAPIAdapter.

Are you on Discord? You can ping me there (fsmanuel) so we can talk about it.

@fsmanuel
Copy link
Member

As discussed on Discord, the idea is to use mirage db to populate LocalStorage.

@fsmanuel
Copy link
Member

Hey @samselikoff, do you have any input on that?

@samselikoff
Copy link

Not really familiar with this addon – does it store network / ember-data payloads into localStorage?

You can call server.db.dump() to dump out Mirage's database, and server.db.loadData(data) to load it back in. Folks have used that before to make Mirage "persist" after a page reload.

@fsmanuel
Copy link
Member

@samselikoff thanks for the info and the pointer to dump. Yes, the addon stores JSON API payloads into localStorage.

@fsmanuel
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants