Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions e2e/teardown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import dotenv from "dotenv";
import postgres from "postgres";

dotenv.config(); // Load .env file contents into process.env

export const teardown = async () => {
try {
if (!process.env.DATABASE_URL || !process.env.E2E_USER_ID)
throw new Error("Missing env variables for DB clean up script");
const db = postgres(process.env.DATABASE_URL as string);

// the test suit adds posts created by the E2E user. We want to remove them between test runs
await db`
DELETE FROM "Post" WHERE "userId" = ${process.env.E2E_USER_ID as string}
`;
// the test suit adds comments created by the E2E user. We want to remove them between test runs
await db`
DELETE FROM "Comment" WHERE "userId" = ${process.env.E2E_USER_ID as string}
`;

console.log("DB clean up successful");
} catch (err) {
console.log("Error while cleaning up DB after E2E test run", err);
}
};

export default teardown;
1 change: 1 addition & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { defineConfig, devices } from "@playwright/test";
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
globalTeardown: "./e2e/teardown.ts",
testDir: "e2e",
/* Run tests in files in parallel */
fullyParallel: true,
Expand Down
Loading