mardi 5 juillet 2016

In Angularjs - karma run gets error: socket hangup

just initiated karma for unittesting my project.

I'm using jasmine and webpack.

Whenever I run karma start and then karma run Chrome opens, start executing and gets stuck. The terminal shows the following error:

/home/user/site/node_modules/karma/lib/runner.js:69
  throw e
  ^

Error: socket hang up
    at createHangUpError (_http_client.js:252:15)
    at Socket.socketOnEnd (_http_client.js:344:23)
    at emitNone (events.js:91:20)
    at Socket.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:934:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

Noting else is shown.

karma.conf:

// Karma configuration
// Generated on Mon Jul 04 2016 16:17:49 GMT+0300 (IDT)

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: http://ift.tt/1ft83uu
    frameworks: ['jasmine', 'requirejs'],


    // list of files / patterns to load in the browser
    files: [
        { pattern: 'spec.bundle.js', watched: false }
    ],


    // list of files to exclude
    exclude: [],

    plugins: [
        require('karma-requirejs'),
        require('karma-chrome-launcher'),
        require('karma-jasmine'),
        require("karma-sourcemap-loader"),
        require("karma-webpack")
    ],

    // preprocess matching files before serving them to the browser
    // available preprocessors: http://ift.tt/1gyw6MG
    preprocessors: {
        'spec.bundle.js': ['webpack', 'sourcemap']
    },

    webpack: {
        devtool: 'inline-source-map',
        module: {
            loaders: [
                { test: /\.js$/, exclude: /node_modules/, loader: 'ng-annotate!babel?presets[]=es2015'},
                { test: /\.less$/, loader: 'style!css!less?root=.'},
                { test: /\.css$/, loader: 'style!css?root=.'},
                { test: /\.json$/, loader: "json" },
                { test: /\.(ttf|eot|svg|otf)$/, loader: "file" },
                { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url-loader?limit=10000&mimetype=application/font-woff" },
                { test: /\.html$/, exclude: /node_modules/, loader: "raw" }
            ]
        }
    },

    webpackServer: {
        noInfo: true // prevent console spamming when running in Karma!
    },


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: http://ift.tt/1ft83KQ
    reporters: ['progress'],


    // web server port
    port: 9876,


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


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


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


    // start these browsers
    // available browser launchers: http://ift.tt/1ft83KU
    browsers: ['Chrome'],


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

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity
})
}

spec.bundle:

import angular from 'angular';
import mocks from 'angular-mocks';
let context = require.context('./src/app', true, /\.spec\.js/);
context.keys().forEach(context);

and the test I wrote:

describe("first test", () => {
beforeEach(module('app'));

var $compile, $rootScope;

beforeEach(inject(function(_$compile_, _$rootScope_){
    // The injector unwraps the underscores (_) from around the parameter names when matching
    $compile = _$compile_;
    $rootScope = _$rootScope_;
}));

it("adds the text to the content", () => {
    var element =  $compile("<content-body text='hi text'></content-body>");
    $rootScope.$digest();
    expect(element.html()).toContain('hi text');
});

});

Can you help me resolve this error please?

Aucun commentaire:

Enregistrer un commentaire