量角器覆盖范围不生成报告

2023-12-21

我们应用程序的后端位于PHP对于前端我们正在使用AngularJs。 我们成功地在本地和生产服务器上运行了 e2e 测试,使用protractor.

在为我们的应用程序编写大量 e2e 测试后,我们开始寻找与单元测试类似的覆盖范围。经过一番寻找,幸运的是我们发现https://www.npmjs.com/package/grunt-protractor-coverage https://www.npmjs.com/package/grunt-protractor-coverage,正是我们想要的。

我得到了帮助http://lkrnac.net/blog/2014/04/measuring-code-coverage-by-protractor/ http://lkrnac.net/blog/2014/04/measuring-code-coverage-by-protractor/文章非常有助于设置一切。我为我的应用程序设置了配置和其他繁重任务,最后我们的代码(js 文件)得到了正确的检测。我将其余文件(html、静态等)复制到该检测代码中,并提供了正确的路径proractor-config文件。测试开始像之前一样运行,但这次使用的是已检测的文件。

至此,一切都已OK。但是当生成任务coverage-report被处决了,我们认为我们已经空了coverage.json file {}。这意味着报告在读取该文件来生成报告时肯定是空的,据我所知,该文件是由protractor-coverage测试执行时执行 grunt 任务。它将信息发送到收集器(端口:3001) 用一个POSTreq 并在生成报告时,GET正在向同一个收集器发出请求。

所以,我想的是,不POST正在向收集器发出请求。

var options = {
  hostname: 'localhost',
  port: <%=collectorPort%>,
  path: '/data',
  method: 'POST',
  headers:{
    'Content-Type':'application/json'
  }
};
function saveCoverage(data){
  var req = http.request(options, function(res) {
      res.on('data', function (chunk) {
      });
  });
  req.on('error', function(e) {
    console.log('problem with request: ' + e.message);
  });

  // write data to request body
  req.write(JSON.stringify(data));
  req.write('\n');
  req.end();
}

Each time it just shows enter image description here where it should have listed down every file: enter image description here

And also, that 100到处都是误导,我对源代码进行了测试:http://lkrnac.net/blog/2014/04/measuring-code-coverage-by-protractor/ http://lkrnac.net/blog/2014/04/measuring-code-coverage-by-protractor/正如所解释的,但即使只有一个 e2e 测试,报告也必须给出实际数字,而不是直接给出100对全部。

我可能有一些错误的配置或遗漏了一些东西。

以下是我的文件:

'use strict';

module.exports = function(grunt) {

  // Load grunt tasks automatically
  require('load-grunt-tasks')(grunt);

  // Define the configuration for all the tasks
  grunt.initConfig({

    // Project settings
    yeoman: {
      // configurable paths
      app: 'app',
      dist: 'dist-test',
      e2e: 'coverage/e2e',
      instrumentedServer: 'coverage/server/instrument',
      instrumentedE2E: 'coverage/e2e/instrumented'
    },
    // Empties folders to start fresh
    clean: {
      coverageE2E: {
        src: ['<%= yeoman.e2e %>/'],
      }
    },

    // Copies remaining files to places other tasks can use
    copy: {
      coverageE2E: {
        files: [{
          expand: true,
          dot: true,
          cwd: '<%= yeoman.app %>',
          dest: '<%= yeoman.e2e %>/instrumented/app',
          src: [
            '**/*',
            '!modules/**/*.js',
            '!editor/**/*.js'
          ]
        }, {
          expand: true,
          cwd: '.tmp/images',
          dest: '<%= yeoman.e2e %>/instrumented/app/images',
          src: ['generated/*']
        }, ]
      },
    },

    // start - code coverage settings
    instrument: {
      files: ['app/modules/**/*.js', 'app/editor/**/*.js'],
      options: {
        lazy: true,
        basePath: 'coverage/e2e/instrumented/'
      }
    },

    makeReport: {
      src: '<%= yeoman.instrumentedE2E %>/*.json',
      options: {
        type: 'html',
        dir: '<%= yeoman.e2e %>/reports',
        print: 'detail',
        //        type: 'lcov'
        //        dir: 'reports'
      }
    },


    protractor_coverage: {
      options: {
        configFile: 'test/e2e/protractor-config.js', // Default config file
        keepAlive: true, // If false, the grunt process stops when the test fails.
        noColor: false, // If true, protractor will not use colors in its output.
        coverageDir: '<%= yeoman.instrumentedE2E %>',
        args: {},
        run: {}
      },
      chrome: {
        options: {
          args: {
            baseUrl: 'https://localapp.vwo.com/v3/#/',
            // Arguments passed to the command
            'browser': 'chrome'
          }
        }
      }
    }
  });

  grunt.registerTask('default', [
    'clean:coverageE2E',
    'copy:coverageE2E',
    'instrument',
    'protractor_coverage:chrome',
    'makeReport'
  ]);
};

And my coverage.json file:

{}

None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

量角器覆盖范围不生成报告 的相关文章

随机推荐