Node.js 摩卡咖啡测试运行两次

Node.js 摩卡咖啡测试运行两次,node.js,mocha.js,Node.js,Mocha.js,我正试图弄明白为什么这个测试会运行两次: it ( "should verify file exists with a one name filename ", function ( done ){ var fileNameOneChar = "/Users/myusername/t.mp3"; console.log(" the file path ", fileNameOneChar ); expect( myApi.fileExists( fileName

我正试图弄明白为什么这个测试会运行两次:

it ( "should verify file exists with a one name filename ", function ( done ){   
    var fileNameOneChar = "/Users/myusername/t.mp3"; 
    console.log(" the file path ", fileNameOneChar ); 
    expect( myApi.fileExists( fileNameOneChar ) ).to.be( true ); 
    done();
});
测试连续运行两次(尽管它只定义了一次),第一次通过(这没问题,该文件实际上存在,api工作正常),第二次失败并出现错误:“错误:超时超过5000ms”


为什么测试要运行两次?我已经找遍了所有关于超时错误的地方有一段时间了,没有在摩卡咖啡上找到任何东西

几分钟前我也遇到了同样的情况,我找到了一个解决方法(不是修复方法):在同步模式下运行测试

基本上,您需要避免设置it方法的done参数

下面是我现在的测试的示例

describe('API /users Endpoint', function () {
  it('GET /users should return a JSON list of users', function (done) {
    request
      .get(config.api.prefix+'users')
      .set('bearer',config.api.key)
      .end(function(err,res){
        if (err) {
          return done(err);
        }
        res.statusCode.should.equal(200);
        res.body.should.not.be(null);
        res.body.posts.should.not.be(undefined);
        res.body.posts.should.not.have.length(0);
      });
  });

希望有帮助

是否
myApi.fileExists
async?