ember-cli-mirage icon indicating copy to clipboard operation
ember-cli-mirage copied to clipboard

Fixtures always appear in application tests

Open ijlee2 opened this issue 4 years ago • 2 comments

In an Ember 3.16 app, I'm using fixtures to set up data for development and production. You can find a sample app at https://github.com/ijlee2/test-mirage-fixtures.

I'm always seeing the fixtures in my tests, even though I didn't call this.server.loadFixtures();, as described in the documentation. Because the fixtures that I have are large, the tests take longer time to complete.

In addition, it seems that if there are 2 tests in the module, the second one results in an error.

mirage_fixtures

In the sample app, if I use server.create() instead of fixtures in scenarios/default.js, the tests correctly don't see any records.

I wonder if the conditional logic in https://github.com/miragejs/miragejs/blob/master/lib/server.js#L499-L506 doesn't always work for Ember tests. Can you look into this?

Thanks,

ijlee2 avatar Mar 24 '20 21:03 ijlee2

Unfortunately that logic is really bad and just kinda grew over time. I have plans to change it but right now it's very funky. I would say either (1) define an empty factory, even if you don't use it, just so you have more control over when loadFixtures() is called, or (2) move your fixtures somewhere else, and just "load" them into Mirage by calling server.db.loadData(fixtures), and then you can do that in your default scenario for development and for tests in each test.

Let me know if that all makes sense.

samselikoff avatar Mar 25 '20 13:03 samselikoff

Thanks, @samselikoff . I think I understand what you meant by both options. The 2nd option may be a better approach in my case, as I wanted to try importing fixture files to do something else.

ijlee2 avatar Mar 25 '20 13:03 ijlee2