Replace mirage with real database


Hi, I would like to replace mirage with a real database connection. The problem is setting up test data. I don’t want to create them upfront in the database, because it’s very fragile and tends to get obsolete very fast. I would like to keep all my test data within the test.

I had an idea that I would call a CLI command before every test to reset the database and populate it with test data from the test. Is something like that possible using ember-cli?

I know that the tests run inside the browser which obviously can’t call any CLI command but during the compilation step, it should be possible to run some CLI commands as it runs inside the node, right?


This is definitely possible, though it requires a lot of pieces to work together.

We are already doing this in Cardstack (which is a framework with Ember on the front and a standard Node server on the backend), since we have control over the server and can bake this kind of support in. Here’s an example of a test that sets up models in the real server, all driven from an Ember acceptance test.

It also depends on having a special authorization path so that during tests your setup code has permission to do very intrusive things to the server’s data.


@edeblois wrote a great article explaining how to set this up in her Elixir + Phoenix + Ember stack: