Skip to content

Commit

Permalink
chore: added teardown script (#1162)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnAllenTech authored Oct 21, 2024
1 parent cffa5e3 commit 62b1847
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
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

0 comments on commit 62b1847

Please sign in to comment.