【问题标题】:Functional test coverage report with node-jscoverage , mocha and express带有 node-jscoverage 、 mocha 和 express 的功能测试覆盖率报告
【发布时间】:2014-05-08 13:18:27
【问题描述】:

我想在快速端点上获得功能测试的覆盖率。 我做了这个简单的设置。

nodetest/index.js

module.exports = process.env.APP_COV
  ? require('./lib-cov')
  : require('./lib');

nodetest/lib/index.js

var express = require('express');
var app = express();
app.get('/hello.txt', function(req, res){
  res.send('Hello World');
});
var server = app.listen(3000, function() {
    console.log('Listening on port %d', server.address().port);
});

nodetest/test/simple.js

var request = require('supertest');

describe("Node Test Service",function(){
    it('Should return 200 OK trying to login', function (done) {
        request("http://localhost:3000")
            .get('/hello.txt')
            .expect(200)
            .end(function (err, res) {
            if(err)
                throw err;
            done();
            });
    });
});

节点测试/Makefile

all: test test-cov
test:
    @./node_modules/.bin/mocha -R xunit > reporter.xml

test-cov: lib-cov
    @APP_COV=1  ./node_modules/.bin/mocha -R html-cov > coverage.html

lib-cov:
    @./node-jscoverage/jscoverage lib lib-cov

node-jscoverage:
    @git clone git://github.com/visionmedia/node-jscoverage.git
    @cd node-jscoverage/ && ./configure && make


.PHONY: test

我正在运行带有 env 变量的服务器,然后启动测试 它产生一个空的coverage.html。 是否有可能获得我要求的保险范围?

【问题讨论】:

    标签: javascript node.js express code-coverage mocha.js


    【解决方案1】:

    我发现为了工作,我必须从测试开始就启动 express 服务器。 我还需要在测试顶部添加一行

    var lib = process.env['COV']?'../lib-cov' : '../lib';
    //run express
    var app = require(lib)
    

    这样当您运行覆盖测试时,您就可以包含已检测的文件。

    【讨论】:

      猜你喜欢
      • 2015-08-19
      • 1970-01-01
      • 1970-01-01
      • 2021-07-23
      • 2012-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-23
      相关资源
      最近更新 更多