Skip to content

Karma 2 no longer correctly reports the original error stack when using source maps #2930

@doberkofler

Description

@doberkofler

Expected behavior

When reporting an error and source maps are available the error stack should point to the original source line and column. The mocha-reporter shows this by using a format like in the following example:
(webpack:///test/unittest/frontend/ods/convert--test.js:43:9 <- temp/karma_unittests/convert--test.js:712:10)

at Context.<anonymous> (webpack:///test/unittest/frontend/ods/convert--test.js:43:9 <- temp/karma_unittests/convert--test.js:712:10)

Actual behavior

Up to Karma 1.7 this worked as expected but starting with Karma 2.0 the commit made a change in the definition of URL_REGEXP that causes the reporter to no longer recognize the lines in the error stack.
In the file lib/reporter.js when building URL_REGEXP the urlRoot + '\\/?' is now added before the (base/|absolute) and because urlRoot is always automatically post fixed with / the resulting regular expression now expects the url always to start with /base causing the matching to fail and to no longer correctly report the original file, line and column of the error stack.

at Context.<anonymous> (base/temp/karma_unittests/convert--test.js?6c85b6986d1a9cc153d2877ce8637a38a6b666ad:712:10)

Environment Details

  • Karma version (output of karma --version): 2.0.0
  • Relevant part of your karma.config.js file
// Karma configuration

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: ['mocha', 'chai'],

    // list of files / patterns to load in the browser
    files: [
      'dist/**/*.js'
    ],

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

    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
		'dist/**/*.js': ['sourcemap']
    },

    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['mocha'],

    // reporter options
    mochaReporter: {
      showDiff: true
  	},

    // 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_DEBUG,

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

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

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

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: 1,

	client: {
		// Capture all console output and pipe it to the terminal.
		captureConsole: true,
		mocha: {
			timeout: 60000
		}
	},

  });
}

Steps to reproduce the behavior

  1. Build a mocha unit test with a failing test and bundle it using webpack
  2. Run the unit test using karma
  3. Compare the results of the error stack between Karma 1.7 and 2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions