Sails.js 测试中的超时问题

Timeout issue in Sails.js testing

这是我的 lifecycle.test.js 文件:

var sails = require('sails');

// Before running any tests...
before(function(done) {

  // Increase the Mocha timeout so that Sails has enough time to lift, even if you have a bunch of assets.
  this.timeout(5000);

  sails.lift({
    // Your Sails app's configuration files will be loaded automatically,
    // but you can also specify any other special overrides here for testing purposes.

    // For example, we might want to skip the Grunt hook,
    // and disable all logs except errors and warnings:
    hooks: { grunt: false },
    log: { level: 'warn' },

  }, function(err) {
    if (err) { return done(err); }

    // here you can load fixtures, etc.
    // (for example, you might want to create some records in the database)

    return done();
  });
});

// After all tests have finished...
after(function(done) {

  // here you can clear fixtures, etc.
  // (e.g. you might want to destroy the records you created above)

  sails.lower(done);

});

这是 FooController.test.js 文件:

var supertest = require('supertest');
var sails = require('sails');

describe('FooController.foo', function() {

  describe('#foo()', function() {
    it('should respond 200', function (done) {
      supertest(sails.hooks.http.app)
      .get('/foo')
      .expect(200)
    });
  });

});

这是当 npm 运行 test 为 运行:

时 运行s 的命令
"test": "node ./node_modules/mocha/bin/mocha --timeout=10000 test/lifecycle.test.js test/integration/**/*.test.js",

但我收到此错误:错误:超时超过 10000 毫秒。对于异步测试和挂钩,确保 "done()"...

完成()很重要

  describe('#foo()', function() {
    it('should respond 200', function (done) {
      supertest(sails.hooks.http.app)
      .get('/foo')
      .expect(200, done)
    });
  });