-
Notifications
You must be signed in to change notification settings - Fork 74
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
When running tests for Yjs with react-scripts test, import of lib0/webcrypto inside lib0/dist/random.cjs causes test failure with "SyntaxError: Unexpected token 'export'".
FAIL src/yjs.test.js
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
/workspaces/lib0-webcrypto-jest-fail/node_modules/lib0/webcrypto.js:3
export const subtle = crypto.subtle
^^^^^^
SyntaxError: Unexpected token 'export'
> 1 | const yjs = require('yjs');
| ^
2 |
3 | describe('yjs', () => {
4 | it('fails', () => {
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1728:14)
at Object.<anonymous> (src/yjs.test.js:1:13)
Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 1.395 sTo Reproduce
Steps to reproduce the behavior:
- Create empty CRA project with
npx create-react-app example-app - Add dependencies via
npm add [email protected] - Create test
src/yjs.test.jswith the content:
const yjs = require('yjs');
describe('yjs', () => {
it('fails', () => {
expect(yjs).toBeDefined();
});
});- Run tests with
npm run test -- --watchAll=false - See error
Expected behavior
The test should not fail.
Environment Information
- Node.js
[email protected],[email protected]
Additional context
I created public repository for reproducing the issue in https://github.com/krotovic/lib0-webcrypto-jest-fail
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working