Issue 1:
Describe the bug

When upgrading from 0.19.0 to 0.19.1, our test suite breaks because nock receives the cors OPTIONS call, which it did not receive before and did not expect. This is a breaking change, and I wouldn't expect the OPTIONS call to be made during tests.

Here's the error stack :

Error: Error: Nock: No match for request {
"method": "OPTIONS",
"url": "http://some_url.org/",
"headers": {
"origin": "http://localhost",
"access-control-request-method": "PUT",
"user-agent": "Mozilla/5.0 (darwin) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/11.12.0",
"host": "some_url.org",
"content-length": 0
}
}
at Object.dispatchError (/Users/somatt/www/hm/_hm/app/client/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:65:19)
at EventEmitter.<anonymous> (/Users/somatt/www/hm/_hm/app/client/node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:676:20)
at EventEmitter.emit (events.js:215:7)
at Request.<anonymous> (/Users/somatt/www/hm/_hm/app/client/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:412:47)
at Request.emit (events.js:210:5)
at Request.onRequestError (/Users/somatt/www/hm/_hm/app/client/node_modules/request/request.js:881:8)
at OverriddenClientRequest.emit (events.js:210:5)
at /Users/somatt/www/hm/_hm/app/client/node_modules/nock/lib/intercepted_request_router.js:101:11
at processTicksAndRejections (internal/process/task_queues.js:75:11)
at runNextTicks (internal/process/task_queues.js:62:3) undefined

Expected behavior

Mostly, a patch version should not break anything and breaking changes should be documented.

Environment:

Axios Version 0.19.1

OS: OSX 10.15.3 (19D76)

nock: 11.7.0

Issue 2:
Describe the bug

After upgrading axios from 0.19.0 to 0.19.1 all tests that use nock got broken. They now produce the following error:

Error: Cross origin http://localhost forbidden

To Reproduce

Repo with minimal test case that reproduces the issue: https://github.com/EvgenyOrekhov/js-framework/tree/axios-bug.

Note that previous commit (which has axios 0.19.0) works fine, the test passes.

import axios from "axios";
import nock from "nock";

it("makes HTTP requests", async done => {
const scope = nock("https://example.com/foo/")
.get("/bar")
.reply(200, { foo: "bar" });

await axios.get("https://example.com/foo/bar");

scope.done();
done();
});

Expected behavior

The test should pass.

Environment:

Axios Version: 0.19.1

OS: Ubuntu 19.10

Browser: n/a

Browser Version: n/a

Additional Library Versions: nock 11.7.2

Additional context/Screenshots

Jest error with stack trace:

FAIL src/http.test.js
✕ makes HTTP requests (34ms)

● makes HTTP requests

Network Error

at createError (node_modules/axios/lib/core/createError.js:16:15)
at XMLHttpRequest.handleError (node_modules/axios/lib/adapters/xhr.js:83:14)
at XMLHttpRequest.<anonymous> (node_modules/jsdom/lib/jsdom/living/helpers/create-event-accessor.js:33:32)
at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:193:27)
at XMLHttpRequestEventTargetImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
at XMLHttpRequestEventTargetImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
at XMLHttpRequest.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:157:21)
at requestErrorSteps (node_modules/jsdom/lib/jsdom/living/xhr-utils.js:132:7)
at dispatchError (node_modules/jsdom/lib/jsdom/living/xhr-utils.js:62:3)
at Object.validCORSHeaders (node_modules/jsdom/lib/jsdom/living/xhr-utils.js:77:5)
at receiveResponse (node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:847:21)
at Request.<anonymous> (node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:679:38)
at Request.onRequestResponse (node_modules/request/request.js:1066:10)
at respond (node_modules/nock/lib/playback_interceptor.js:299:11)
at respondUsingInterceptor (node_modules/nock/lib/playback_interceptor.js:341:7)
at node_modules/nock/lib/playback_interceptor.js:281:7

console.error node_modules/jsdom/lib/jsdom/virtual-console.js:29
Error: Cross origin http://localhost forbidden
at dispatchError (/home/user/my-app/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:65:19)
at Object.validCORSHeaders (/home/user/my-app/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:77:5)
at receiveResponse (/home/user/my-app/node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:847:21)
at Request.<anonymous> (/home/user/my-app/node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:679:38)
at Request.emit (events.js:321:20)
at Request.onRequestResponse (/home/user/my-app/node_modules/request/request.js:1066:10)
at OverriddenClientRequest.emit (events.js:321:20)
at respond (/home/user/my-app/node_modules/nock/lib/playback_interceptor.js:299:11)
at respondUsingInterceptor (/home/user/my-app/node_modules/nock/lib/playback_interceptor.js:341:7)
at /home/user/my-app/node_modules/nock/lib/playback_interceptor.js:281:7 undefined