ember.jsember-testing

How to get module option from test command in environment config


When running tests using a command such as ember test --module="Acceptance | example", how could I capture the module option within the environment.js config file?

The aim here is to pass a flag indicating the acceptance test module into the application instance when testing. The flag will simply be used in the application to check whether to execute a block of code.

Update 23/09/18:

One idea I've had is that perhaps I can pass a flag into the application instance from the beforeEach hook in acceptance test modules. This would be better because I wouldn't have to include the --module option in the test command, and I'd be able to run all my tests at once. I'm not sure this is possible or how to do this but it's currently my best start.


Solution

  • I've had success implementing my idea. In the acceptance tests, I've got:

    import config from '../../config/environment';
    
    module('Acceptance | example', function(hooks) {
      setupApplicationTest(hooks);
    
      hooks.beforeEach(function() {
        config.APP.testModule = 'Acceptance | example';
      ...
      });
    ...
    

    I can then use this by importing the config, then accessing the flag with:

    config.APP.testModule

    For now at least, I'm going to use this. I will hold off from accepting this answer for a while because it would still be great to hear if anyone has any other ideas or suggestions on how to improve this!