Introduce jest snapshot testing utils (fixes #135)#297
Introduce jest snapshot testing utils (fixes #135)#297Daniel15 merged 2 commits intofacebook:masterfrom
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 |
|
@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
applyTransformfunction, since it can be used for a lot of things.runInlineTestand extractedapplyTransformfunctionrunSnapshotTest, same asrunInlineTestbut takes noexpectedOutputdefineSnapshotTest, same asdefineInlineTestbut takes noexpectedOutputrunInlineTestandrunSnapshopTestnow both also return the resultapplyTransform