首页 文章

从gulp运行时,摩卡测试失败

提问于
浏览
-1

我已经为我的应用程序的服务级别类开发了一套测试,并且当它们在mocha中运行时都会通过,即:

mocha testfile.js

但是当我从gulp运行它们时,我在其中一个文件中的每个测试都会出现超时错误:

1)预订服务应创建预订:错误:超过2000毫秒的超时 . 确保在此测试中调用done()回调 .

2)预订服务应取消预订:错误:超过2000ms超时 . 确保在此测试中调用done()回调 .

...等等每个测试

我的gulpfile看起来像这样:

var serviceTests = [
  './test/block-service-test.js',
  './test/booking-service-test.js',
  './test/location-service-test.js',
  './test/logging-service-test.js'
];

gulp.task('serviceTests', function(){
  gulp.src(serviceTests)
    .pipe(mocha()) 
    .on('end', function() { console.log('>>Finished Running Tests'); })
    .pipe(exit());
});

我唯一能想到的是失败的测试是通过mongoose连接到数据库 . 以下是设置和其中一个测试的示例:

process.env.MONGOLAB_URI = 'mongodb://localhost:27017/TestDB';
process.env.IN_TEST = true;

var mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
mongoose.connect(process.env.MONGOLAB_URI);

describe("booking service", function() {

    var start = moment(new Date());
    var end = moment(start).add(2, 'h');
    var tutorId = "SomeTutorId";
    var userId = "SomeUserId";

    it("should create booking", function(done){
        return bookingService.createBooking(tutorId, userId,  start, end, "123 Anywhere St", "Test", "User", "Tutor", "LastName")
        .then(function(booking){
            assert.notEqual(booking, null);
            done();
        }).catch(function(err){
            console.log(err);
            assert.fail();
            done();
        });
    });
});

任何想法为什么他们可能从摩卡而不是吞咽?

1 回答

  • 0

    写了一个关闭数据库连接的测试 . 所有猫鼬所做的不是给出“封闭连接”错误,而是超时 .

相关问题