Node.js 在每篇文章之前清除索引(摩卡咖啡,弹性)
我们如何在每次测试前清除索引?(在测试失败的那一刻,超时) 我试过了Node.js 在每篇文章之前清除索引(摩卡咖啡,弹性),node.js,asynchronous,elasticsearch,mocha.js,Node.js,Asynchronous,elasticsearch,Mocha.js,我们如何在每次测试前清除索引?(在测试失败的那一刻,超时) 我试过了 DeleteBy(我已经尝试了术语和q) http删除 删除索引 我有以下代码: var assert = require("assert"), elasticsearch = require('elasticsearch'), request = require('request'), q = require('q'), client; client = new elasticsearc
- DeleteBy(我已经尝试了术语和q)
- http删除
- 删除索引
var assert = require("assert"),
elasticsearch = require('elasticsearch'),
request = require('request'),
q = require('q'),
client;
client = new elasticsearch.Client();
describe('people', function(){
beforeEach(function(done){
//is this correct?
//looks like poeple get deleted.
client.deleteByQuery({
index: 'people',
q: '*'
}, function (error, response) {
done();
});
//I have also tried the following:
//this way returns an accept code.
// var deleteOptions = {
// method: 'DELETE',
// uri: 'http://localhost:9200/people/person'
// };
//
// webApi(deleteOptions).then(function(data){
// //{"acknowledged":true}
// console.log(data.body);
// done();
// });
//the following throws an exception
//delete index
// client.indices.delete('people').then(function(del){
// console.log(del);
// client.indices.create('people').then(function(ct){
// console.log(ct);
// done();
// });
// });
});
describe('add a entry into the index', function(){
it('should add Dave as a person to the database', function(done){
//THIS TEST WILL FAIL
//Error: timeout of 2000ms exceeded
//I have tried adding a timeout.
assert.equal(1,1);
});
});
});
var webApi = function(options){
var deferred = q.defer();
var handle = function (error, response, body) {
//console.log(body);
if(error) {
deferred.reject(error);
}
else {
deferred.resolve({response:response, body:body});
}
};
request(options, handle);
return deferred.promise; //NOTE: we now return a promise
};
用
标记的测试此测试将失败
并超时,因为您从未在其中调用done()
。您已经用一个参数声明了传递给it
的匿名函数,它告诉Mocha您的测试是异步的(即使其中的代码现在不是异步的),因此Mocha等待调用done()
。您可以调用它,也可以从函数中删除该参数