-
-
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-runner): Handle unsafe worker_threads structureClone
with function
type in matchers
#14436
base: main
Are you sure you want to change the base?
fix(jest-runner): Handle unsafe worker_threads structureClone
with function
type in matchers
#14436
Conversation
✅ Deploy Preview for jestjs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
structureClone
with function
type in matchers
function makeSerializableTestResults(result: TestResult): TestResult { | ||
const {testResults} = result; | ||
const serializableResults = testResults.map(resultItem => { | ||
if (resultItem.failureDetails) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I get it right: the problem is that failureDetails
includes data which cannot be serialised? If so, it be better to serialised it earlier in the test runner.
This was discussed already, I will try to dig out the thread. The idea is that we know in advance that all what the runner returns has to be serialisable, because that data will be passed through workers. If I remember it right, the test runner is already serialising most of the data. Seem like something was simply overlooked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I get it right: the problem is that failureDetails includes data which cannot be serialised?
Yes, exactly, the problem with function
type which throw an error during clone. Also DOM nodes might cause similar behaviour, but I'm not sure if it's a valid case for workers.
If so, it be better to serialised it earlier in the test runner.
I was also thinking about it, my only concern was that it might be exposed to other tools (outside of jest
repo). But if the approach is ok I can fix this and add some tests to cover the serialisation
This was discussed already, I will try to dig out the thread
Sounds good, found this related PR, would be nice to look into other discussions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it is. I was talking about #11467. The conclusions are made in #11467 (comment) and following comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrazauskas Thanks a lot, now I have full context
…ooper/jest into fix/worker-threads-data-clone
@SimenB I'm trying to solve the issue with unserialisable values with worker_threads, as discussed here, unfortunately I can't post comments to original PR since it's closed, so let's discuss here? I made an implementation in this PR with the patch in
|
@SimenB @mrazauskas Could you guys take a look here, please? I'm ok to implement it in Good thing is that at least we keep the name of the original type, e.g. |
I think that's fine - it should be stringified by the time a reporter gets the value. If people want to format the message themselves, that should be done in a custom matcher |
Summary
This PR solves this particular issue #14423
Test plan
Issue solved, now
workerThreads
can be used safely withfunction
typesI tested the behaviour on
examples/typescript
suite. I added example test, changed config inpackage.json
to use workers and reproduced the behaviour from the issue and the checked that it is fixed after my changes were implemented. Example test:Config:
Command: