How to run multiple Karma goals in Grunt?

We use Grunt to create several but similar applications in one assembly. This is a rather complex and large project with a folder for each application and a folder named share with a lot of common components.

several karma targets
Angular introduces dependency by name (String) and our apps have files with the same names as HomeController, MenuController. This forces us to separate the karma targets per application, so dependencies are only loaded from the general and specific application under test.

Fatal error
When using grunt to run karma targets, it only runs the first successful one and cannot run the second. Fatal error: listen EADDRINUSE

The error has something to do with the port being used.

Karma configuration (simplified)

module.exports = function(config) {
  'use strict';  

    config.set({
    autoWatch: false,
    basePath: '../',
    frameworks: ['jasmine'], 
    exclude: [],
    browsers: ['PhantomJS'],   
    plugins: [
      'karma-html-reporter',
      'karma-junit-reporter',
      'karma-coverage',
      'karma-phantomjs-launcher',
      'karma-jasmine',
      'karma-brackets'
    ],
    singleRun: false,
    colors: true,
    logLevel: config.LOG_DEBUG
  });
};

      

Grunt-karma configuration

var dep = [
  'bower_components/**/*.js',
  'app/shared/**/*.js',
];

module.exports = {
  options: {
    configFile: 'test/karma.conf.js',
    reporters: ['brackets', 'html', 'junit', 'coverage'],
    browsers: ['PhantomJS'],
    port: 9002,
    singleRun: true
  },
  A: {
    options: {
      files: dep.concat([       
        'app/A/src/**/*.js'
      ]),      
    }
  },
  B: {
    options: {
      files: dep.concat([
        'app/B/src/**/*.js'
      ]),      
    }
  }
};

      

How can I run both karma targets (A and B) in the same grunt task? I guess I have to either reset the karma server (phantomJs?) Or run them as separate "sets" on the same target, but I can't seem to figure out how.

Hope someone out there can help! Thank!

Update1
This issue on github seems to address the same issue but still hasn't made it to release.

+3


source to share


2 answers


workaround that works
Remove the tasks karma

from the distribution task. Instead of trying to run multiple karma targets in a single grunt task, you can execute multiple grunt commands separately from the command line (mostly on a continuous integration server. Development rarely requires all targets to be met)

The command can be: (optional xxxxxx is any task you want to run after testing is complete)



grunt testA && grunt testB && grunt xxxxxx

      

0


source


Perhaps you can just move your parameter port

to the targets and choose a different port for each one?



 A: {
    options: {
      port: 9011,
      files: dep.concat([       
        'app/A/src/**/*.js'
      ]),      
    }
  },
  B: {
    options: {
      port: 9012,
      files: dep.concat([
        'app/B/src/**/*.js'
      ]),      
    }
  }

      

0


source







All Articles