You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Polly replays weird array type from persisted file (replayedData instanceof Array returns false)
Shareable Source
In regular API call:
console.log(response.hits.hitsinstanceofArray)// trueconstslidesCamelized=response.hits.hits.map((el)=>camelize(el._source))asSlide[]constproductsIds=slidesCamelized.filter((el)=>el.productId!==null).map((element)=>element.productId)asnumber[]// some operations so we know that map and filter work in this typeconsole.log(productsIdsinstanceofArray)// trueconsole.log(productsIds.constructor.prototype)// Object(0) []console.log(Array.constructor.prototype)// {}
but when invoked in tests while replaying using Polly:
Why this is an issue?
Because Elastic query builder validates termsQuery method using instanceof Array. This makes all elasticsearch queries (that were built using data from persisted polly records and termsQuery) fail.
Config
I am using @pollyjs/adapter-fetch due to Node 18 on our project. Also, it's worth to mention that node-http adapter doesn't work with native http from core node. I had to write my own Elastic Client library to use Polly with.
Description
Polly replays weird array type from persisted file (replayedData instanceof Array returns false)
Shareable Source
In regular API call:
but when invoked in tests while replaying using Polly:
Error Message & Stack Trace
Why this is an issue?
Because Elastic query builder validates termsQuery method using
instanceof Array
. This makes all elasticsearch queries (that were built using data from persisted polly records and termsQuery) fail.Config
I am using @pollyjs/adapter-fetch due to Node 18 on our project. Also, it's worth to mention that node-http adapter doesn't work with native http from core node. I had to write my own Elastic Client library to use Polly with.
Copy the config used to setup the Polly instance:
Dependencies
Copy the @pollyjs dependencies from
package.json
:Relevant Links
Environment
I am using superTest, jest for testing and express for API
The text was updated successfully, but these errors were encountered: