Skip to content
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

feat(ct): react optional declaration merging hooks config #31055

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sand4rt
Copy link
Collaborator

@sand4rt sand4rt commented May 28, 2024

This comment has been minimized.

route?: string;
routing?: boolean;
declare module '@playwright/experimental-ct-react/hooks' {
interface RegisterHooksConfig {
Copy link
Contributor

Choose a reason for hiding this comment

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

We prefer to not override types globally in Playwright. Can we help the user in some other way? Perhaps by casting test exported from the package like const test = baseTest as SomeTestDeclaration<SpecificHooksConfig>? Or by extending with a mnt fixture that is mount<SpecificHooksConfig>?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We prefer to not override types globally in Playwright.

Normally i wouldn't use declare module in this way, but i think this is a good use case. Especially because the mount() is called so many times. The beforeMount<T>, afterMount<T>() and mount<T>() can also still be specified manually for the people who think it's too much magic.

Can we help the user in some other way?

I don't think there's another way to make the hooksConfig in beforeMount(), afterMount() and mount() automatically type-safe with a single type definition right? type-casting const test would solve a part of the problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there's another way to make the hooksConfig in beforeMount(), afterMount() and mount() automatically type-safe with a single type definition right? type-casting const test would solve a part of the problem.

That's right. However, you only write beforeMount() and afterMount() once, so explicitly typing them is not a big deal. It looks like the main goal is to avoid mount<T> every time.

@sand4rt sand4rt force-pushed the ct-react-declarationMerge-hooksConfig branch from d1447ef to a43d5d6 Compare June 6, 2024 17:36

This comment has been minimized.

Copy link
Contributor

github-actions bot commented Jun 6, 2024

Test results for "tests 1"

15 passed
✔️✔️✔️

Merge workflow run.

@sand4rt sand4rt marked this pull request as draft June 9, 2024 22:06
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.

None yet

2 participants