elastic / elasticsearch-js-mock

Mock utility for the Elasticsearch's Node.js client
https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-testing.html
Apache License 2.0
46 stars 10 forks source link

how to use with multiple versions ? #21

Open Cactusbone opened 2 years ago

Cactusbone commented 2 years ago

Following install multiple versions

I have

"dependencies": {
  "es6": "npm:@elastic/elasticsearch@^6.7.0",
  "es7": "npm:@elastic/elasticsearch@^7.0.0"
}

in my package.json

However when adding elasticsearch-mock, it uses require('@elastic/elasticsearch') for { Connection, errors } (without a peer dependency too ...)

How can I use the client I want with mock ?

delvedor commented 2 years ago

Hello! I think the only solution is to write an "hack" with proxyquire.

Cactusbone commented 2 years ago

Thanks for the answer, I've been using http-proxy for mocking only parts of elasticsearch (to simulate errors), with an actual elasticsearch as fallback. It works quite well and does not require mingling with the client lib, just pass the http-proxy url to the client and you're good to go :) (not using elasticsearch-js-mock at all)