ckeditor5
ckeditor5 copied to clipboard
Testing project using jest & jsdom throws ckeditor-duplicated-modules error
📝 Provide detailed reproduction steps (if any)
When running Jest unit tests for a project which imports CKEditor 5, the tests throw a ckeditor-duplicated-modules error. This is caused by an underlying JSDOM issue where it loads the CKEditor5 build script twice which causes ckeditor5-utils/src/version.js
to execute twice and throw an error.
- Run tests where jsdom is used in jest
- CKEditor throws an error
ckeditor-duplicated-modules
✔️ Expected result
No error should be thrown, there should be a better determination of version conflict and shouldn't result in breaking of test scenarios when there is no real runtime issue.
❌ Actual result
Error is thrown and tests cannot be fixed or mocked to avoid it.
❓ Possible solution
Two solutions here, both would reside in ckeditor5-utils/src/version.js
One would be to check the version to ensure it's not the same as the one currently loading. That's when we should be throwing an error, not when the same script is loaded twice.
Second would be to just avoid throwing an error entirely when in a test environment. This one is trickier and would vary based on which test runner is being used and the environment in which it's being tested.
I'd suggest moving forward with option one, for which I can push a quick PR for.
If you'd like to see this fixed sooner, add a 👍 reaction to this post.
Hi, thanks for the report. Seems like related/duplicate of https://github.com/ckeditor/ckeditor5-react/issues/219. Please check https://github.com/ckeditor/ckeditor5-react/issues/225 for more information on this topic.
Bit late to this thread, but I just ran into this issue. I was able to get my tests running by putting:
Object.defineProperty(global, 'CKEDITOR_VERSION', {
set: function(val) {
if(global.CKEDITOR_VERSION) {
global.CKEDITOR_VERSION = '';
}
}
});
in my jestSetup.js
file which set up the environment before the tests are run. Just makes it so utils/src/version.js
never throws the error since global.CKEDITOR_VERSION
is never set.
There has been no activity on this issue for the past year. We've marked it as stale and will close it in 30 days. We understand it may be relevant, so if you're interested in the solution, leave a comment or reaction under this issue.
There has been no activity on this issue for the past year. We've marked it as stale and will close it in 30 days. We understand it may still be relevant, so if you're interested in the solution, leave a comment or reaction under this issue.
We've closed your issue due to inactivity over the last year. We understand that the issue may still be relevant. If so, feel free to open a new one (and link this issue to it).