Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix passthrough support with axios 1.2 #363

Merged

Conversation

marcbachmann
Copy link
Collaborator

Fixes #357

@marcbachmann marcbachmann force-pushed the fix-axios-v1-passthrough-support branch from 2b40430 to 04b3de6 Compare February 12, 2023 20:26
@marcbachmann
Copy link
Collaborator Author

marcbachmann commented Feb 12, 2023

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

@teetotum
Copy link

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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

@marcbachmann
Copy link
Collaborator Author

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

@marco-gagliardi
Copy link

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

@farhan-helmy
Copy link

+1 @marco-gagliardi

@marcbachmann
Copy link
Collaborator Author

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

@marcbachmann marcbachmann merged commit 39597cb into ctimmerm:master Mar 26, 2023
@marcbachmann
Copy link
Collaborator Author

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
Copy link
Collaborator Author

marcbachmann commented Mar 26, 2023

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

passthrough onNoMatch does not work with axios 1.2.0 or above
5 participants