سؤال

I remember that at some point in the past I could actually debug my tests with Chrome Dev Tools and go into my unminified sources.

I'm not sure if this is a configuration option that was changed but now whenever I try to debug my tests using Chrome I see only the minified sources.

Is there an option I need to set to see the unminified sources?

هل كانت مفيدة؟

المحلول 2

I found a solution to this that does not involve losing coverage data!

Based on this guide for Debugging Karma Unit Tests, I came up with the following, which works in IntelliJ:

var sourcePreprocessors = 'coverage';

var isDebugMode = function () {
    return process.argv.some(function (argument) {
        return argument === '--debug';
    });
};

var hasNoCoverage = function () {
    return !(process.argv.some(function (argument) {
        return argument.includes("coverage");
    }));
};

if (isDebugMode() || hasNoCoverage()) {
    console.log("Not generating coverage.");
    sourcePreprocessors = '';
}

config.set({
    ...
    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
        "WebRoot/js/**/*.js": sourcePreprocessors
    },
    ...
});  

NOTE:

Per info mentioned here, adding the following to your karma.conf.js (or however you are configuring Karma) should disable minification:

coverageReporter: {
  instrumenterOptions: {
    istanbul: { noCompact: true }
  }
}

However, this does not remove the coverage data, and the source files still end up getting mangled up:

__cov_SNsw2QFfQtMZHyIEO9CT1A.s['74']++;
my.toPercentageString = function (value) {
    __cov_SNsw2QFfQtMZHyIEO9CT1A.f['18']++;
    __cov_SNsw2QFfQtMZHyIEO9CT1A.s['75']++;
    return numbro(value).format('0.0%');
};
__cov_SNsw2QFfQtMZHyIEO9CT1A.s['76']++;

نصائح أخرى

Disabling the preprocessors Karma configuration in the Gruntfile.js did it.

var karmaConfig = {
...

  preprocessors: {
    // 'js/**/*.js': 'coverage'
    },
  reporters: ['spec', 'coverage'],
  colors: true,
  singleRun: false,
  usePolling: true,  

...

Disabling preprocessors (like @pgpb.padilla mentioned) unfortunately disables code coverage (istanbul) if that is something you use. I found that only way to disable obfuscation is to run separately without coverage reporter i.e. karma start karma.config.js --reporters progress and then separately for the build include the coverage karma start karma.config.js --reporters progress,coverage

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top