-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New CKEditor5 installation methods break tests: "domDocument.createElement is not a function" #17504
Comments
Hi! This would mean tweaking quite many internals of our engine (meaning it's not only what you pointed). I assume this problem is related to tree shaking (#16395) and possibly barrel files. It's possible that optimized imports will work better, but I'm not sure, @filipsobol?
I would advise not to do that via Testing the editor outside a browser is a thing we don't support, even |
It's unlikely, but worth trying. |
Thank you for your response @Witoso!
Correct me if I'm wrong, but I think this would still be a problem because tree-shaken code is only marked for deletion -- tests would need to run on production/minified code for the code to actually be removed.
Sorry, what I meant by direct imports is what you are calling optimized imports. Maybe I misunderstood, but I thought one of the goals of #15502 was to replace individual imports with a single
Mocking is definitely an option, and probably something I will explore next -- I just wanted to reach out and get your general thoughts before I started making changes. If you don't think my use-case is valid and that this is expected behavior for the ckeditor library, then I'll go a different route. |
I think that depends on your bundler/build process for tests. Maybe mentioning tree-shaking was too big a shortcut, and it is more of an effect than a cause. As you mentioned, the code leaks the need for browser's globals. Importing from indexes will pollute the scope.
The main goal was to reduce the forced webpack dependency, and also improve DX of installing tons of packages. But we realized at some point, there's going to be a need for something for more advanced users, for optimizing every byte, as 100% treeshakable code is an utopian dream in the project of our size. Some libraries call it cherry-picking, and optimized path will stay with us for sure. Currently, we monitor tree-shaking size, and it will be brought down in the future, but engine is near the end our list, as we assumed that every editor instance needs the core internals. But the case you mentioned: import, don't render, may help us revisit the priorities list (@filipsobol, @Reinmar). For now, the mocking is the safest path in a non-browser env. |
Sounds good, thank you @Witoso! |
📝 Description
I'm trying to integrate CKEditor5 into my project with the new installation methods, and I'm seeing a lot of existing tests fail due to a transitive CKEditor5 dependency. Basically, we have tests that don't depend on CKEditor5 directly, but have deeply nested children that consume CKEditor5. These children are never rendered in the test because we are shallow rendering the parent.
Our tests are currently running with
@jest-environment node
because it's a lot faster than@jest-environment jsdom
. CKEditor5, however, assumes a global document object which breaks all tests that have CKEditor5 somewhere in the dependency tree.✔️ Expected result
Test runs without a TypeError.
❌ Actual result
❓ Possible solution
These tests can be fixed simply by switching from
@jest-environment node
to@jest-environment jsdom
, but this slows things down even though CKEditor5 is not always being used. Also, not all imports from CKEditor5 require a global document, but it seems like with the new installation method, any import will now require a browser environment. Another possible workaround is to just go back to direct imports rather than importing everything fromckeditor5
.A possible solution could be to not access the document object in the global scope. For example, in domconverter.ts, the global document generates some constant variables at the top level:
Instead, these could potentially be created in the constructor when a
DomConverter
is instantiated and wouldn't require the document object unless people are actually consuming theDomConverter
class.If you'd like to see this fixed sooner, add a 👍 reaction to this post.
The text was updated successfully, but these errors were encountered: