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

[Docs]: How to write isolated playwright tests against a real database #33699

Open
nodefir opened this issue Nov 20, 2024 · 0 comments
Open

[Docs]: How to write isolated playwright tests against a real database #33699

nodefir opened this issue Nov 20, 2024 · 0 comments

Comments

@nodefir
Copy link

nodefir commented Nov 20, 2024

Page(s)

https://playwright.dev/docs/next/browser-contexts

Description

When writing playwright tests against a local database (i.e. a postgres server with a database named your_app_test), there does not seem to be anywhere online that walks one through writing transactional tests that will not leak data during parallelization. All I have been able to come across is information on fixture data, but what about data created by the test itself?

I have gone down the rabbit hole of trying to recreate the seamless system testing (end-to-end testing) provided by Rails, which is able to spin up a test server and run tests in parallel without having to worry about data collisions.

Approaches I have tried thus far:

  • data truncation in before/after hooks
  • data truncation around await use() in fixtures
  • beginning and rolling back transactions around test (using beforeEach, afterEach, and then a fixture)
  • creating isolated databases using something like execSync(psql -c "CREATE DATABASE your_app_test_${env.process.TEST_WORKER_INDEX}; (doesn't work because env.process.TEST_WORKER_INDEX isn't available to the web server).
  • data truncation using a single worker (too slow to realistically be an option - but works)

How can I achieve a similar workflow to Rails system tests, where I can create data (directly in the test or by clicking around in my app) in a test database without worrying about other tests creating similar data? Is this out of scope for playwright?

For what it's worth, I am using prisma and Next.js.

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

1 participant