mardi 3 octobre 2017

Angular.js injector error doesn't give any hints about missing dependencies in Karma test

I'm trying to create few simple tests for my Angular.JS app, but unfortunately I can't resolve missing dependencies due to very short output from Angular / Karma (?)

My Karma config looks as follows:

module.exports = function (config) {
config.set({
    basePath: '',
    singleRun: true,
    autoWatch: false,
    frameworks: ['jasmine'],
    browsers: ['PhantomJS'],
    preprocessors: {
        './src/app/myApp.app.js': ['babel']
    },
    files: [
        './node_modules/angular/angular.js',
        './node_modules/angular-mocks/angular-mocks.js',
        './src/app/myApp.app.js',

        './test.js'
    ],
    plugins: [
        'karma-mocha-reporter',
        'karma-jasmine',
        'karma-babel-preprocessor',
        'karma-phantomjs-launcher'
    ],
    babelPreprocessor: {
        options: {
            presets: ['env'],
            sourceMap: 'inline'
        },
        sourceFileName: function (file) {
            return file.originalPath;
        }
    },
    reporters: ['mocha']
});
}

What I'm doing here is basically including angular, angular-mocks, entry module for my app and one file with tests. Of course some dependencies are missing now, but I'd like to add only required ones (and learn about missing deps after karma start).

Unfortunaltely, after running karma start I can only see that test has failed, and that's all - nothing more (for example, at runtime you can see 'rich' error message in browser's console, based on which you can include missing deps). Take a look at this error:

  x it should do something funny
    PhantomJS 2.1.1 (Mac OS X 0.0.0)
  node_modules/angular/angular.js:4693:53
  forEach@node_modules/angular/angular.js:325:24
  loadModules@node_modules/angular/angular.js:4653:12
  createInjector@node_modules/angular/angular.js:4575:30
  WorkFn@node_modules/angular-mocks/angular-mocks.js:3120:60

And that's all. If I include minified version of Angular, I see browser-like error message, based on which I can add required deps. With non-minified version it's working like I've described. So my question is - how can I make error messages rich in karma tests?

Aucun commentaire:

Enregistrer un commentaire