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

Add the ability to bypass prompts by passing command line arguments #189

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

uselessinfo
Copy link

Users would be able to bypass all prompts by passing the options via command line. A complete example looks like this:

> npx jest-codemods src/cli/**/*.test.ts --force --parser=tsx --transformer=mocha --mochaAssertion=chai-should --standaloneMode=0 --skipImportDetection

NOTICE: Skipping import detection, you might get false positives
Executing command: jscodeshift -t /Users/jonathan.waltner/git/jest-codemods/dist/transformers/mocha.js src/cli/git-status.test.ts src/cli/transformers.test.ts --ignore-pattern node_modules --parser tsx --extensions=tsx,ts --skipImportDetection=true
Processing 2 files... 
Spawning 2 workers...
Sending 1 files to free worker...
Sending 1 files to free worker...
All done. 
Results: 
0 errors
2 unmodified
0 skipped
0 ok
Time elapsed: 0.888seconds 
Executing command: jscodeshift -t /Users/jonathan.waltner/git/jest-codemods/dist/transformers/chai-should.js src/cli/git-status.test.ts src/cli/transformers.test.ts --ignore-pattern node_modules --parser tsx --extensions=tsx,ts --skipImportDetection=true
Processing 2 files... 
Spawning 2 workers...
Sending 1 files to free worker...
Sending 1 files to free worker...
All done. 
Results: 
0 errors
0 unmodified
2 skipped
0 ok
Time elapsed: 0.665seconds 

This allows for integration with editors and for easy consistency when doing a piecemeal conversion of an existing test suite on a large codebase.

@codecov
Copy link

codecov bot commented Jan 16, 2020

Codecov Report

Merging #189 into master will decrease coverage by 0.61%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #189      +/-   ##
==========================================
- Coverage   92.84%   92.23%   -0.62%     
==========================================
  Files          24       24              
  Lines        1496     1506      +10     
  Branches      309      310       +1     
==========================================
  Hits         1389     1389              
- Misses         72       82      +10     
  Partials       35       35
Impacted Files Coverage Δ
src/cli/index.ts 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f20f26e...c1a65b0. Read the comment docs.

Copy link
Owner

@skovhus skovhus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

I'm a bit reluctant here. I see the editor integration as a nice use-case, but I'm considering if it makes sense to expose this using another API.

If we do want to expose all the command line options we should:

  • Validate the command-line options – you can easily make a mistake here)
  • Add some unit test documenting that this actually works (I can help with this)
  • We need to improve some of the documentation (I did some suggestions in here)
  • --transformer should also allow the option all

Let me know what your primary use case are for the adding CLI arguments. Then we can try to figure out the best solution for those use cases. :)

--parser The parser to use (babel, flow, ts, tsx)
--transformer The transformer to use (ava, chai-assert, chai-should, expect-js, expect, jasmine-globals, jasmine-this, mocha, should, tape)
--skipImportDetection Keep using the global object for assertions
--standaloneMode Use explicit require calls instead of globals
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use explicit require calls instead of globals -> Use explicit require calls to Jest instead of globals (not recommended unless you run the tests in a browser)

-d, --dry Dry run (no changes are made to files)
--parser The parser to use (babel, flow, ts, tsx)
--transformer The transformer to use (ava, chai-assert, chai-should, expect-js, expect, jasmine-globals, jasmine-this, mocha, should, tape)
--skipImportDetection Keep using the global object for assertions
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use if your current assertion library is not required, but globally available (might result in some false positive transformations)

@uselessinfo
Copy link
Author

I am perfectly happy to go a different route if there is a better way to go about this, but I'd be equally happy to add some tests and better validation, whatever you think is best.

Our use case is that we have a large suite of Tape tests and are migrating to Jest. Doing the transformation wholesale is not really an option, but doing them piecemeal as we update areas of the code is. The hope was that we could either share a snippet, or define a task in VSCode that would do the specific combination of transforms that we know we need, without relying on everyone to choose consistent options each time they update a test.

CLI arguments was just the quickest and most portable way I could think of to do this.

@skovhus
Copy link
Owner

skovhus commented Jan 24, 2020

Thank for sharing more context here. I’m curious if you could share the size of the codebase and why moving everything wouldn’t be possible.

I understand that having everything as CLI options would be nice for some projects.

There are two options:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants