Skip to content
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

Support different parsers in the test utils #332

merged 2 commits into from Oct 29, 2019

Support different parsers in the test utils #332

merged 2 commits into from Oct 29, 2019


Copy link

@skovy skovy commented Jul 14, 2019


jscodeshift now supports TypeScript (and other parsers) via the CLI. The react-codemod package can now support different React codebases.


In order to use the defineTest helper in testUtils.js with different parsers the defineTest function needs to allow dynamic parsers and look at different extensions (for TypeScript: .ts, .tsx).

The approach used in this PR was to add another parameter testOptions that allows passing in an object with a parser key. The extension then can be inferred from the file being parsed.

I didn't feel great about adding another parameter so I opted for an object so if there are additional config options they can be added to this object rather than adding more arguments and passing many nulls to get to the proper position. I also considered folding testFilePrefix into this object:

  testFilePrefix?: string;
  parser?: "flow" | "ts" | "tsx" | ...;

However, this would be a breaking change for those using the testUtils. I'm happy to make that change but opted for avoiding the breaking change.

I also originally experiment with reusing the second existing options parameter but that's what get's passed to the transformer and it felt like mixing two unrelated option configs. Open to feedback on this approach. See the proposed pull request in react-codemod for how this helper would be used and the overall motivation for this change: reactjs/react-codemod#228


  • See the new TypeScript sample added (in the sample directory)
Copy link

@Daniel15 Daniel15 commented Oct 21, 2019

Seems like a reasonable idea. Could you please rebase?

Copy link
Contributor Author

@skovy skovy commented Oct 23, 2019

Thanks for taking a look @Daniel15! This should be ready for another look 👌

@Daniel15 Daniel15 merged commit 08b8608 into facebook:master Oct 29, 2019
1 check passed
Copy link

@vagusX vagusX commented Nov 19, 2019

Sorry but I have to ask that when will this feature release to npm? @Daniel15

@skovy skovy deleted the skovy/support-parsers-in-test-utils branch Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants