Add a codemod
See original GitHub issueHas anybody thought/worked on a codemod already to automatically refactor jQuery based tests?
Would like to get rid off jQuery from ember-bootstrap
(@cibernox thanks for the awesome blog post btw!), but refactoring the test suite manually is probably the most work.
Certainly it would be next to impossible to cover all possible cases of chainable jQuery code, but at least for the 90% of very common cases (assertions based on .length
, .text()
, .hasClass()
) there could be some solution that relieves us at least from most of the work.
Have not worked with AST before, but would be a good use case to learn something new, unless there is already some work going into that direction?
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
Codemods: A Quick and Easy Way to Automate Code ...
The codemod will add import PropTypes from 'prop-types'; to each file and replace any instances of React.PropTypes with PropTypes .
Read more >Write Code to Rewrite Your Code: jscodeshift - Toptal
Up your refactoring game by using codemods, scripts used to rewrite other scripts. In this article, Toptal Freelance Developer Jeremy Greer walks us...
Read more >Writing your very first codemod with jscodeshift - Medium
Step 1: Open AST Explorer. From the Transform menu at the top of the page, select jscodeshift. Step 2: In the top-left panel,...
Read more >Advanced Features: Codemods | Next.js
Use codemods to update your codebase when upgrading Next.js to the latest version. ... Safely removes <a> from next/link or adds legacyBehavior prop....
Read more >Your first codemod - CodeshiftCommunity
Your first codemod. Every codemod follows the same series of operations: find, modify/insert, remove and finally output. That's it.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure, play with it.
The general rules are:
Acceptance:
click()
toawait click()
(same withfillIn
and others):contains
/:eq
/:odd
)import
statement.async
to the function.this.$(selector).text()
tofind(selector).textContent
(and assume nobody does the thing I mentioned)this.$(selector).length
tofindAll(selector).length
this.$(selector).click()
=>click(selector)
;this.$(selector).focus()
=>focus(selector)
;this.$(selector).val('something')
=>fillIn(selector)
;this.$(selector).val()
=>find(selector).value
;this.$(selector).trigger('keydown', { keyCode: num })
=>keyEvent(selector, 'keydown', num)
;$el.attr('id')
toel.id
This alone is like 70% of the work.
Given that the change of getting things wrong along the way ideally the user should be propted to review and answer Y/N on every step.
Sure, this can be closed. Forgot about it…