ctimmerm / axios-mock-adapter

Axios adapter that allows to easily mock requests
MIT License
3.45k stars 244 forks source link

Fix passthrough support with axios 1.2 #363

Closed marcbachmann closed 1 year ago

marcbachmann commented 1 year ago

Fixes https://github.com/ctimmerm/axios-mock-adapter/issues/357

marcbachmann commented 1 year ago

argh. the baseURL somehow changes from one version to another. v1.2 removes the baseURL after normalization, v0.17.0 doesn't

teetotum commented 1 year ago

If I understand it correctly your fix is to call the (unmocked) axios API (with the current request configuration, and without any transformations) when a passthrough is to be performed. (I'm a bit embarressed that I haven't thought about that as a possible fix when I attempted a fix for my own mock library)

Are there any ramifications? By stripping all transformations from the "inner call" you counteract one of those ramifications, right? I.e. that the transformations would run once too often. Does axios do any other things besides transformations before the adapter is called? What with interceptors? Would for example a LoggingInterceptor now log two entries for the request when it should only log once?

I still hope for a positive reaction from the axios maintainers regarding a proposal for making the default adapter available.

marcbachmann commented 1 year ago

Are there any ramifications? By stripping all transformations from the "inner call" you counteract one of those ramifications, right? I.e. that the transformations would run once too often.

You're right, the interceptors are probably called twice. We could clone the instance during instantiation. Then interceptors won't get copied.

I think everything else config-based is only handled by the adapter.

marcbachmann commented 1 year ago

I've extended the tests with a counter for the request and response interceptors. This should be good to merge.

marcbachmann commented 1 year ago

@ctimmerm This pr fixes compatibility with axios 1. would you like to review that?

marco-gagliardi commented 1 year ago

hello @ctimmerm , can this fix be merged? :)

farhan-helmy commented 1 year ago

+1 @marco-gagliardi

marcbachmann commented 1 year ago

@ctimmerm feel free to add me as maintainer here and on npm if you don't have the time to maintain this module.

marcbachmann commented 1 year ago

I got access to github & npm and released that change as v1.21.3. https://github.com/ctimmerm/axios-mock-adapter/releases/tag/v1.21.3 https://www.npmjs.com/package/axios-mock-adapter

marcbachmann commented 1 year ago

Somehow the prepublish script didn't run completely. The axios-mock-adapter.js file isn't there. 🤔 Just the minified version: image

That shouldn't affect normal operation as src/index.js is declared as main in the package.json.

steveatkoan commented 1 year ago

thanks so much! this fix allows me to upgrade axios now. Very appreciated