-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
fix(jest-worker): Remove circular references from messages sent to workers #10881
Conversation
d67338b
to
75e522f
Compare
75e522f
to
8fc3d64
Compare
We'd want to restore the original object on the receiving side, no? Should we use something like https://github.com/storybookjs/telejson? |
@SimenB sounds reasonable. I'll try to rework. |
Would the 'advanced' serialization format be an alternative for use-cases that require circular references to avoid that all workers must pay for the overhead of I would suggest to not enable this option by default because it comes with a slight performance overhead. |
@MichaReiser I tried that, but it just changes the error to the same as worker threads
While using worker (which uses structured clone by default)
|
@SimenB that's rather interesting because the MDN documentation explicitly mentions circular references...
What kind of object did you pass? Any chance it did use Proxies, contained Symbols, or used other features that make it not a plain JS object? spec However, it is as it is. I still believe that it would make sense to change jest worker to allow passing in a custom serializer / deserialiser instead of requiring a custom serialization logic for all clients. Or manually calling |
I've opened up #10981 which uses |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Fixes #10577
Summary
This fix prevents objects with circular references to be sent to worker processes. Node uses
JSON.stringify
to serialize such messages and this causes an error in case there are circular references in the messages.Please note I added new dependency,
fclone
, though I'm not sure it's allowed or if there already is another such function in the repository.Test plan
This fix allows to run the tests described in the issue linked. The repro setup can be found at https://repl.it/@Frantiekiaik/jest-playground-1.