-
Notifications
You must be signed in to change notification settings - Fork 17
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
feat!: Support Axios v1 #46
Conversation
BREAKING CHANGE: CreateAxiosRequestTransformer now must return AxiosRequestTransformer instead of AxiosResponseTransformer.
axios [1.0.0, 2.0.0) are now supported. < 1.0.0 versions are also supported, but it will be deleted in the next major release. To run jest testing on axios v1, I also added babel-jest to transform ES modules that axios exports because jest only supports CommonJS without enabling experimental ESM support implicitly.
// HACK: Axios exports their module in both CommonJS style and ESM style. | ||
// However, jest does prefer the ESM one that occurs a runtime error. | ||
// So in this resolver the main module of axios package is replaced to CommonJS one. | ||
// This only applies to tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice solution 👍
@@ -78,7 +78,7 @@ export interface CreateAxiosInterceptor { | |||
(options?: AxiosCaseMiddlewareOptions): AxiosInterceptor; | |||
} | |||
export interface CreateAxiosRequestTransformer { | |||
(options?: AxiosCaseMiddlewareOptions): AxiosResponseTransformer; | |||
(options?: AxiosCaseMiddlewareOptions): AxiosRequestTransformer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch ✨
test/integration/basic.ts
Outdated
@@ -94,7 +94,7 @@ test('it should be converted on success', (done) => { | |||
}) | |||
.then((response) => { | |||
expect(JSON.stringify(response.data)).toBe(JSON.stringify(camelData)); | |||
expect(response.headers.contentType).toBe('application/json'); | |||
expect(response.headers.contentType || response.headers['Content-Type']).toBe('application/json'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of these changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mpyw response.headers.contentType
is no longer available in axios >= 1.0, so I added response.headers['Content-Type']
which actually exists. To keep backward compatibility, I left the previous one with logical OR. This means the tests can be run even with axios < 1.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was headers.contentType
really generated by axios
, not by axios-case-converter
? I suspect that the camelCase conversion no longer works for latest axios
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mpyw Could you please approve to run CI workflow for confirming the tests pass? |
Closes #45
axios [1.0.0, 2.0.0) are now supported.
< 1.0.0 versions are also supported, but it will be deleted in the next major release.
To run jest testing on axios v1, I also added babel-jest to transform ES modules that axios exports because jest only supports CommonJS without enabling experimental ESM support implicitly.