【问题标题】:Node JS + Grunt-sonar-runner + Code Coverage not showingNode JS + Grunt-sonar-runner + 代码覆盖率未显示
【发布时间】:2016-04-13 19:30:22
【问题描述】:

我在 node js 中创建了一个 REST 服务,并使用 mocha 编写了测试用例。我已经能够使用 istanbul 生成代码覆盖率,并且工作得非常好。现在我的要求是使用 Sonar 显示代码覆盖率。代码合规性违规正在按预期列出。但是声纳中没有生成代码覆盖率。我怀疑 gruntfile.js 配置有问题。目前,我通过将源代码复制到 node_modules 中的 grunt-sonar-runner 文件夹中并执行 grunt-sonar-runner 来生成代码合规性违规。我当前的文件夹结构如下图:

<ProjectRoot>

|--server.js
|--[test]
|--|--serverTest.js

|--[node_modules]
|--|--[grunt-sonar-runner]
|--|--|--[src]
|--|--|--|--server.js

在 gruntfile.js 中,

grunt.initConfig({
    jshint: {
        all: [
            'Gruntfile.js',
            'tasks/*.js',
            'test/*.js'
        ],
        options: {
            jshintrc: '.jshintrc'
        }
    },

    // Before generating any new files, remove any previously-created files.
    clean: {
        tests: ['tmp']
    },

    // Configuration to be run (and then tested).
    sonarRunner: {
        analysis: {
            options: {
                debug: true,
                separator: '\n',
                sonar: {
                    host: {
                        url: 'http://localhost:9000'
                    },
                    jdbc: {
                        url: 'jdbc:h2:tcp://localhost:9092/sonar',
                        username: 'sonar',
                        password: 'sonar'
                    },
                    projectKey: 'sonar:grunt-sonar-runner:0.1.0',
                    projectName: 'Grunt Sonar Runner',
                    projectVersion: '0.10',
                    sources: ['src'].join(','),
                    language: 'js',
                    sourceEncoding: 'UTF-8'
                }
            }
        },
        dryRun: {
            options: {
                dryRun: true,
                debug: true,
                separator: '\n',
                sonar: {
                    host: {
                        url: 'http://localhost:9000'
                    },
                    jdbc: {
                        url: 'jdbc:mysql://localhost:3306/sonar',
                        username: 'sonar',
                        password: 'sonar'
                    },
                    projectKey: 'sonar:grunt-sonar-runner:0.1.0',
                    projectName: 'Grunt Sonar Runner',
                    projectVersion: '0.10',
                    sources: ['src'].join(','),
                    exclusions: '**/R.js'
                }
            }
        }
    },

    // Unit tests.
    mochaTest: {
        test: {
            options: {
                reporter: 'spec'
            },
            src: ['test/**/*.js'],

        }
    }

});

我们有两个部分 --> 分析和dryRun。这是什么dryRun?

除此之外,我们还有一个名为 mochaTest 的键。

在使用 istanbul 运行 mocha 时,我在名为 coverage 的文件夹中的项目根目录中生成了覆盖率报告。不幸的是,它没有在声纳中列出。任何帮助将不胜感激。

提前致谢,

贵族

【问题讨论】:

  • 您不应该提供 options.sonar.javascript.lcov.reportPath 吗? npmjs.com/package/grunt-sonar-runner
  • 是的.. 感谢您的回复。问题得到解决。卸载 grunt-sonar-runner 模块。只需在项目根文件夹中定义一个 sonar-roject.properties。在该属性文件中,我们可以指定由 istanbul 生成的 lcov.info 的相对路径。启动 sonar qube 服务器后,只需运行 sonar-runner(前提是系统路径中存在 sonar runner)。声纳报告将显示在声纳仪表板中。

标签: node.js gruntjs sonarqube mocha.js


【解决方案1】:

只需在项目根文件夹中定义一个 sonar-roject.properties。在该属性文件中,我们可以指定由 istanbul 生成的 lcov.info 的相对路径。启动 sonar qube 服务器后,只需运行 sonar-runner(前提是系统路径中存在 sonar runner)。声纳报告将显示在声纳仪表板中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-24
    • 2016-03-06
    • 2013-11-28
    • 2012-06-30
    • 2012-06-11
    • 2016-09-14
    • 2012-12-22
    • 2014-03-26
    相关资源
    最近更新 更多