Skip to content

#377 - Automatically support test and expect aliases with variable references #386

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

MSroczynski3
Copy link
Contributor

The list of changes in this PR:

  • Add new function getImportedAliases to the src/utils/ast.ts that gets and resolves importedAliases. The function is heavy guarded against various runtime erros.
  • Extended resolveToPlaywrightFn to use getImportedAliases.
  • Added various tests for test and expect aliases.
  • Added tests for src/utils/ast.ts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test isn't really helpful, let's remove it.

* For example, for `import { test as foo } from '@playwright/test'`,
* `getImportedAliases(context, 'test')` will return `['foo']`.
*/
export function getImportedAliases(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't tell the full story. What if for example you want to do this:

const custom = test.extend()

which is very common in Playwright. With this method, that wouldn't be caught.

We shouldn't just use AST parsing, we should find any test import, and then track all of it's references including .extend assignments, and then those are the valid aliases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants