2

我们应用程序的后端位于PHP我们正在使用的前端AngularJs。我们成功地使用protractor.

在为我们的应用程序编写了大量的 e2e 测试之后,我们开始寻找类似于单元测试的覆盖范围。在搜索了很多之后,幸运的是我们找到了https://www.npmjs.com/package/grunt-protractor-coverage,正是我们想要的。

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

到此为止,一切都是OK。但是当coverage-report执行生成任务时,我们发现我们有空coverage.json文件{}。这意味着报告在读取该文件以生成报告时肯定是空的,据我所知,该文件是protractor-coverage在执行测试时由 grunt 任务生成的。3001它使用请求将信息发送到收集器(端口POST:),并且在生成报告时,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();
}

每次它只显示在此处输入图像描述 它应该列出每个文件的位置:在此处输入图像描述

而且100到处都是误导,我对源代码进行了测试: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'
  ]);
};

还有我的coverage.json文件:

{}
4

0 回答 0