MasterKale / SimpleWebAuthn

WebAuthn, Simplified. A collection of TypeScript-first libraries for simpler WebAuthn integration. Supports modern browsers, Node, Deno, and more.
https://simplewebauthn.dev
MIT License
1.63k stars 137 forks source link

Lazy Text Encoder #87

Closed Moumouls closed 3 years ago

Moumouls commented 3 years ago

Found an issue during some JSDOM Jest tests.

TextEncoder is not currently supported correctly into jsdom env of Jest.

To avoid a systemic crash at import time it's better to init text encoder into the function.

A workaround is to use the node env of Jest. But some tests require jsdom and could import indirectly the package.

MasterKale commented 3 years ago

I originally fixed this with browser's custom jest-environment.js. Is this no longer working? Unit tests are still passing in this library, so is this PR to fix issues with your Jest setup?

Moumouls commented 3 years ago

I originally fixed this with browser's custom jest-environment.js. Is this no longer working? Unit tests are still passing in this library, so is this PR to fix issues with your Jest setup?

In this library it works, but not in other projects (e.g. Parse SDK JS). This error happened in Parse SDK JS unit tests. The solution with custom jest env will work, but it seems to me more appropriate also to avoid this error by just doing an import 😃 Also i don't know when jest will add the support of TextEncoder into the JSdom.

MasterKale commented 3 years ago

@Moumouls I don't know why I resisted this for so long - thank you for helping make this library more pleasant to integrate 😅

MasterKale commented 3 years ago

This has been published to NPM as browser@0.10.6