Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to activate debugInfoEnabled only for Unit tests?

In my angularjs 1.3 app, i disabled debug info to increase performance :

$compileProvider.debugInfoEnabled(false);

But when i launch my Jasmine tests with Karma, i got error with isolateScope :

var isoScope = element.isolateScope();

I know that it is completely normal,
but i'm looking for a way to reactivate the debug just for testing.
Can i do it programmatically ?
Can i define that in the karma-unit.conf.js ?

like image 899
asicfr Avatar asked Oct 19 '22 18:10

asicfr


1 Answers

My approach to this was to create a set of config files, the load specific files via grunt or gulp, depending on the task or environment variables.

example config:

// configFileLocal.js
angular.module('myapp.config')
.constant('apiUrl', 'https://myapi.com/api')
.constant('debugInfoState', true);

an excerpt from Gruntfile:

copy: {
  test: {
    src: (function () {
      var filename;
      if (process.env.REMOTE_TESTS) {
        filename = './config-files/configFileTestsRemote.js';
      } else {
        filename = './config-files/configFileTestsLocal.js';
      }
      return filename;
    })(),
    dest: '<%= yeoman.app %>/scripts/root/config.js',
  },
  dev: {
    src: './config-files/configFileLocal.js',
    dest: '<%= yeoman.app %>/scripts/root/config.js',
  },
  ...

then of course you need to load it in your app like this:

angular.module('myapp')
.config(function ($compileProvider, debugInfoState) {
  $compileProvider.debugInfoEnabled(debugInfoState);
});

so /app/scripts/root/config.js is overwritten every time. in index.html, the only file that is loaded is /app/scripts/root/config.js this task should be run before any concatenation tasks.

like image 76
wiherek Avatar answered Oct 22 '22 23:10

wiherek