-
Notifications
You must be signed in to change notification settings - Fork 481
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
Add simple utility for unit testing jscodeshift transform #104
Conversation
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
import jscodeshift from './core'; |
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.
this should be a lazy require inside of runTest
. Jest resets the module registry after each test and we had issues previously where two copies of ast-types was present.
cc @pieterv
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.
Oooh, good point. Will fix.
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.
Updated.
ddbea63
to
7a042b7
Compare
Awesome! Would you mind mentioning this in the readme somewhere? |
Sure :) I was thinking about it a bit, and I think I'll move the test fixtures to a separate directory to keep them separate from the unit test files themselves. |
7a042b7
to
e8cedbe
Compare
Updated to add a section to the readme. |
Thanks, this is great! |
@fkling - It would be useful to mention this in the release notes for v0.3.20, mainly so people know that this is only included from that version onwards. |
Whoops, yes of course! Sorry for forgetting to add this! |
No worries 👍 |
Adds a simple utility to allow unit testing of jscodeshift transforms in a standard way, without having to write a bunch of boilerplate code. This is loosely based off the technique used in react-codemod, with some changes. The main change is that where possible it doesn't depend on any global environment/configuration:
test
function was coming from in thejs-codemod
repo 😛foo/bar.js
, test is atfoo/__tests__/bar-test.js
).js
suffix for the test fixtures (input and expected output). This is mainly so they don't accidentally get picked up as unit tests by Jest, or as code that should be bundled with the app.Also included an example of how to use it, using a simple transform (the default example from AST Explorer).