-
Notifications
You must be signed in to change notification settings - Fork 483
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
Introduce jest snapshot testing utils (fixes #135) #297
Conversation
- Refactored `runInlineTest` and extracted `applyTransform` function - Introduced `runSnapshotTest`, same as `runInlineTest` but takes no `expectedOutput` - maybe worth merging the two, but that requires breaking change - Introduced `defineSnapshotTest`, same as `defineInlineTest` but takes no `expectedOutput` - maybe worth merging the two, but that requires breaking change - `runInlineTest` and `runSnapshopTest` now both also return the result `applyTransform` - This can be used to take the result of one run and use it for another (check for idempotent)
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
Any chance for a bump on this. It's been hanging for quite a while, and would make life so much easier. |
I can try to review this soon! In the meantime you might find the existing test utils useful. |
I've published this fork as a temporary scoped package: https://www.npmjs.com/package/@hypnosphi/jscodeshift |
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.
Seems reasonable to me.
@jbrown215 does |
Looks like it's included: v0.6.4...v0.7.0 |
@Hypnosphi: Yes and yes |
For what it's worth, I was just writing a transform today and really like that you separated out const {applyTransform} = require('jscodeshift/dist/testUtils');
const fooToBar = require('../fooToBar');
function transform(input, options = null) {
return applyTransform(fooToBar, options, {source: input});
}
test('first', () => {
expect(
transform(`foo()`),
).toMatchInlineSnapshot(`"bar();"`);
}); |
The main benefit of this PR is actually the
applyTransform
function, since it can be used for a lot of things.runInlineTest
and extractedapplyTransform
functionrunSnapshotTest
, same asrunInlineTest
but takes noexpectedOutput
defineSnapshotTest
, same asdefineInlineTest
but takes noexpectedOutput
runInlineTest
andrunSnapshopTest
now both also return the resultapplyTransform