Node.js 使用http.get禁用控制台日志记录
我有以下代码:Node.js 使用http.get禁用控制台日志记录,node.js,testing,bdd,Node.js,Testing,Bdd,我有以下代码: var should = require('should'), http = require('http'), apis = { baseUrl: 'http://11.0.0.20:4000', listLiveMatches: '/api/blah/' }; describe('GET ' + apis.baseUrl + apis.listLiveMatches, function () { 'use strict'; var liveL
var should = require('should'),
http = require('http'),
apis = {
baseUrl: 'http://11.0.0.20:4000',
listLiveMatches: '/api/blah/'
};
describe('GET ' + apis.baseUrl + apis.listLiveMatches, function () {
'use strict';
var liveListUrl = apis.baseUrl + apis.listLiveMatches;
it('is alive & returning 200', function (done) {
http.get(liveListUrl, function (res) {
res.should.be.ok;
res.should.have.property('statusCode');
res.statusCode.should.equal(200);
done();
});
});
it('is emitting json response', function (done) {
http.get(liveListUrl, function (res) {
res.should.be.ok;
res.should.have.property('headers');
res.headers['content-type'].should.startWith('application/json');
done();
});
});
});
我的吞咽任务如下所示:
gulp.task('test-server', function () {
return gulp.src('test/rest-api.js')
.pipe(mocha({
reporter: 'spec'
}))
.on('error', function(){
console.log('error');
});
});
我唯一的问题是,对于每个http.get,控制台都会记录我想要阻止的响应主体,google搜索禁用http.get上的日志记录没有任何结果。当您直接从mocha而不是通过gulp运行测试文件时会发生什么?@R.A.Lucas在我直接通过mocha调用测试文件并显示通过或失败结果时,效果很好。