HomePhabricator
Diffusion Comm 961052269b9f

[web] Fix missing WebCrypto mock in tests

Description

[web] Fix missing WebCrypto mock in tests

Summary:
Fixes https://linear.app/comm/issue/ENG-3276/web-unit-tests-mock-missing-webcrypto-apis

There are a few solutions, I decided to go with Jest setupFiles.

Some other solutions on StackOverflow: https://stackoverflow.com/questions/52612122/how-to-use-jest-to-test-functions-using-crypto-or-window-mscrypto - they use Object.defineProperty, but simply assigning the variable does the trick as well.

The crypto.webcrypto is a polyfill introduced in Node 15 that provides compatibility with browser APIs.

Test Plan:

  • Run yarn test in web without this change. Tests for text-utils and device-id should fail.
  • Apply this diff and re-run tests. All tests should pass.

Reviewers: ashoat

Reviewed By: ashoat

Subscribers: tomek, atul

Differential Revision: https://phab.comm.dev/D7019

Details

Provenance
bartekAuthored on Mar 9 2023, 8:51 AM
Reviewer
ashoat
Differential Revision
D7019: [web] Fix missing WebCrypto mock in tests
Parents
rCOMM538ca1cc8b28: [Identity] Rename IdentityService service to IdentityKeyserverService
Branches
Unknown
Tags
Unknown