Test results do not appear in browser - grunt-karma

5

I'm using grunt and karma to do my project tests. But when I use the grunt test command, the results do not appear in the browser or in the command line.

The only thing that appears is the following:

This is my karma.conf.js file: '// Karma configuration // Generated on Mon Mar 31 2014 10:21:42 GMT-0300 (E. South America Standard Time)

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: './',


    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine','requirejs'],


// list of files / patterns to load in the browser
files: [

  'app/bower_components/jquery/dist/jquery.js',
  'app/bower_components/angular/angular.js',
  'app/bower_components/angular-cookies/angular-cookies.js', 
  'app/bower_components/angular-resource/angular-resource.js', 
  'app/bower_components/angular-sanitize/angular-sanitize.js', 
  'app/bower_components/angular-mocks/angular-mocks.js',      
  'app/scripts/*.js',
  'app/scripts/**/*.js',
  'test/spec/**/*.js'
],

  plugins: [
        'karma-junit-reporter',
        'karma-chrome-launcher',
        'karma-firefox-launcher',
        'karma-jasmine',
        'karma-requirejs'
    ],    


// list of files to exclude
exclude: [

],

// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,

reporters: ['dots'],


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_DEBUG,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,

    browserNoActivityTimeout: 10000,


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Firefox'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false
  });
};

My test file:

describe('Controller: MainCtrl', function () {

  // load the controller's module
  beforeEach(module('AbsenteismoApp'));

  var MainCtrl,
    scope;

  // Initialize the controller and a mock scope
  beforeEach(inject(function ($controller, $rootScope) {
    scope = $rootScope.$new();
    MainCtrl = $controller('MainCtrl', {
      $scope: scope
    });
  }));

  it('deve verificar o tamanho do array expressao scope', function () {
    expect(scope.expressao.length).toBe(1);
  });
});

What will be tested:

 'use strict';

angular.module('AbsenteismoApp')
    .controller('MainCtrl',['$scope',function($scope){

        $scope.expressao = [];
  }]);

At the command prompt this message appears:

  

WARN [Disconnected (1 times), because no   message in 10000 ms.

    
asked by anonymous 01.04.2014 / 16:17

2 answers

2

You are using the Require.js plugin; then it will be necessary to manually initialize the tests .

If you do not use Require.js, I recommend that you remove references from your configuration file as the plugin changes the default behavior of Karma.

In my application, I do the following, using as base a file generated by Karma itself:

require.config({
    // Carrega todos os testes
    deps: testFiles,

    paths: ...,
    shim: ...,

    // Inicializa os testes
    callback: window.__karma__.start
});

And, in the configuration file:

files: [
    "portal/js/require/require.config.js",
    "test/modules/cic/unit-main.js",
    { pattern: "js/**/*.js", included: false },
    { pattern: "test/libs/*.js", included: false },
    { pattern: "test/unit/**/*.spec.js", included: false }
],

Patterns that are with included: false will only served by the Karma HTTP server, but will not have the script tags included on the page. Thus, Require.js takes care of these.

    
15.04.2014 / 01:40
1

For Karma to close the Browser you need to have the SingleRun turned on. In the very description you have in the code:

// Continuous Integration mode  - Modo de integração continuo
// if true, Karma captures browsers, runs the tests and exits  - caso true o Karma abre, corre testes e fecha o browser

So change to:

singleRun: true
    
01.04.2014 / 17:15