gutenberg-mobile
gutenberg-mobile copied to clipboard
Module `yjs` is being imported twice when running tests
Describe the bug
As shared in https://github.com/wordpress-mobile/gutenberg-mobile/pull/6049#issuecomment-1671758916, when running tests the module yjs is producing a failure with the error:
console.error
Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438
3 | */
4 | // @ts-ignore
> 5 | import { IndexeddbPersistence } from 'y-indexeddb';
| ^
6 |
7 | /** @typedef {import('./types').ObjectType} ObjectType */
8 | /** @typedef {import('./types').ObjectID} ObjectID */
at console.<anonymous> (gutenberg/node_modules/jest-mock/build/index.js:709:23)
at Object.<anonymous> (gutenberg/node_modules/yjs/src/index.js:124:11)
at Object.<anonymous> (gutenberg/node_modules/y-indexeddb/dist/y-indexeddb.cjs:5:9)
at Object.require (gutenberg/packages/sync/src/connect-indexdb.js:5:1)
at Object.require (gutenberg/packages/sync/src/index.js:1:1)
at Object.require (gutenberg/packages/core-data/src/sync.js:4:1)
at Object.require (gutenberg/packages/core-data/src/actions.js:21:1)
at Object.require (gutenberg/packages/core-data/src/entities.js:15:1)
at Object.require (gutenberg/packages/core-data/src/queried-data/reducer.js:16:1)
at Object.require (gutenberg/packages/core-data/src/queried-data/index.js:3:1)
at Object.require (gutenberg/packages/core-data/src/reducer.js:17:1)
at Object.require (gutenberg/packages/core-data/src/index.js:9:1)
at Object.require (gutenberg/packages/edit-post/src/index.native.js:4:1)
at Object.require (src/jetpack-editor-setup.js:5:1)
at Object.require (src/test/index.js:11:1)
It's likely that some of the test cases, especially the ones that cover the setup process, are re-importing this module more than once. In any case, we should investigate this behavior further in case it's covering any undesired side effects.
To Reproduce
- This has been solved by mocking the module, so to reproduce the failure we need to revert the change: https://github.com/wordpress-mobile/gutenberg-mobile/commit/137431daf81843be334d36aef6496a26c3766af2.
- Run the command
npm run test. - Observe the failure in the tests.
Expected behavior Tests should succeed without needing to mock modules out of the scope of the test cases.
Noting that this same error currently logs when running tests in WordPress/gutenberg as well: npm run test:native. We'll need to implement a solution in that repository.