i18next / i18next-http-backend

i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.
MIT License
452 stars 70 forks source link

have fetch pluggable #132

Closed jacobbogers closed 9 months ago

jacobbogers commented 9 months ago

Hi, Can you expose the "fetch" as pluggable, this would help greatly at testing especially as we dont use jest mocks (we use it.concurrent extensively will be an issue since jest mocks are global to test file)

hence the need to make it pluggable per it test

Example (just spitballing):

config: { 
    getFetch: () => globalThis.fetch
}

for mocking (integration tests)

config: { 
    getFetch: () => fetchMocked
}
adrai commented 9 months ago

If you know of a way that works without breaking all current environments (client, server, Node.js, Deno, etc.) feel free to open a PR

jacobbogers commented 9 months ago

Thanks for your understanding, let me see if I can cook something up.

adrai commented 9 months ago

btw: I would prefer to not add additional complexity, since you can also pass your custom request function here: https://github.com/i18next/i18next-http-backend?tab=readme-ov-file#backend-options

image
jacobbogers commented 9 months ago

I made a PR

https://github.com/i18next/i18next-http-backend/pull/133

jacobbogers commented 9 months ago

To answer your question about request

Sure we can use request , but our test regiment is to simulate at lowest level possible, (the actual network traffic and especially simulating errors, checking headers, or sending back incomplete data, delays, etc, etc) and see if our apps in an integration test setting can deal with this situation prorperly.

btw: I would prefer to not add additional complexity, since you can also pass your custom request function here: https://github.com/i18next/i18next-http-backend?tab=readme-ov-file#backend-options

image