【问题标题】:grunt-karma debug unminified sourcesgrunt-karma 调试未压缩的源
【发布时间】:2014-05-09 08:35:48
【问题描述】:

我记得在过去的某个时候,我实际上可以使用 Chrome 开发工具调试我的测试并进入我未缩小的源代码。

我不确定这是否是一个已更改的配置选项,但现在每当我尝试使用 Chrome 调试我的测试时,我只能看到缩小的源代码。

我需要设置一个选项来查看未缩小的来源吗?

【问题讨论】:

    标签: debugging gruntjs karma-runner


    【解决方案1】:

    Gruntfile.js 中禁用preprocessors Karma 配置即可。

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

    【讨论】:

    • 是什么导致了缩小?是伊斯坦布尔吗?为什么删除预处理器会消除缩小?
    • 老实说我不知道​​。发生的事情是,我浏览了我的提交历史,发现添加了预处理器,所以我在没有它们的情况下进行了测试,结果证明它做到了。我想你可以通过 Karma 的 repo 并尝试弄清楚,但我不知道你是否想这样做。
    • 谢谢!这让我发疯,无法弄清楚为什么 IntelliJ 没有在源文件中的断点处停止,而是在测试中的断点处停止。这解决了它!
    【解决方案2】:

    我找到了一个不涉及丢失覆盖数据的解决方案!

    根据Debugging Karma Unit Tests 的本指南,我想出了以下内容,适用于 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
        },
        ...
    });  
    

    注意:

    根据here 提到的信息,将以下内容添加到您的karma.conf.js(或者您正在配置 Karma)应该禁用缩小:

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

    但是,这不会删除覆盖数据,并且源文件最终仍然会被破坏:

    __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']++;
    

    【讨论】:

    • 业力指南链接已损坏,现在要求购买域名
    【解决方案3】:

    如果您使用的是禁用preprocessors(就像提到的@pgpb.padilla),不幸的是会禁用代码覆盖(伊斯坦布尔)。我发现禁用混淆的唯一方法是在没有coverage 记者的情况下单独运行,即karma start karma.config.js --reporters progress,然后单独为构建包括覆盖karma start karma.config.js --reporters progress,coverage

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 2019-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多