Skip to content

Instantly share code, notes, and snippets.

@silviot
Created January 8, 2021 15:15
Show Gist options
  • Save silviot/4b062421a2bc6e128ffe666873060cda to your computer and use it in GitHub Desktop.
Save silviot/4b062421a2bc6e128ffe666873060cda to your computer and use it in GitHub Desktop.
Apply patch to jsdom
#!/bin/bash
# This PR lays unmerged, so we apply it with this script:
# https://github.com/jsdom/jsdom/pull/3073
find node_modules/ -name xhr-utils.js -exec patch -N -r- {} ./jsdom.patch \;
--- node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/xhr-utils.js.orig 2021-01-06 16:00:27.029643588 +0100
+++ node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/xhr-utils.js 2021-01-06 16:06:04.662096891 +0100
@@ -93,7 +93,9 @@
}
const acahStr = response.headers["access-control-allow-headers"];
const acah = new Set(acahStr ? acahStr.trim().toLowerCase().split(headerListSeparatorRegexp) : []);
- const forbiddenHeaders = Object.keys(flag.requestHeaders).filter(header => {
+ const forbiddenHeaders = acah.has("*") ?
+ [] :
+ Object.keys(flag.requestHeaders).filter(header => {
const lcHeader = header.toLowerCase();
return !simpleHeaders.has(lcHeader) && !acah.has(lcHeader);
});
@silviot
Copy link
Author

silviot commented Jan 8, 2021

To apply the fix from jsdom/jsdom#3073 before it's merged you can add the above files to your project and add the following to your package.json:

  "scripts": {
    "postinstall": "sh fix-jsdom.sh",
  },

Only tested on Linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment