Open GrayedFox opened 1 month ago
I think what would be best is to simply add support for member expressions (e.g. agent.seesAnything
in assertFunctionNames
. Let's stick to a single setting, and not support regex right now.
Using assertFunctionNames
is tedious and leaves us open to, by mistake, listing a function that does not in fact contain a expect statement
Would it be possible to automatically detect when a helper function contains a expect statement?
test('something', async ({ page }) => {
await helperFunction(page);
});
async function helperFunction(page: Page) {
await expect(page.locator('div')).toBeVisible(); // All good, there's a expect statement
}
@maxime-dupuis I really like that idea a lot. It won't be perfect semantic analysis (e.g. if you import a helper, it won't work), but could be really nice for the majority of single file uses.
Pretty much an extension of this issue.
We use a sort of scrappy version of the Screenplay pattern, basically just an abstract base class for common testing logic and child classes for each user bucket. Thus many of our assertions live inside a class method:
Thus from inside the spec it looks like:
I tried specifying the allowed methods like this but that didn't work and the rule still reported an error:
I could probably work around this by assigning the class methods like so (untested):
What would help our use case and keep our code clean is if we could specify a further property of the eslint rule that, rather than looking for an exact function name or call signature, simply checks that the method name matches a specific character sequence:
This rule would enable functions in any form and in any call/execution context to work so long as the name and location logic match, the advantage being that it is agnostic about where the function/method comes from. For example the above config would allow for:
Shorthand could default match logic to contains:
I'm flexible on the schema - if there's a more eslint/PlayWright friendly way to structure the rule options then happy with that, mainly concerned about the logic.
If this sounds like an acceptable suggestion and in line with the plugin I would be happy to open a PR that adds it in due time 👍🏽