elasticsearch-js-mock icon indicating copy to clipboard operation
elasticsearch-js-mock copied to clipboard

how to use with multiple versions ?

Open Cactusbone opened this issue 4 years ago • 2 comments

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 ?

Cactusbone avatar Dec 13 '21 14:12 Cactusbone

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

delvedor avatar Jan 12 '22 11:01 delvedor

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)

Cactusbone avatar Jan 17 '22 09:01 Cactusbone