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-environment-jsdom webIDL validator issue in node 18 #14379

Closed
MGibson1 opened this issue Aug 1, 2023 · 5 comments
Closed

[Bug]: jest-environment-jsdom webIDL validator issue in node 18 #14379

MGibson1 opened this issue Aug 1, 2023 · 5 comments

Comments

@MGibson1
Copy link

MGibson1 commented Aug 1, 2023

Version

29.6.2

Steps to reproduce

  1. Clone my repo at https://github.com/mgibson1/jest-jsdom-issue
  2. Install with npm ci
  3. Test with npm run test
  4. Observe type error (note, the type of the 2nd argument is ArrayBuffer:
TypeError: Failed to execute 'importKey' on 'SubtleCrypto': 2nd argument is not instance of ArrayBuffer, Buffer, TypedArray, or DataView.

Expected behavior

Tests should pass since parameter types match

Actual behavior

Test fails with TypeError

Additional context

Working with JSDOM

The testEnvironment-node branch changes test environment to node and injects a simple JSDOM into global.

Tests pass in this branch.

Working when using a TypedArray

the typed-array branch still uses jsdom as a test environment, but converts usage in crypto from ArrayBuffer to TypedArray. I don't see why these types would be interpreted differently by the validator, but it appears that this is a reasonable workaround.

Suggested JSDOM workaround for other v22 issues

It was suggested to override JSDOM to use the correct version for other improvements that haven't made their way in to jest-environment-jsdom yet, but I'd pegged the package to the current release and this issue persists. It must be due to some configuration happening in jest-environment-jsdom.

Environment

System:
  OS: macOS 13.4.1
  CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Binaries:
  Node: 18.17.0 - /usr/local/bin/node
  npm: 9.6.7 - /usr/local/bin/npm
MGibson1 added a commit to bitwarden/clients that referenced this issue Aug 2, 2023
MGibson1 added a commit to bitwarden/clients that referenced this issue Aug 4, 2023
* Change everything to Uint8Array

related to jestjs/jest#14379

* Work on failing type tests

* Revert changes to custom matcher setup

* Remove last BufferArrays from tests

* Fix custom matcher type errors in vscode

* Remove errant `.buffer` calls on Uint8Arrays

* Encryption Pair should serialize Array Buffer and Uint8Array

* Fix EncArrayBuffer encryption

---------

Co-authored-by: Thomas Rittson <trittson@bitwarden.com>
@mrazauskas
Copy link
Contributor

It can be you are hitting #2549. Unfortunately I have no suggestions how exactly to make it work with JSDOM.

Perhaps a custom test environment could help? For example, you could build on top of jest-environment-node-single-context and inject JSDOM. Load it via @jest-environment pragma in selected test files. Just an idea. I didn’t try that.

@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 Sep 12, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 12, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

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 Nov 12, 2023
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