javascript - Sails.js 测试中的超时问题
问题描述
这是我的生命周期.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 run test 时运行的命令:
"test": "node ./node_modules/mocha/bin/mocha --timeout=10000 test/lifecycle.test.js test/integration/**/*.test.js",
但我收到此错误:错误:超过 10000 毫秒的超时。对于异步测试和钩子,确保“done()”...
解决方案
done() 很重要
describe('#foo()', function() {
it('should respond 200', function (done) {
supertest(sails.hooks.http.app)
.get('/foo')
.expect(200, done)
});
});
推荐阅读
- typescript - 在 TypeScript 中创建 HTMLHeadingElement
- reactjs - 节点异步映射在 redux 操作中无法正确执行
- php - 外部文件的新模板 - VueJS
- python-3.x - Python中的排名/计数
- mysql - MySQL INSERT INTO 语句出现问题,DATETIME 值不会转移到新表
- c++ - 为什么尝试在 C++ 中分配二维数组会导致内存损坏错误?
- excel - Excel:SUMIF 的 SUM 与 VLOOKUP 的 SUM 与数组函数?
- c# - 错误 CS1061 不包含定义 - Roslyn 编译问题
- datatables - I18n 翻译未在 Datatable 初始化中呈现?
- java - 在哪里放置 -Xms java 选项