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

[Feature] Support for Typescript using keyword #27761

Closed
plushdohn opened this issue Oct 23, 2023 · 1 comment
Closed

[Feature] Support for Typescript using keyword #27761

plushdohn opened this issue Oct 23, 2023 · 1 comment

Comments

@plushdohn
Copy link

plushdohn commented Oct 23, 2023

I think supporting Typescript's new explicit resource management syntax out of the box would be a huge win for Playwright.

In full-stack apps that use Prisma or other ORMs it's very common to create temporary DB entries and removing them at the end of each test. This usually requires wrapping the whole test in a try/finally block, which is one of the main use-cases for using in TypeScript.

Here's a demo:

test('my test', async ({ page }) => {
  // Create a temporary DB entry just to set up the environment
  const post = await myDb.posts.create(/* */);

  try {
    // Test-related code
  } finally {
    // Delete entry at end of test
    await myDb.posts.delete(post.id);
  }
}

This would become:

test('my test', async ({ page }) => {
  await using post = await getTemporaryPost();
  
  // Test-related code

  // No need for cleaning up `using` takes care of it at the end of the scope
});

I would be happy to open a PR if you approve the feature!

@mxschmitt
Copy link
Member

Folding into #27141. Please upvote it there!

@mxschmitt mxschmitt closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2023
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

No branches or pull requests

2 participants