You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
instead of running your Next.js server as a webServer, start it in the worker fixture from the guide above;
make sure your Next.js server creates a unique database in this setup;
you might want to override baseURL fixture to use the freshly launched server's address;
teardown your Next.js server in the fixture cleanup.
This will ensure that tests running in one worker will talk to its own server instance that will connect to its own database. Let me know what you think.
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:
await use()
in fixturesbeforeEach
,afterEach
, and then a fixture)psql -c "CREATE DATABASE your_app_test_${env.process.TEST_WORKER_INDEX};
(doesn't work becauseenv.process.TEST_WORKER_INDEX
isn't available to the web server).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.
The text was updated successfully, but these errors were encountered: