miragejs / ember-cli-mirage

An Ember Addon to easily add Mirage JS to your Ember app.
http://ember-cli-mirage.com
MIT License
863 stars 439 forks source link

No serializer when building with Embroider #2579

Open bartocc opened 2 months ago

bartocc commented 2 months ago

When building our app with embroider, many tests fail because the serializer is not properly loaded by mirage and ember-data errors telling us that the response does not contain the required fields, like data

I've tracked this down to https://github.com/miragejs/ember-cli-mirage/blob/master/packages/ember-cli-mirage/addon/utils/read-modules.js, where ember-cli-mirage tries to find module names like my-app/serializers/*, etc…

But when the mirage folder is a sibling of the app folder, these modules do not exit in the final build because Embroider does not consume the mirage folder

I've tried moving the mirage folder inside the app folder, and both a classic build and an embroider build seem to work…

Is that a workaround you would recommend? I wonder if doing so, the mirage files would not end up in the prod build 🤔

cah-brian-gantzler commented 2 months ago

If you are only referring to the mirage files in tests, I think you have to do the following to get embroider to tree shake out the mirage folder.

 const { Webpack } = require('@embroider/webpack');
  return require('@embroider/compat').compatBuild(app, Webpack, {
    staticAppPaths: ['mirage'],
    // extraPublicTrees: [extraTreeHere]
    // staticAddonTestSupportTrees: true,
    // staticAddonTrees: true,
    // staticHelpers: true,
    // staticModifiers: true,
    // staticComponents: true,
  });

While they are making it slowly better, there are several things that still do not play well with embroider in this repo. I created a stripped down version of this repo that does play well with embroider and what I have been using for a while. https://github.com/bgantzler/ember-mirage. There are a few things it does not support and you have to do manually, see migration https://github.com/bgantzler/ember-mirage/blob/main/docs/migration.md, if you are ok with that, you can use that repo. Otherwise you may have to wait while this library gets updated.

Eventually I am assuming they will be pretty equal. Should that happen, assume this one would survive since it is more known.