Karma: How to prevent preprocessor error from crashing karma server

Created on 12 Oct 2019  路  2Comments  路  Source: karma-runner/karma

I upgraded from karma v2 to karma v4 and am having an issue where the karma server crashes if there is an error in the babel preprocessor. With version 2, the error would be logged in the console, but the server would continue to run. Is there a way to handle errors / unhandledRejections so that the server does not crash? Thanks!

Actual behaviour

ERROR [preprocessor.babel]:
ERROR [karma-server]: UnhandledRejection
DEBUG [launcher]: Disconnecting all browsers
DEBUG [launcher]: CAPTURED -> BEING_KILLED
DEBUG [launcher]: BEING_KILLED -> BEING_FORCE_KILLED
DEBUG [launcher]: Process Chrome exited with code 0 and signal null
DEBUG [temp-dir]: Cleaning temp dir DEBUG [launcher]: Finished all browsers
DEBUG [launcher]: BEING_FORCE_KILLED -> FINISHED
DEBUG [launcher]: FINISHED -> FINISHED

Environment Details

  • Karma version (4.3.0):
  • Relevant part of your karma.config.js file (couldn't get formatting to work)
    module.exports = function(config) {
    config.set({
    frameworks: ['jasmine-jquery', 'jasmine', 'fixture'],
    plugins : ["karma-"],
    preprocessors: {
    'test/jasmine/spec/Rio//
    .js': ['babel'],
    'src/webapp/Rio/js/.js': [ 'babel' ],
    'src/webapp/Rio/js/!(vendor|component)/
    /.js': [ 'babel' ]
    },
    babelPreprocessor: {
    options: {
    sourceMap: 'inline',
    presets: ['@babel/preset-env'],
    plugins: config.server ? [
    '@babel/plugin-proposal-optional-chaining',
    '@babel/plugin-proposal-nullish-coalescing-operator'
    ] : [
    ["istanbul", {
    "exclude": [
    'test/jasmine/spec/*/.js'
    ]
    }],
    '@babel/plugin-proposal-optional-chaining',
    '@babel/plugin-proposal-nullish-coalescing-operator'
    ],
    overrides: [{
    sourceType: "script",
    }],
    }
    },
    coverageIstanbulReporter : {
    reports: ['html', 'cobertura', 'text-summary'],
    dir: 'target/coverage/rio/',
    thresholds: {
    global: {
    lines : 99.17,
    statements : 99.14,
    branches: 94.17,
    functions: 98
    }
    },
    },
    specReporter: {
    suppressErrorSummary: false,
    suppressFailed: false,
    suppressPassed: false,
    suppressSkipped: process.env.NODE_ENV === 'debug',
    showSpecTiming: false,
    failFast: false
    },
    files: [
    { .....}',
    ],
    client: {
    jasmine: {
    random: false,
    hideDisabled: true
    }
    },
    reporters: ['progress', 'coverage-istanbul', 'spec', 'summary', 'kjhtml'],
    port: 9876, // karma web server port
    colors: true,
    logLevel: config.LOG_DEBUG,
    browsers: ['PhantomJS'],
    customLaunchers: {
    OmniChrome: {
    base: 'Chrome',
    flags: [
    '--start-maximized',
    '--allow-file-access-from-files',
    '--disable-translate',
    '--disable-extensions',
    '--remote-debugging-port=9223',
    '--auto-open-devtools-for-tabs',
    'http://localhost:9876/debug.html'
    ]
    }
    },
    autoWatch: true,
    singleRun: false,
    concurrency: Infinity
    })
    };

Steps to reproduce the behaviour

  1. start karma server
  2. type invalid JS syntax in a watched file
  3. save the file and refresh the karma controlled browser

Most helpful comment

In your config you can register a handler for infrastructure_error

process.on('infrastructure_error', (error) => {
  console.error('infrastructure_error', error);
});

That will point you to the error. But exiting in this case is by design. Unhandled rejections are exceptions, continuing does not make sense.

All 2 comments

In your config you can register a handler for infrastructure_error

process.on('infrastructure_error', (error) => {
  console.error('infrastructure_error', error);
});

That will point you to the error. But exiting in this case is by design. Unhandled rejections are exceptions, continuing does not make sense.

Thanks @johnjbarton.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IgorMinar picture IgorMinar  路  5Comments

VinishaDsouza picture VinishaDsouza  路  3Comments

anius picture anius  路  3Comments

donaldpipowitch picture donaldpipowitch  路  3Comments

mboughaba picture mboughaba  路  3Comments