miragejs/ember-cli-mirage

setupMirage under embroider?

x8BitRain opened this issue · 3 comments

Question

We have an Ember app with several hundred tests using ember-cli-mirage and we've got the app running on embroider but the tests we have use setupMirage // import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';

ex:

module('Acceptance | example...', function (hooks) {
  setupApplicationTest(hooks);
  setupMirage(hooks);

  module('example...', function (hooks) {

which can't be imported by embroider? It results in:

ERROR in ./tests/acceptance/test-test.js 4:0-60
Module not found: Error: Can't resolve 'ember-cli-mirage/test-support' in '$TMPDIR/embroider/b5931e/tests/acceptance'
 @ ./assets/test.js 8:13-69

So I read this and createServer can be imported from 'miragejs' by embroider.

What's the best way to get the tests working again under embroider? Are there any examples of tests that work with setupMirage and embroider or do I misunderstand completely?

Thanks!

The link you refer to still uses setupMirage, the code it refers to is how mirage/config.js should now be formatted.

Still learning embroider and trying to figure it out. Importing setupMirage should work the same as importing anything else from test support for any other addon. Embroider should see the import and include the code.

I am looking at ember-qunit and dont see a difference in how they configure and export setupApplicationTest vs how we are exporting setupMirage.

When you say you are using embroider, what exactly does that mean? You are setting the more stricter modes?

Okay thanks for the tip, I'm using embroider with the "Optimized Safe" flags.
I looked at my imports again and was able to make it work by changing it from:

import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';

to

import { setupMirage } from 'ember-cli-mirage/test-support';

My IDE tells me both imports are valid but embroider/webpack wasn't able to import the package the old way when embroider was added to the build pipeline.

@SergeAstapov This looks like another import that should be deprecated.

import { setupMirage } from 'ember-cli-mirage/test-support';

is the way it should be done. I didnt notice in your original post that you stated that. Not sure I would have noticed and it should have worked. But still learning how embroider works so good to know.