我想了解快捷键端点上功能测试的覆盖范围。我做了这个简单的设置。
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);
});节点测试/测试/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();
});
});
});节点/生成文件
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。有可能得到我想要的保险吗?
发布于 2014-05-09 13:25:49
我发现,为了工作,我必须从测试开始快速服务器。我还需要在测试的基础上添加一行。
var lib = process.env['COV']?'../lib-cov' : '../lib';
//run express
var app = require(lib)因此,当您运行覆盖率测试时,您将包括已检测的文件。
https://stackoverflow.com/questions/23542922
复制相似问题