-
Notifications
You must be signed in to change notification settings - Fork 39
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
Check if page methods are missing await (missing-playwright-await
)
#310
base: main
Are you sure you want to change the base?
Check if page methods are missing await (missing-playwright-await
)
#310
Conversation
@@ -247,6 +247,21 @@ runRuleTester('missing-playwright-await', rule, { | |||
}, | |||
}, | |||
}, | |||
// Page methods |
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.
Would love to hear more ideas on test cases here. It's a bit simpler to check page methods than the test/except cases, since it's not a chained call.
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.
Let's add test cases to assert myPage.goto
, frame.goto
, myFrame.goto
, etc.
@@ -57,6 +57,76 @@ const playwrightTestMatchers = [ | |||
'toBeInViewport', | |||
] | |||
|
|||
const pageMethods = new Set([ |
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.
Please double check these 🙏 I tried to alphabetically sort them and make sure I included all methods that return Promise
and not any that don't, but I could have made a mistake here.
@@ -116,10 +116,17 @@ export function dig(node: ESTree.Node, identifier: string | RegExp): boolean { | |||
: false | |||
} | |||
|
|||
export function isPage(node: ESTree.CallExpression) { |
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.
I'm kind of dubious on whether this function is a good idea or not, since you have to check if node.callee
is a MemberExpression
anyway to get the type checking to work properly. Open to thoughts.
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.
How about instead accepting a MemberExpression
and then doing isPage(node.callee)
.
{ code: `await page.goto('https://example.com')` }, | ||
{ code: `await page.title()` }, | ||
// Other page methods are ignored | ||
{ code: `page.frames()` }, | ||
// Other methods with the same name are ignored | ||
{ code: `randomObject.title()` }, | ||
// Does not need to be awaited when returned | ||
{ code: `() => { return page.content() }` }, |
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.
Let's add a few tests for this
, e.g. this.page.goto()
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.
Also, this probably doesn't support stuff like this: page.locator('.foo').click()
. Without that, this rule is pretty limited in usefulness.
@@ -247,6 +247,21 @@ runRuleTester('missing-playwright-await', rule, { | |||
}, | |||
}, | |||
}, | |||
// Page methods |
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.
Let's add test cases to assert myPage.goto
, frame.goto
, myFrame.goto
, etc.
@@ -116,10 +116,17 @@ export function dig(node: ESTree.Node, identifier: string | RegExp): boolean { | |||
: false | |||
} | |||
|
|||
export function isPage(node: ESTree.CallExpression) { |
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.
How about instead accepting a MemberExpression
and then doing isPage(node.callee)
.
messageId: 'page', | ||
node: node.callee, | ||
}) | ||
} |
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.
Go ahead and return at the end of this if statement, if it is a page method, no need to run parseFnCall
since it won't be a expect or test function
missing-playwright-await
rule #159This adds support for checking if
Page
methods are properly awaited, as part of themissing-playwright-await
rule.I've intentionally skipped the
waitForEvent
,waitForRequest
, andwaitForResponse
methods, as I believe these should be covered by a different lint rule or PR, since it is more complex: #199