Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用http.get禁用控制台日志记录_Node.js_Testing_Bdd - Fatal编程技术网

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调用测试文件并显示通过或失败结果时,效果很好。