Open krotovic opened 5 months ago
Thanks for the repository! I fiddled around with it a bit.
I don't think 0.2.88 broke jest. It probably broke when webcrypto
was introduced to lib0.
lib0
makes a lot of use of the package exports feature to link to "native" alternatives (the browser uses browser webcrypto, nodejs uses nodejs apis).
package.json exports is a stable feature of nodejs. Pretty much all module bundlers support it. They are very useful.. I'm sorry that they are not well supported in jest..
My best bet would be to try explicitly setting a mapping from lib0/webcrypto
to the desired file:
I tried explicitly mapping lib0/webcrypto to the cjs file by setting moduleNameMapper
:
// jest.config.js
moduleNameMapper: {
'lib0/webcrypto': '<rootDir>/node_modules/lib0/dist/webcrypto.cjs'
}
However, when I set a custom jest config, I can't start using react-scripts anymore.
If you find a solution, it would be great if you could post it here, as it could help others!
Describe the bug When running tests for Yjs with
react-scripts test
, import oflib0/webcrypto
insidelib0/dist/random.cjs
causes test failure with "SyntaxError: Unexpected token 'export'".To Reproduce Steps to reproduce the behavior:
npx create-react-app example-app
npm add yjs@13.5.50
src/yjs.test.js
with the content:describe('yjs', () => { it('fails', () => { expect(yjs).toBeDefined(); }); });