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

JSDom 11.12 causes SecurityError: localStorage is not available for opaque origins #6766

Closed
csvan opened this issue Jul 27, 2018 · 22 comments · Fixed by #6792
Closed

JSDom 11.12 causes SecurityError: localStorage is not available for opaque origins #6766

csvan opened this issue Jul 27, 2018 · 22 comments · Fixed by #6792

Comments

@csvan
Copy link

csvan commented Jul 27, 2018

🐛 Bug Report

A clear and concise description of what the bug is.

Jsdom just recently upgraded to version 11.12, which includes support for window.localStorage and other features. See https://github.com/jsdom/jsdom/blob/master/Changelog.md.

A fresh yarn install deduces that Jest uses this latest version, but this causes all existing Jest test cases to fail with:

SecurityError: localStorage is not available for opaque origins

To Reproduce

Steps to reproduce the behavior:

  1. Install latest Jest
  2. Make a clean yarn/npm install
  3. Setup a basic test case
  4. Run it

Expected behavior

Test case should pass.

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: Linux 4.15
    CPU: x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
  Binaries:
    Node: 10.7.0
    Yarn: 1.7.0
    npm: 6.1.0
  npmPackages:
    jest:
      wanted: ~23.4.0
      installed: 23.4.1

@csvan
Copy link
Author

csvan commented Jul 27, 2018

Relevant: jsdom/jsdom#2304

@csvan
Copy link
Author

csvan commented Jul 27, 2018

Update: as noted in the linked issue, adding the following to the Jest config solves the issue:

testURL: 'http://localhost'

Perhaps the default for this config option needs to be changed?

@csvan csvan changed the title JSDOM 11.12 causes: SecurityError: localStorage is not available for opaque origins JSDom 11.12 causes SecurityError: localStorage is not available for opaque origins Jul 27, 2018
@SamuelBrucksch
Copy link

This fix seems to work. However when i run my tests from Webstorm i always get empty test suite now. Looks like there are also issues now with the Jest plugin in Webstorm when adding a testURL.

@gokulkrishh
Copy link

gokulkrishh commented Jul 27, 2018

@csvan @SamuelBrucksch I was just debugging the issue. Jest is using a dependency module called jest-environment-jsdom in itspackage.json --> "jsdom": "^11.5.1" caret(^) because of this npm have installed jsdom as 11.12.0 (which is new version published today). Hence the issue

@Ky6uk
Copy link

Ky6uk commented Jul 27, 2018

Hmm. Defining testURL: 'http://localhost' globally in Jest's config doesn't help me. But defining testURL in the specific project helps. Is it probably issue when you have projects: [] in Jest config?

@OlivierB-OB
Copy link

As a temporary workaround you can install jsdom "11.11.0" (exact) as a dev-dependency in your package. jest-environment-jsdom should then use this version instead of the lastest "11.12.0" causing the behavior.

Cheers!

@wahengchang
Copy link

Add testEnvironment env config for non-browser enviroment

  "jest": {
    "testEnvironment": "node"
  },

hwillson added a commit to apollographql/apollo-client that referenced this issue Jul 27, 2018
A recent Renovate merged Jest update caused all tests to start to
fail, due to JSDom security errors. This config adjustment was
recommended in the Jest repo to address this issue.

Relates to:
jestjs/jest#6766 (comment)
taras added a commit to microstates/react that referenced this issue Jul 28, 2018
mbfisher added a commit to mbfisher/seek-style-guide that referenced this issue Jul 28, 2018
mbfisher added a commit to mbfisher/sku that referenced this issue Jul 28, 2018
mbfisher added a commit to mbfisher/sku that referenced this issue Jul 29, 2018
andgreendigital added a commit to and-digital/and-workshop-corejs that referenced this issue Jan 14, 2019
splix added a commit to emeraldpay/emerald-wallet that referenced this issue Jan 19, 2019
splix added a commit to emeraldpay/emerald-wallet that referenced this issue Jan 19, 2019
splix added a commit to emeraldpay/emerald-wallet that referenced this issue Jan 19, 2019
splix added a commit to emeraldpay/emerald-wallet that referenced this issue Jan 19, 2019
leosuncin added a commit to leosuncin/graphql-import-loader that referenced this issue Jan 28, 2019
Use the file path instead of file content to import schema. Set Jest's environment to node
to avoid the error with jsdom's localStorage, see jestjs/jest#6766 and jsdom/jsdom#2304.

BREAKING CHANGE: Use absolute path inside DSL won't work anymore, but now will be the same
behavior of `graphql-import` dealing with paths.

Fix prisma-labs#10
ef-stripe pushed a commit to stripe-archive/timberlake that referenced this issue Jan 28, 2019
tollmanz added a commit to CondeNast/perf-timeline-cli that referenced this issue Mar 24, 2019
Jest updated the JSDOM dependency to 11.12+ in a recent update. This
update causes Jest to throw a security error about localStorage when the
tests are assumed to run in the browser and no `testURL` is defined.

Since our tests are not run in the browser, a workaround for this issue
is to explicitly define the environment as `node`. Hopefully this
protects us from weird edge cases in the future.

Refs: jestjs/jest#6766,
jsdom/jsdom#2304
tollmanz added a commit to CondeNast/perf-timeline-cli that referenced this issue Mar 24, 2019
Jest updated the JSDOM dependency to 11.12+ in a recent update. This
update causes Jest to throw a security error about localStorage when the
tests are assumed to run in the browser and no `testURL` is defined.

Since our tests are not run in the browser, a workaround for this issue
is to explicitly define the environment as `node`. Hopefully this
protects us from weird edge cases in the future.

Refs: jestjs/jest#6766,
jsdom/jsdom#2304
tollmanz added a commit to CondeNast/perf-timeline-cli that referenced this issue Mar 24, 2019
Jest updated the JSDOM dependency to 11.12+ in a recent update. This
update causes Jest to throw a security error about localStorage when the
tests are assumed to run in the browser and no `testURL` is defined.

Since our tests are not run in the browser, a workaround for this issue
is to explicitly define the environment as `node`. Hopefully this
protects us from weird edge cases in the future.

Refs: jestjs/jest#6766, jsdom/jsdom#2304
tollmanz added a commit to CondeNast/perf-timeline-cli that referenced this issue Mar 24, 2019
Jest updated the JSDOM dependency to 11.12+ in a recent update. This
update causes Jest to throw a security error about localStorage when the
tests are assumed to run in the browser and no `testURL` is defined.

Since our tests are not run in the browser, a workaround for this issue
is to explicitly define the environment as `node`. Hopefully this
protects us from weird edge cases in the future.

Refs: jestjs/jest#6766, jsdom/jsdom#2304
mariocao pushed a commit to mariocao/sheikah that referenced this issue May 17, 2019
cajames added a commit to cajames/vue-tag-manager that referenced this issue Jun 20, 2019
- Handle major changes to JSDom in 11.12 ([read here](jestjs/jest#6766))
- Setting test URL for jest environment to handle above ([read here](https://jestjs.io/docs/en/configuration#testurl-string))
cajames added a commit to cajames/vue-tag-manager that referenced this issue Jun 25, 2019
- Handle major changes to JSDom in 11.12 ([read here](jestjs/jest#6766))
- Setting test URL for jest environment to handle above ([read here](https://jestjs.io/docs/en/configuration#testurl-string))
viralganatra added a commit to viralganatra/app-scripts that referenced this issue Jul 13, 2019
Background: Running Jest without the testUrl option results in the following error:

"localStorage is not available for opaque origins"

jestjs/jest#6766
TomJamesDuffy added a commit to clocklimited/cf-form-cancel-delegate that referenced this issue Jul 26, 2019
jamesplease pushed a commit to jamesplease/bestfetch that referenced this issue Nov 21, 2019
could not run tests due to this error -- jestjs/jest#6766
MaxDesiatov added a commit to graphql-community/graphql-directive-uid that referenced this issue Apr 7, 2020
Update in package.json is required to work around jestjs/jest#6766
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet