Skip to content

Commit cee4687

Browse files
committed
chore: added teardown script
1 parent 77aa243 commit cee4687

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

e2e/teardown.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import dotenv from "dotenv";
2+
import postgres from "postgres";
3+
4+
dotenv.config(); // Load .env file contents into process.env
5+
6+
export const teardown = async () => {
7+
try {
8+
if (!process.env.DATABASE_URL || !process.env.E2E_USER_ID)
9+
throw new Error("Missing env variables for DB clean up script");
10+
const db = postgres(process.env.DATABASE_URL as string);
11+
12+
// the test suit adds posts created by the E2E user. We want to remove them between test runs
13+
await db`
14+
DELETE FROM "Post" WHERE "userId" = ${process.env.E2E_USER_ID as string}
15+
`;
16+
// the test suit adds comments created by the E2E user. We want to remove them between test runs
17+
await db`
18+
DELETE FROM "Comment" WHERE "userId" = ${process.env.E2E_USER_ID as string}
19+
`;
20+
21+
console.log("DB clean up successful");
22+
} catch (err) {
23+
console.log("Error while cleaning up DB after E2E test run", err);
24+
}
25+
};
26+
27+
export default teardown;

playwright.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { defineConfig, devices } from "@playwright/test";
1010
* See https://playwright.dev/docs/test-configuration.
1111
*/
1212
export default defineConfig({
13+
globalTeardown: "./e2e/teardown.ts",
1314
testDir: "e2e",
1415
/* Run tests in files in parallel */
1516
fullyParallel: true,

0 commit comments

Comments
 (0)