Mock database

Summary

  1. Create the .env.test file and put a different DATABASE_URL there, pointing at ./prisma/test.db.
    • ?connection_limit=1 is useful since SQLite locks the entire database during writes. This prevents race conditions in tests (one test tries to write to a db while it's locked due to a write from another test).
  2. Edit playwright.config.ts to add a new dotenv.configure() to load .env.test with overrides: true. This will point the test process to the correct env file.
  3. In playwright.config.ts, also set webServer.env (DATABASE_URL: process.env.DATABASE_URL) to use the correct test DB URL.
  4. Create playwright.setup.ts to (1) reset the test DB before the test run; (2) prepare the test database (generate client + apply the initial migrations).
  5. Edit playwright.config.ts to use the playwright.setup.ts as the globalSetup so Playwright knows when to run it.
  6. Run the existing tests (no test changes in this exercise). See the prisma/test.db written on disk. See how it persists after the test run to help with debugging. Open and show what's been created as a part of this test run.

Please set the playground first

Loading "Mock database"
Loading "Mock database"
Login to get access to the exclusive discord channel.