testingember.jsember-cliember-cli-mirage

Place to put assets for dev/test in emberjs


I'm using mirage to mock some data and I'd like to mock an <img> with the appropriate file.

The problem is that I will have to place the image in /public/assets and the images placed there will be deployed later on as well.

Is there a way to avoid this? I couldn't find a recommendation in the ember cli website (https://ember-cli.com/user-guide/#asset-compilation)

I found one addon that could do this (ember-test-assets), but I'd like to avoid installing extra addons as much as possible.

Thanks!


Solution

  • You can exclude files in ember-cli-build.js with some help of Broccoli

    const EmberApp = require('ember-cli/lib/broccoli/ember-app');
    const Funnel = require('broccoli-funnel');
    
    module.exports = function(defaults) {
      let app = new EmberApp(defaults, {
        // Add options here
      });
    
      // Filter your test files in 'production'
      if (EmberApp.env() === 'production') {
        return new Funnel(app.toTree(), {
          exclude: ['**/test-*'] // e.g. any file prefixxed with 'test-'
        });
      }
      return app.toTree();
    };
    

    References: