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

[Bug]: Jest 28 with jest-environment-jsdom use browser’s version of Nano ID but does not have crypto polyfill #12947

Closed
ai opened this issue Jun 17, 2022 · 3 comments

Comments

@ai
Copy link
Contributor

ai commented Jun 17, 2022

Version

28

Steps to reproduce

Jest config:

export default {
  testEnvironment: 'jsdom'
};

Add to any test:

import { nanoid } from 'nanoid'

it('works with crypto', () => {
  nanoid()
})

Expected behavior

  1. Use Node.js version (avoid package.exports.browser in resolver)
  2. Or provide a crypto polyfill in jest-environment-jsdom

Actual behavior

Error:

ReferenceError: crypto is not defined

Additional context

Nano ID has in it’s package.json:

"exports": {
    ".": {
      "browser": "./index.browser.js",
      "default": "./index.js"
    }
  }

Seems like jest-environment-jsdom is changing the resolver to use exports.*.browser but do not provide true browser environment to make it safe.

Environment

System:
    OS: Linux 5.18 Fedora Linux 36 (Workstation Edition)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
  Binaries:
    Node: 18.3.0 - ~/.asdf/installs/nodejs/18.3.0/bin/node
    Yarn: 1.22.19 - ~/.asdf/shims/yarn
    npm: 8.11.0 - ~/.asdf/plugins/nodejs/shims/npm
  npmPackages:
    jest: ^28.1.1 => 28.1.1
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Jul 17, 2022
@SimenB
Copy link
Member

SimenB commented Jul 17, 2022

JSDOM provides all APIs, not Jest itself, so this issue should go there (see discussion in uuidjs/uuid#616).


That said, JSDOM implements crypto.getRandomValues() as of https://github.com/jsdom/jsdom/releases/tag/20.0.0

@SimenB SimenB closed this as not planned Won't fix, can't repro, duplicate, stale Jul 17, 2022
@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 Aug 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants