Javascript @elastic/elasticsearch mock无法对';未定义';或';空';
我试图使用libJavascript @elastic/elasticsearch mock无法对';未定义';或';空';,javascript,node.js,unit-testing,
elasticsearch,lambda,Javascript,Node.js,Unit Testing,
elasticsearch,Lambda,我试图使用lib@elastic/elasticsearch mock模拟@elasticsearch/elasticsearch 我已经按照文档使用了代码,并尝试运行,但是得到了这个结果 代码 但是得到这个错误 /home/app/node_modules/@elastic/elasticsearch-mock/index.js:18 ConfigurationError, ^ TypeError: Cannot destructure property `Configuration
@elastic/elasticsearch mock
模拟@elasticsearch/elasticsearch
我已经按照文档使用了代码,并尝试运行,但是得到了这个结果
代码
但是得到这个错误
/home/app/node_modules/@elastic/elasticsearch-mock/index.js:18
ConfigurationError,
^
TypeError: Cannot destructure property `ConfigurationError` of 'undefined' or 'null'.
at Object.<anonymous> (/home/app/node_modules/@elastic/elasticsearch-mock/index.js:17:7)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Module._load (internal/modules/cjs/loader.js:724:14)
at Function.hookedLoader [as _load] (/home/app/node_modules/mockery/mockery.js:111:12)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/app/test/lib/es-helper-test.js:12:14)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Module._load (internal/modules/cjs/loader.js:724:14)
at Function.hookedLoader [as _load] (/home/app/node_modules/mockery/mockery.js:111:12)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at /home/app/node_modules/mocha/lib/mocha.js:220:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/home/app/node_modules/mocha/lib/mocha.js:217:14)
at Mocha.run (/home/app/node_modules/mocha/lib/mocha.js:485:10)
at Object.<anonymous> (/home/app/node_modules/mocha/bin/_mocha:403:18)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
at internal/main/run_main_module.js:17:11
您可能需要添加一个解析器,甚至只是为了控制台记录客户端
从非常有限的角度来看
据我所知,您需要在客户机上添加您想要模拟的每个索引、查询、解析器等,因为没有可查询的数据库-这意味着您提供了数据并告诉模拟如何返回数据(同时仍在学习这一点,模拟库的文档非常简短)我已经按照文档进行了测试,但它仍然不适合我。弹性搜索(java程序)本身也需要安装在本地系统上,才能正常运行(如果尚未安装)。我也不知道你说的“测试”是什么意思;您是否尝试了添加的冲突解决程序?是,使用冲突解决程序进行了测试。
/home/app/node_modules/@elastic/elasticsearch-mock/index.js:18
ConfigurationError,
^
TypeError: Cannot destructure property `ConfigurationError` of 'undefined' or 'null'.
at Object.<anonymous> (/home/app/node_modules/@elastic/elasticsearch-mock/index.js:17:7)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Module._load (internal/modules/cjs/loader.js:724:14)
at Function.hookedLoader [as _load] (/home/app/node_modules/mockery/mockery.js:111:12)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/app/test/lib/es-helper-test.js:12:14)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Module._load (internal/modules/cjs/loader.js:724:14)
at Function.hookedLoader [as _load] (/home/app/node_modules/mockery/mockery.js:111:12)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at /home/app/node_modules/mocha/lib/mocha.js:220:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/home/app/node_modules/mocha/lib/mocha.js:217:14)
at Mocha.run (/home/app/node_modules/mocha/lib/mocha.js:485:10)
at Object.<anonymous> (/home/app/node_modules/mocha/bin/_mocha:403:18)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
at internal/main/run_main_module.js:17:11
"@elastic/elasticsearch": "7.13.0"
"@elastic/elasticsearch-mock": "^0.3.0"
const { Client } = require('@elastic/elasticsearch')
const Mock = require('@elastic/elasticsearch-mock')
const mock = new Mock()
const client = new Client({
node: 'http://localhost:9200',
Connection: mock.getConnection()
})
// Add this resolver
mock.add({
method: 'GET',
path: '/'
}, () => {
return { status: 'ok' }
})
client.info(console.log)