New: Improve debugging for RuleTester#67
Conversation
984d05e to
220a1ee
Compare
220a1ee to
d6dd7df
Compare
nzakas
left a comment
There was a problem hiding this comment.
Thanks for writing this up. I feel like this is really a proposal to figure out a way to test just one snippet of code easily and less about using the debugger statement.
For instance, if we added a only: true option to each code block you care about and skipped the rest, similar to Mocha’s it.only, would that solve the problem?
| 1. Add an optional `before` function property to the config for valid/invalid code. | ||
| 2. Update RuleTester to call this function (if it exists) just prior to the valid/invalid code being passed into the rule. | ||
| 3. If the autofix code is tested as well, the before hook should be called before that as well. | ||
| 4. Because of the potential to call the `before` hook twice - it may make sense to pass in an argument that defines when this code is being called. (ie a string: 'create' | 'fix') This would enable a developer to conditionally debug whichever code they want. |
There was a problem hiding this comment.
This seems very unexpected. Can you explain why it would be run twice?
There was a problem hiding this comment.
I was thinking that the before hook might be called before RuleTester passes code into the create and fix methods for an ESLint rule. I might be mistaken about how that works, because I haven't written a rule that implements fix yet.
|
|
||
| ## Summary | ||
|
|
||
| Add a `before` hook to the valid/invalid code configuration, so that developers can inject a debugger into RuleTester before code is passed into the rule being tested. |
There was a problem hiding this comment.
I’m a bit worried at how focused this is on the debugger case. Are there any other potential uses?
There was a problem hiding this comment.
I couldn't immediately think of another use case that wasn't already solved by another API. I thought before and after would allow for performance timing, but ESLint has documentation about performance analysis on rules.
My concern with this was that by testing a single code snippit, you don't know if you've broken other tests. I bumped into this problem exactly while writing a rule. I was developing against a single code snippit, got it passing, then uncommented the others and saw that my changes had broken a handful of others.
|
|
I guess I’m used to the I’m not sold on this proposal as of this moment, but let’s see what others think. |
btmills
left a comment
There was a problem hiding this comment.
I've done a similar workflow in the past of faking .only by commenting out all the other cases. Having an API to debug one case while still running all the others without debugging would be ideal in a vacuum, though implementing that might be pretty hairy because of the way RuleTester works. If a before hook is indeed too complex, I'd be open to considering a .only equivalent since it'd still be an improvement over the status quo.
| ## Detailed Design | ||
|
|
||
| 1. Add an optional `before` function property to the config for valid/invalid code. | ||
| 2. Update RuleTester to call this function (if it exists) just prior to the valid/invalid code being passed into the rule. |
There was a problem hiding this comment.
RuleTester doesn't call rules directly. It calls linter.verify(...). If RuleTester were to call before immediately before the verify() call, it would still take developers on a tour of ESLint internals before they get to their rule code.
There was a problem hiding this comment.
That might make this a non-starter. A way to avoid stepping through the internals would be if the rule was conditionally edited and a debugger was inserted into it by RuleTester
|
Rejected in favor of #73 |
Summary
Add a
beforehook to the valid/invalid code configuration, so that developers can inject a debugger into RuleTester before code is passed into the rule being tested.Related Issues
Open issue in eslint/eslint: eslint/eslint#13625