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

AbortController: Request is not defined #205

Closed
reelmatt opened this issue Aug 10, 2020 · 1 comment
Closed

AbortController: Request is not defined #205

reelmatt opened this issue Aug 10, 2020 · 1 comment

Comments

@reelmatt
Copy link

I'm running into a similar issue to #204 with the new AbortController module introduced in v0.9.0.

My Node.js/Express app still seems fine when I hit API endpoints manually, or testing through Postman. However, when trying to run unit tests with Jest (v26.3.0), it complains throwing a ReferenceError:

 FAIL  test/base.test.js
  ● Test suite failed to run

    ReferenceError: Request is not defined

      19 | 
      20 | /* SETUP */
    > 21 | const Airtable = require('airtable');
         |                  ^
      22 | 
      23 | 
      24 | 

      at Object.<anonymous> (node_modules/airtable/lib/abort-controller.js:5:25)
      at Object.<anonymous> (node_modules/airtable/lib/base.js:8:23)
      at Object.<anonymous> (node_modules/airtable/lib/airtable.js:3:12)
      at Object.<anonymous> (lib/base.js:21:18)
      at Object.<anonymous> (test/base.test.js:3:14)

This seems to be expected behavior for Jest as they don't polyfill environments, but I'm not sure how to proceed.

Forking the repo and changing the lib/abort-controller.js file to the following:

var fetch = require('node-fetch');

// istanbul ignore file
if (typeof window === 'undefined') {
    module.exports = require('abort-controller');
} else {
    if ('signal' in new fetch.Request('')) {
        module.exports = window.AbortController;
    } else {
        var polyfill = require('abortcontroller-polyfill/dist/cjs-ponyfill');
        module.exports = polyfill.AbortController;
    }
}

silences the ReferenceError when running the tests, but then throws a TypeError: fetch is not a function., presumably from my poorly-hacked "solution".

Does any one have ideas on how to proceed?

@reelmatt
Copy link
Author

@jugglinmike answered this in #204. The solution was adding whatwg-fetch to the Jest setup files.

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

No branches or pull requests

1 participant