jest-chain
jest-chain copied to clipboard
Update to work with jest version 27
Note
This PR would require a new tag, because it updates functionality to work with Jest version 27 (instead of 25 like currently). There's no backward compatibility.
What
The class JestAssertionError does no longer pass message: ()=> string as matcherResult, but the message as a string:
class JestAssertionError extends Error {
matcherResult?: Omit<SyncExpectationResult, 'message'> & {message: string};
}
(from Jest)
Why
The JestAssertionError in this repo still called super(result.message()) which with Jest 27 causes an error to be thrown result.message instead of showing the correct matcher error.
See issue: https://github.com/mattphillips/jest-chain/issues/34
- [x] Unit tests
- [x] Documentation is up to date
- [x] No additional lint warnings
Would something along the lines of:
super(typeof result.message === 'function' ? result.message() : result.message);
be better to maintain backwards compatibility? (a little hacky nonetheless)
That's actually what I did to fix the problem on my local environment and it works. But I think the question is: is there a point in maintaining backward compatibility ?
What I mean is jest-chain works as it's supposed to and I don't see the need for some new features.
So I'm not sure someone using current version with Jest 25 would take with a dim view not being able to update.
I hope @mattphillips sees this. This repo doesn't seem to be still alive as there hasn't been a commit for over a year and a half.
I suggested to add this maybe as a new version, because I didn't add backward compatibility on purpose - would have required also updating the tests etc. Seeing as the current state is working for a jest version that is two majors behind the current one, I think a new version for this lib, making explicit that it is working with > Jest 27, would be a good solution.
I'm not sure if it will get merged though, the repository looks a bit abandoned 🤔 ?
I'm currently using my own fork in the project I needed the change in: https://github.com/programmiri/jest-chain/tree/include-dist
I included the dependency updates there and a co-worker 💜 also fixed this issue with the runtime errors on that branch.
I'm not sure what we'll do if the lib isn't updated in some time, probably add it as a internal package in our own repository. Don't think duplicating a repository or something like that is a nice move in OS? :D
Perhaps tagging @mattphillips again will help? Otherwise there may be no choice but to stop using jest-chain, or fork it with the bug fix for Jest 27.
FYI - I'd raised a ticket around this in the main Jest repos - where they helped me narrow the issue down to jest-chain looks like Matt has been nudged in that conversation - so perhaps it will bring it back to the top of this notifications
https://github.com/facebook/jest/issues/11933
has there been no update on this? Can we get a fork going for jest? Currently working on a project that is based on jest 24 and upgrading is painful. Lots of this bug cropping up :(
I've not received feedback for this yet, sorry.
We're currently still using my branch at work 🙈 but that's not a long-term solution, so I may implement that functionality as an internal package in our repository.
It does not look like this repo is worked on anymore (which is totally ok!) so I thought it makes no sense to try to create an MR with a fix for this issue while keeping it backward compatible.
But feel free to e.g. copy the stuff I did in my fork for further use! It fixed this for us (currently using Jest 27.0.6).
I've not received feedback for this yet, sorry.
We're currently still using my branch at work 🙈 but that's not a long-term solution, so I may implement that functionality as an internal package in our repository.
It does not look like this repo is worked on anymore (which is totally ok!) so I thought it makes no sense to try to create an MR with a fix for this issue while keeping it backward compatible.
But feel free to e.g. copy the stuff I did in my fork for further use! It fixed this for us (currently using Jest 27.0.6).
I'm using your repository instead. Thank you! For anyone who is interested, here is the config in package.json.
"jest-chain": "github:programmiri/jest-chain#include-dist",
This is a huge blocker. Too bad the project doesn't seem to be maintained as the fix is really simple and does not cause any other problem that I can see...
Hey @programmiri thanks for submitting this fix and sorry for the delay in merging it!
I'll get this published shortly and will report back with a version number.
Very nice!
Fix has been published in: https://www.npmjs.com/package/jest-chain/v/1.1.6