Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
doberkofler opened this issue Feb 11, 2018 · 3 comments · Fixed by karronoli/redpen#10 · May be fixed by Omrisnyk/npm-lockfiles#122 or Omrisnyk/npm-lockfiles#132

Comments

@doberkofler
Copy link
Contributor

doberkofler commented Feb 11, 2018

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
@andsouto
Copy link

I'm having exactly the same problem after upgrading to karma 2.0 and #2931 fixed the problem for me. What prevents it to be merged?

@lusarz
Copy link
Contributor

lusarz commented Feb 22, 2018

I confirm this issue. Here I prepared minimal reproduction. To reproduce:

npm install
npm run test

then

npm install karma@1.7
npm run test

@Cobertos
Copy link

Cobertos commented Feb 22, 2018

Can confirm that reverting to karma@1.7.1 works on my project and that karma@2.0.0 is the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants