-
Notifications
You must be signed in to change notification settings - Fork 243
ts-migration/consistent-test-it #327
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| import { getDocsUrl, getNodeName, isDescribe, isTestCase } from './util'; | ||
| import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils'; | ||
| import { createRule, getNodeName, isDescribe, isTestCase } from './tsUtils'; | ||
|
|
||
| export default { | ||
| export default createRule({ | ||
| name: __filename, | ||
| meta: { | ||
| docs: { | ||
| url: getDocsUrl(__filename), | ||
| category: 'Best Practices', | ||
| description: 'Have control over `test` and `it` usages', | ||
| recommended: false, | ||
| }, | ||
| fixable: 'code', | ||
| messages: { | ||
|
|
@@ -26,7 +30,14 @@ export default { | |
| additionalProperties: false, | ||
| }, | ||
| ], | ||
| type: 'suggestion', | ||
| }, | ||
| defaultOptions: [ | ||
| { fn: 'test', withinDescribe: 'it' } as { | ||
| fn?: 'it' | 'test'; | ||
| withinDescribe?: 'it' | 'test'; | ||
| }, | ||
| ], | ||
| create(context) { | ||
| const configObj = context.options[0] || {}; | ||
| const testKeyword = configObj.fn || 'test'; | ||
|
|
@@ -39,6 +50,10 @@ export default { | |
| CallExpression(node) { | ||
| const nodeName = getNodeName(node.callee); | ||
|
|
||
| if (!nodeName) { | ||
| return; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new, but seeing as tests pass I guess it doesn't matter.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's required by typescript - Ah, the joys of complex ASTs 😂
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I believe this is b/c of the I mean, that branch must be being hit b/c coverage isn't complaining, so it can happen.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just so it's written down somewhere, this is the code that can be used to make It's b/c I needed to know how to do this to implement a test for another rule to get coverage other the line :) |
||
| } | ||
|
|
||
| if (isDescribe(node)) { | ||
| describeNestingLevel++; | ||
| } | ||
|
|
@@ -56,7 +71,7 @@ export default { | |
| data: { testKeyword, oppositeTestKeyword }, | ||
| fix(fixer) { | ||
| const nodeToReplace = | ||
| node.callee.type === 'MemberExpression' | ||
| node.callee.type === AST_NODE_TYPES.MemberExpression | ||
| ? node.callee.object | ||
| : node.callee; | ||
|
|
||
|
|
@@ -81,7 +96,7 @@ export default { | |
| data: { testKeywordWithinDescribe, oppositeTestKeyword }, | ||
| fix(fixer) { | ||
| const nodeToReplace = | ||
| node.callee.type === 'MemberExpression' | ||
| node.callee.type === AST_NODE_TYPES.MemberExpression | ||
| ? node.callee.object | ||
| : node.callee; | ||
|
|
||
|
|
@@ -101,9 +116,9 @@ export default { | |
| }, | ||
| }; | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| function getPreferredNodeName(nodeName, preferredTestKeyword) { | ||
| function getPreferredNodeName(nodeName: string, preferredTestKeyword: string) { | ||
| switch (nodeName) { | ||
| case 'fit': | ||
| return 'test.only'; | ||
|
|
@@ -114,7 +129,7 @@ function getPreferredNodeName(nodeName, preferredTestKeyword) { | |
| } | ||
| } | ||
|
|
||
| function getOppositeTestKeyword(test) { | ||
| function getOppositeTestKeyword(test: string) { | ||
| if (test === 'test') { | ||
| return 'it'; | ||
| } | ||
|
|
||
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.
do we need
as conston the schema?Uh oh!
There was an error while loading. Please reload this page.
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.
might not need the type info here then. Maybe not though, not sure how
enuminschemaworksThere 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.
Not as far as I'm aware - the
schemais json schema, so it's not actually used by TS (it'd be cool if it was, but it's far too complex)