vectara / stream-query-client

A TypeScript utility for easily making requests/parsing responses to/from Vectara's streaming query API
Apache License 2.0
3 stars 0 forks source link

Add support for debug option, change details structure, bump to 2.0.0 #11

Closed cjcenizal closed 4 months ago

cjcenizal commented 4 months ago

Changes:

Notes on testing

I originally tried jest-fetch-mock but ran into some challenges with mocking the streamed response.

I then switched to Mock Service Worker which has guidance on how to mock a streaming API. I took a misstep by trying to use msw/browser but then came across https://stackoverflow.com/questions/77399773/cannot-find-module-msw-node-from which pointed me to use msw/node because Jest operates in a Node environment.

The only major problem I ran into with MSW was that the docs advise using their HttpResponse mocking tool, and this resulted in the tests erroring out with this enigmatic message at the point in which HttpResponse was being instantiated:

TypeError: Cannot read properties of undefined (reading '200')

The docs state that we can replace HttpResponse with the built-in Response object, so I did that and the tests proceeded without a hitch.

This general journey mirrored Kent Dodds's journey in Stop mocking fetch.