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

Axios 16 compat #4

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Axios 16 compat #4

wants to merge 12 commits into from

Conversation

myabc
Copy link

@myabc myabc commented Oct 15, 2017

Some additions to @teppeis's PR #3 (mostly to address this comment: #3 (comment))

  • support both older and newer versions of Axios.
  • set up testing against various versions of Axios.

cassette.originalResponseData.fixture = true
return resolve(cassette.originalResponseData)
if (arguments.length === 3) { // axios <= 0.12
var resolve = arguments[0];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove the extra semi colons?

@@ -11,7 +11,8 @@ function key(axiosConfig) {
method: axiosConfig.method,
data: axiosConfig.data,
headers: _.omit(axiosConfig.headers, [
'Content-Length', 'content-length'
'Content-Length', 'content-length',
'User-Agent', 'user-agent'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know if axios stopped injecting its own user-agent header?
that was one of the reasons I needed some of those workarounds.

Copy link
Author

@myabc myabc Oct 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nettofarah this change was made quite some time ago: axios/axios@db85c7b - Axios only injects its own User-Agent header if none is set.

Copy link
Author

@myabc myabc Oct 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nettofarah I obviously can't read! Your original comment stated the exact same thing 😄

Removing the User-Agent is an alternate strategy that I decided to pursue after testing React components with axios-vcr + Axios + jsdom. In order to simulate a browser environment, jsdom actually provides an implementation of XmlHttpRequest, which causes axios to use the xhr adapter.

Thanks to CORS, the addition of a custom User-Agent means that the request is no longer classified as "simple" but rather one that needs to preflighted. As such, an extra OPTIONS request is fired before the actual request (and in my particular use case, this is something our server doesn't support). / @NudelSieb

If we decide to reinstate the code injecting the User-Agent: axios-vcr header, we would first need to check if the original adapter is http.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we decide to reinstate the code injecting the User-Agent: axios-vcr header, we would first need to check if the original adapter is http.

If I understand things correctly, this might be the safer option here.

@@ -21,11 +21,11 @@ function writeAt(filePath, jsonPath, value) {

return fs.readJson(filePath).then(function(json) {
_.set(json, jsonPath, value)
return fs.writeJson(filePath, json)
return fs.writeJson(filePath, json, { spaces: 2 })
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 spaces 😍

assert.deepEqual(fixture.originalResponseData, _.omit(res, 'fixture'))
done()

VCR.ejectCassette(path)
}).catch(err => { console.log(err); done() })
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would you remove the catch call here?
we want to make sure tests don't hang if they fail.

Copy link
Owner

@nettofarah nettofarah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really great.
I left a few comments and questions.

@soswow
Copy link

soswow commented Nov 8, 2017

  1. Why do we need to support older axios?
  2. It's 0.17 already latest.

@soswow
Copy link

soswow commented Nov 8, 2017

Using this branch and axios 16 I have a problem. jsonPaths do not match between request and response
During request:

{
   "url":"https://launchlibrary.net/1.2/launch",
   "method":"get",
   "headers":{
      "common":{
         "Accept":"application/json, text/plain, */*"
      },
      "delete":{
      },
      "get":{
      },
      "head":{
      },
      "post":{
         "Content-Type":"application/x-www-form-urlencoded"
      },
      "put":{
         "Content-Type":"application/x-www-form-urlencoded"
      },
      "patch":{
         "Content-Type":"application/x-www-form-urlencoded"
      }
   }
}

And during response

{
   "url":"https://launchlibrary.net/1.2/launch",
   "method":"get",
   "headers":{
      "Accept":"application/json, text/plain, */*"
   }
}

@soswow
Copy link

soswow commented Nov 8, 2017

also for some reason it doesn't take params parameter =\

@nettofarah
Copy link
Owner

@soswow I would prefer that the library is backward compatible. But I'm ok with issuing a new major release to only support newer versions of axios

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.

4 participants