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

Possible to disable jsdom for some test suites? #1467

Closed
johanventer opened this issue Jan 29, 2017 · 1 comment
Closed

Possible to disable jsdom for some test suites? #1467

johanventer opened this issue Jan 29, 2017 · 1 comment

Comments

@johanventer
Copy link

johanventer commented Jan 29, 2017

I'm working on an app that uses Amazon's API Gateway, the JS SDK uses axios under the hood. The tests that call a service fail with the following when using jsdom:

Network Error      
      at createError (node_modules/axios/lib/core/createError.js:15:15)
      at XMLHttpRequest.handleError [as onerror] (node_modules/axios/lib/adapters/xhr.js:87:14)
      at XMLHttpRequest.callback.(anonymous function) (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:289:32)
      at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:219:27)
      at invokeInlineListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:166:7)
      at EventTargetImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:122:7)
      at EventTargetImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:87:17)
      at XMLHttpRequest.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:61:35)
      at dispatchError (node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:946:9)
      at validCORSHeaders (node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:979:7)
      at receiveResponse (node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:834:12)
      at EventEmitter.client.on.res (node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:662:38)
      at emitOne (events.js:96:13)
      at EventEmitter.emit (events.js:188:7)
      at Request.realClient.on.res (node_modules/jsdom/lib/jsdom/living/xhr-utils.js:281:49)
      at emitOne (events.js:96:13)
      at Request.emit (events.js:188:7)
      at Request.onRequestResponse (node_modules/request/request.js:986:10)
      at emitOne (events.js:96:13)
      at ClientRequest.emit (events.js:188:7)
      at HTTPParser.parserOnIncomingClient (_http_client.js:474:21)
      at HTTPParser.parserOnHeadersComplete (_http_common.js:99:23)
      at TLSSocket.socketOnData (_http_client.js:363:20)
      at emitOne (events.js:96:13)
      at TLSSocket.emit (events.js:188:7)
      at readableAddChunk (_stream_readable.js:176:18)
      at TLSSocket.Readable.push (_stream_readable.js:134:10)
      at TLSWrap.onread (net.js:548:20)

If I disable jsdom (by removing --env=jsdom from package.json) then these tests succeed. However, this then makes tests using ReactDOM.render fail.

Can I have my cake and eat it to? Perhaps some way to disable jsdom in particular test suites and reset the environment?

@johanventer
Copy link
Author

Nevermind, I worked this out. I can force axios to use it's http adapter, rather than the xhr adapter it defaults to (because it detects jsdom's provided XMLHttpRequest) with:

axios.defaults.adapter = require('axios/lib/adapters/http');

@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant