From 4634e258149769e89f62668db3e4f0c85956f717 Mon Sep 17 00:00:00 2001 From: Shrey Dadhaniya Date: Thu, 8 Feb 2024 23:50:55 +0530 Subject: [PATCH 1/6] feat: added test cases for seeds --- .env.sample | 1 + e2e/db.js | 39 ++++++++++++ e2e/routes/apps/todo.test.js | 5 ++ e2e/routes/seeds/chat-app.test.js | 22 +++++++ e2e/routes/seeds/ecommerce.test.js | 62 +++++++++++++++++++ .../seeds/generated-credentials.test.js | 25 ++++++++ e2e/routes/seeds/social-media.test.js | 41 ++++++++++++ e2e/routes/seeds/todo.test.js | 37 +++++++++++ e2e/test-server.js | 28 +-------- package.json | 2 +- playwright.config.js | 3 +- 11 files changed, 237 insertions(+), 28 deletions(-) create mode 100644 e2e/db.js create mode 100644 e2e/routes/seeds/chat-app.test.js create mode 100644 e2e/routes/seeds/ecommerce.test.js create mode 100644 e2e/routes/seeds/generated-credentials.test.js create mode 100644 e2e/routes/seeds/social-media.test.js create mode 100644 e2e/routes/seeds/todo.test.js diff --git a/.env.sample b/.env.sample index 949acb1f..cddd0574 100644 --- a/.env.sample +++ b/.env.sample @@ -1,5 +1,6 @@ # ################# REQUIRED ENV VARS START ################# PORT=8080 +MONGODB_PORT=10000 # mongodb port for e2e testing MONGODB_URI=mongodb://mongodb:27017 # `mongodb://localhost:27017` in case using local mongodb NODE_ENV=development # changing this will avoid stack traces in the error response EXPRESS_SESSION_SECRET=7fdOMCFRSLD9cv1k-5n3Dz5n3DmVmVHVIg9GG_OGTUkBfLNdgZAwKDNtoCJ0X0cyqaM0ogR80-zh9kx0Mkx # ok to change diff --git a/e2e/db.js b/e2e/db.js new file mode 100644 index 00000000..154b9d7e --- /dev/null +++ b/e2e/db.js @@ -0,0 +1,39 @@ +import mongoose, { mongo } from "mongoose"; +import { MongoMemoryServer } from "mongodb-memory-server"; + +let mongoServer = null; +let dbInstance = undefined; +let MONGO_PORT = process.env.MONGODB_PORT || 10000; +let MONGO_URL = `mongodb://127.0.0.1:${MONGO_PORT}/`; + +const connectDB = async () => { + try { + await mongoose.disconnect(); + mongoServer = await MongoMemoryServer.create({ + instance: { + port: +MONGO_PORT, + }, + }); + dbInstance = await mongoose.connect(MONGO_URL); + } catch (error) { + console.log("Mongo db connect error: ", error); + process.exit(1); + } +}; +export const clearDB = async (collectionName = null) => { + if (!dbInstance) { + dbInstance = await mongoose.connect(MONGO_URL); + } + const connection = mongoose.connection; + if (collectionName) { + await connection.db.collection(collectionName).deleteMany({}); + } else { + const collections = await connection.db.listCollections().toArray(); + const collectionNames = collections.map((col) => col.name); + for (let name of collectionNames) { + await connection.db.collection(name).deleteMany({}); + } + } +}; + +export default connectDB; diff --git a/e2e/routes/apps/todo.test.js b/e2e/routes/apps/todo.test.js index 2f660c02..c4cfbd7a 100644 --- a/e2e/routes/apps/todo.test.js +++ b/e2e/routes/apps/todo.test.js @@ -1,5 +1,6 @@ import { test, expect } from "@playwright/test"; import { getApiContext } from "../../common.js"; +import { clearDB } from "../../db.js"; let apiContext; let todoId = null; @@ -7,6 +8,7 @@ let todoId = null; test.describe("Todo App", () => { test.beforeAll(async ({ playwright }) => { apiContext = await getApiContext(playwright); + await clearDB(); }); test.afterAll(async ({}) => { await apiContext.dispose(); @@ -27,6 +29,9 @@ test.describe("Todo App", () => { title: "test-todo-title", description: "test-todo-description", }; + const _res = await apiContext.post(`/api/v1/todos`, { + data: todo, + }); const res = await apiContext.post(`/api/v1/todos`, { data: todo, }); diff --git a/e2e/routes/seeds/chat-app.test.js b/e2e/routes/seeds/chat-app.test.js new file mode 100644 index 00000000..c96a1a38 --- /dev/null +++ b/e2e/routes/seeds/chat-app.test.js @@ -0,0 +1,22 @@ +import { test, expect } from "@playwright/test"; +import { getApiContext } from "../../common.js"; +import { clearDB } from "../../db.js"; + +let apiContext; + +test.describe("Seed Chat App", () => { + test.beforeAll(async ({ playwright }) => { + apiContext = await getApiContext(playwright); + await clearDB(); + }); + test.afterAll(async ({}) => { + await apiContext.dispose(); + }); + + test.describe("POST:/api/v1/seed/chat-app - Seed Chat", async () => { + test("should seed Chat App DB", async ({ page }) => { + const res = await apiContext.post(`/api/v1/seed/chat-app`); + expect(res.status()).toEqual(201); + }); + }); +}); diff --git a/e2e/routes/seeds/ecommerce.test.js b/e2e/routes/seeds/ecommerce.test.js new file mode 100644 index 00000000..85e866f1 --- /dev/null +++ b/e2e/routes/seeds/ecommerce.test.js @@ -0,0 +1,62 @@ +import { test, expect } from "@playwright/test"; +import { getApiContext } from "../../common.js"; +import { clearDB } from "../../db.js"; +import { + CATEGORIES_COUNT, + PRODUCTS_COUNT, +} from "../../../src/seeds/_constants.js"; + +let apiContext; + +test.describe("Seed Ecommerce App", () => { + test.beforeAll(async ({ playwright }) => { + apiContext = await getApiContext(playwright); + await clearDB(); + }); + test.afterAll(async ({}) => { + await apiContext.dispose(); + }); + + test.describe("POST:/api/v1/seed/ecommerce - Seed Ecommerce", async () => { + test("should return 0 products before seed", async ({ page }) => { + const res = await apiContext.get( + `/api/v1/ecommerce/products?page=1&limit=1` + ); + const json = await res.json(); + expect(res.status()).toEqual(200); + expect(json.data.totalProducts).toEqual(0); + }); + test("should return 0 categories before seed", async ({ page }) => { + const res = await apiContext.get( + `/api/v1/ecommerce/categories?page=1&limit=1` + ); + const json = await res.json(); + expect(res.status()).toEqual(200); + expect(json.data.totalCategories).toEqual(0); + }); + test("should seed ecommerce DB", async ({ page }) => { + const res = await apiContext.post(`/api/v1/seed/ecommerce`); + expect(res.status()).toEqual(201); + }); + test(`should return ${PRODUCTS_COUNT} products after seed`, async ({ + page, + }) => { + const res = await apiContext.get( + `/api/v1/ecommerce/products?page=1&limit=1` + ); + const json = await res.json(); + expect(res.status()).toEqual(200); + expect(json.data.totalProducts).toEqual(PRODUCTS_COUNT); + }); + test(`should return ${CATEGORIES_COUNT} categories after seed`, async ({ + page, + }) => { + const res = await apiContext.get( + `/api/v1/ecommerce/categories?page=1&limit=1` + ); + const json = await res.json(); + expect(res.status()).toEqual(200); + expect(json.data.totalCategories).toEqual(CATEGORIES_COUNT); + }); + }); +}); diff --git a/e2e/routes/seeds/generated-credentials.test.js b/e2e/routes/seeds/generated-credentials.test.js new file mode 100644 index 00000000..3c72e281 --- /dev/null +++ b/e2e/routes/seeds/generated-credentials.test.js @@ -0,0 +1,25 @@ +import { test, expect } from "@playwright/test"; +import seedCredentials from "../../../public/temp/seed-credentials.json" assert { type: "json" }; +import { getApiContext } from "../../common.js"; + +let apiContext; + +test.describe("Get credentials", () => { + test.beforeAll(async ({ playwright }) => { + apiContext = await getApiContext(playwright); + }); + test.afterAll(async ({}) => { + await apiContext.dispose(); + }); + + test.describe("GET:/api/v1/seed/generated-credentials - Get credentials", async () => { + test("should return public/temp/seed-credentials.json content", async ({ + page, + }) => { + const res = await apiContext.get(`/api/v1/seed/generated-credentials`); + const json = await res.json(); + expect(res.status()).toEqual(200); + expect(json.data).toMatchObject(seedCredentials); + }); + }); +}); diff --git a/e2e/routes/seeds/social-media.test.js b/e2e/routes/seeds/social-media.test.js new file mode 100644 index 00000000..0c8b6b6d --- /dev/null +++ b/e2e/routes/seeds/social-media.test.js @@ -0,0 +1,41 @@ +import { test, expect } from "@playwright/test"; +import { getApiContext } from "../../common.js"; +import { clearDB } from "../../db.js"; +import { SOCIAL_POSTS_COUNT } from "../../../src/seeds/_constants.js"; + +let apiContext; + +test.describe("Seed social-media App", () => { + test.beforeAll(async ({ playwright }) => { + apiContext = await getApiContext(playwright); + await clearDB(); + }); + test.afterAll(async ({}) => { + await apiContext.dispose(); + }); + + test.describe("POST:/api/v1/seed/social-media - Seed social-media", async () => { + test("should return 0 posts before seed", async ({ page }) => { + const res = await apiContext.get( + `/api/v1/social-media/posts?page=1&limit=1` + ); + const json = await res.json(); + expect(res.status()).toEqual(200); + expect(json.data.totalPosts).toEqual(0); + }); + test("should seed social-media DB", async ({ page }) => { + const res = await apiContext.post(`/api/v1/seed/social-media`); + expect(res.status()).toEqual(201); + }); + test(`should return ${SOCIAL_POSTS_COUNT} post after seed`, async ({ + page, + }) => { + const res = await apiContext.get( + `/api/v1/social-media/posts?page=1&limit=1` + ); + const json = await res.json(); + expect(res.status()).toEqual(200); + expect(json.data.totalPosts).toEqual(SOCIAL_POSTS_COUNT); + }); + }); +}); diff --git a/e2e/routes/seeds/todo.test.js b/e2e/routes/seeds/todo.test.js new file mode 100644 index 00000000..12ac4fec --- /dev/null +++ b/e2e/routes/seeds/todo.test.js @@ -0,0 +1,37 @@ +import { test, expect } from "@playwright/test"; +import { getApiContext } from "../../common.js"; +import { clearDB } from "../../db.js"; +import { TODOS_COUNT } from "../../../src/seeds/_constants.js"; + +let apiContext; + +test.describe("Seed Todo App", () => { + test.beforeAll(async ({ playwright }) => { + apiContext = await getApiContext(playwright); + await clearDB(); + }); + test.afterAll(async ({}) => { + await apiContext.dispose(); + }); + + test.describe("POST:/api/v1/seed/todos - Seed Todos", async () => { + test("should return 0 todos before seed", async ({ page }) => { + const res = await apiContext.get(`/api/v1/todos`); + const json = await res.json(); + expect(res.status()).toEqual(200); + expect(json.data.length).toEqual(0); + }); + + test("should seed todo DB", async ({ page }) => { + const res = await apiContext.post(`/api/v1/seed/todos`); + expect(res.status()).toEqual(201); + }); + + test(`should return ${TODOS_COUNT} todos after seed`, async ({ page }) => { + const res = await apiContext.get(`/api/v1/todos`); + const json = await res.json(); + expect(res.status()).toEqual(200); + expect(json.data.length).toEqual(TODOS_COUNT); + }); + }); +}); diff --git a/e2e/test-server.js b/e2e/test-server.js index c6609b5a..02f8e8da 100644 --- a/e2e/test-server.js +++ b/e2e/test-server.js @@ -1,36 +1,12 @@ import dotenv from "dotenv"; -import mongoose from "mongoose"; -import { MongoMemoryServer } from "mongodb-memory-server"; -import { httpServer } from "../src/app.js"; - dotenv.config({ path: "../.env", }); +import { httpServer } from "../src/app.js"; +import connectDB from "./db.js"; -let mongoServer = null; -let dbInstance = undefined; const PORT = process.env.PORT || 8080; -const connectDB = async () => { - try { - await mongoose.disconnect(); - mongoServer = await MongoMemoryServer.create(); - dbInstance = await mongoose.connect(`${mongoServer.getUri()}`); - await clearDB(); - } catch (error) { - console.log("Mongo db connect error: ", error); - process.exit(1); - } -}; -export const clearDB = async () => { - const collections = mongoose.connection.collections; - - for (const key in collections) { - const collection = collections[key]; - await collection.deleteMany({}); - } -}; - /** * Starting from Node.js v14 top-level await is available and it is only available in ES modules. * This means you can not use it with common js modules or Node version < 14. diff --git a/package.json b/package.json index 529dd2ea..35192d79 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "pre-commit": "lint-staged", "prepare": "node prepare.js", "start:test-server": "node -r dotenv/config --experimental-json-modules e2e/test-server.js", - "test:playwright": "set NODE_OPTIONS=--experimental-vm-modules && npx playwright test" + "test:playwright": "SET NODE_OPTIONS=--experimental-vm-modules -r dotenv/config --experimental-json-modules && npx playwright test" }, "repository": { "type": "git", diff --git a/playwright.config.js b/playwright.config.js index 1e5f667d..89f0297d 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -19,7 +19,8 @@ export default defineConfig({ /* Retry on CI only */ retries: process.env.CI ? 2 : 0, /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, + // using multiple workers will create DB overwrite issue because we use one DB to test everything + workers: 1, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ reporter: "html", /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ From 043147d8e66d853dffb2ff061bf610f1eb15b17d Mon Sep 17 00:00:00 2001 From: Shrey Dadhaniya Date: Fri, 9 Feb 2024 20:57:19 +0530 Subject: [PATCH 2/6] refactor: convert ` to " and revert apps/todo.test.js --- e2e/routes/apps/todo.test.js | 3 --- e2e/routes/seeds/chat-app.test.js | 2 +- e2e/routes/seeds/ecommerce.test.js | 10 +++++----- e2e/routes/seeds/generated-credentials.test.js | 2 +- e2e/routes/seeds/social-media.test.js | 6 +++--- e2e/routes/seeds/todo.test.js | 6 +++--- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/e2e/routes/apps/todo.test.js b/e2e/routes/apps/todo.test.js index c4cfbd7a..37e383ce 100644 --- a/e2e/routes/apps/todo.test.js +++ b/e2e/routes/apps/todo.test.js @@ -29,9 +29,6 @@ test.describe("Todo App", () => { title: "test-todo-title", description: "test-todo-description", }; - const _res = await apiContext.post(`/api/v1/todos`, { - data: todo, - }); const res = await apiContext.post(`/api/v1/todos`, { data: todo, }); diff --git a/e2e/routes/seeds/chat-app.test.js b/e2e/routes/seeds/chat-app.test.js index c96a1a38..75e67186 100644 --- a/e2e/routes/seeds/chat-app.test.js +++ b/e2e/routes/seeds/chat-app.test.js @@ -15,7 +15,7 @@ test.describe("Seed Chat App", () => { test.describe("POST:/api/v1/seed/chat-app - Seed Chat", async () => { test("should seed Chat App DB", async ({ page }) => { - const res = await apiContext.post(`/api/v1/seed/chat-app`); + const res = await apiContext.post("/api/v1/seed/chat-app"); expect(res.status()).toEqual(201); }); }); diff --git a/e2e/routes/seeds/ecommerce.test.js b/e2e/routes/seeds/ecommerce.test.js index 85e866f1..d3d81643 100644 --- a/e2e/routes/seeds/ecommerce.test.js +++ b/e2e/routes/seeds/ecommerce.test.js @@ -20,7 +20,7 @@ test.describe("Seed Ecommerce App", () => { test.describe("POST:/api/v1/seed/ecommerce - Seed Ecommerce", async () => { test("should return 0 products before seed", async ({ page }) => { const res = await apiContext.get( - `/api/v1/ecommerce/products?page=1&limit=1` + "/api/v1/ecommerce/products?page=1&limit=1" ); const json = await res.json(); expect(res.status()).toEqual(200); @@ -28,21 +28,21 @@ test.describe("Seed Ecommerce App", () => { }); test("should return 0 categories before seed", async ({ page }) => { const res = await apiContext.get( - `/api/v1/ecommerce/categories?page=1&limit=1` + "/api/v1/ecommerce/categories?page=1&limit=1" ); const json = await res.json(); expect(res.status()).toEqual(200); expect(json.data.totalCategories).toEqual(0); }); test("should seed ecommerce DB", async ({ page }) => { - const res = await apiContext.post(`/api/v1/seed/ecommerce`); + const res = await apiContext.post("/api/v1/seed/ecommerce"); expect(res.status()).toEqual(201); }); test(`should return ${PRODUCTS_COUNT} products after seed`, async ({ page, }) => { const res = await apiContext.get( - `/api/v1/ecommerce/products?page=1&limit=1` + "/api/v1/ecommerce/products?page=1&limit=1" ); const json = await res.json(); expect(res.status()).toEqual(200); @@ -52,7 +52,7 @@ test.describe("Seed Ecommerce App", () => { page, }) => { const res = await apiContext.get( - `/api/v1/ecommerce/categories?page=1&limit=1` + "/api/v1/ecommerce/categories?page=1&limit=1" ); const json = await res.json(); expect(res.status()).toEqual(200); diff --git a/e2e/routes/seeds/generated-credentials.test.js b/e2e/routes/seeds/generated-credentials.test.js index 3c72e281..63bb4602 100644 --- a/e2e/routes/seeds/generated-credentials.test.js +++ b/e2e/routes/seeds/generated-credentials.test.js @@ -16,7 +16,7 @@ test.describe("Get credentials", () => { test("should return public/temp/seed-credentials.json content", async ({ page, }) => { - const res = await apiContext.get(`/api/v1/seed/generated-credentials`); + const res = await apiContext.get("/api/v1/seed/generated-credentials"); const json = await res.json(); expect(res.status()).toEqual(200); expect(json.data).toMatchObject(seedCredentials); diff --git a/e2e/routes/seeds/social-media.test.js b/e2e/routes/seeds/social-media.test.js index 0c8b6b6d..97bcb449 100644 --- a/e2e/routes/seeds/social-media.test.js +++ b/e2e/routes/seeds/social-media.test.js @@ -17,21 +17,21 @@ test.describe("Seed social-media App", () => { test.describe("POST:/api/v1/seed/social-media - Seed social-media", async () => { test("should return 0 posts before seed", async ({ page }) => { const res = await apiContext.get( - `/api/v1/social-media/posts?page=1&limit=1` + "/api/v1/social-media/posts?page=1&limit=1" ); const json = await res.json(); expect(res.status()).toEqual(200); expect(json.data.totalPosts).toEqual(0); }); test("should seed social-media DB", async ({ page }) => { - const res = await apiContext.post(`/api/v1/seed/social-media`); + const res = await apiContext.post("/api/v1/seed/social-media"); expect(res.status()).toEqual(201); }); test(`should return ${SOCIAL_POSTS_COUNT} post after seed`, async ({ page, }) => { const res = await apiContext.get( - `/api/v1/social-media/posts?page=1&limit=1` + "/api/v1/social-media/posts?page=1&limit=1" ); const json = await res.json(); expect(res.status()).toEqual(200); diff --git a/e2e/routes/seeds/todo.test.js b/e2e/routes/seeds/todo.test.js index 12ac4fec..6be1a3ca 100644 --- a/e2e/routes/seeds/todo.test.js +++ b/e2e/routes/seeds/todo.test.js @@ -16,19 +16,19 @@ test.describe("Seed Todo App", () => { test.describe("POST:/api/v1/seed/todos - Seed Todos", async () => { test("should return 0 todos before seed", async ({ page }) => { - const res = await apiContext.get(`/api/v1/todos`); + const res = await apiContext.get("/api/v1/todos"); const json = await res.json(); expect(res.status()).toEqual(200); expect(json.data.length).toEqual(0); }); test("should seed todo DB", async ({ page }) => { - const res = await apiContext.post(`/api/v1/seed/todos`); + const res = await apiContext.post("/api/v1/seed/todos"); expect(res.status()).toEqual(201); }); test(`should return ${TODOS_COUNT} todos after seed`, async ({ page }) => { - const res = await apiContext.get(`/api/v1/todos`); + const res = await apiContext.get("/api/v1/todos"); const json = await res.json(); expect(res.status()).toEqual(200); expect(json.data.length).toEqual(TODOS_COUNT); From 3619cbbeb78820540d44755ba45c8d4adce85760 Mon Sep 17 00:00:00 2001 From: Shrey Dadhaniya Date: Fri, 9 Feb 2024 21:08:07 +0530 Subject: [PATCH 3/6] refactor: change variable names and use error log --- e2e/db.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/e2e/db.js b/e2e/db.js index 154b9d7e..47b6a8b3 100644 --- a/e2e/db.js +++ b/e2e/db.js @@ -3,26 +3,26 @@ import { MongoMemoryServer } from "mongodb-memory-server"; let mongoServer = null; let dbInstance = undefined; -let MONGO_PORT = process.env.MONGODB_PORT || 10000; -let MONGO_URL = `mongodb://127.0.0.1:${MONGO_PORT}/`; +let MONGODB_PORT = process.env.MONGODB_PORT || 10000; +let MONGODB_URL = `mongodb://127.0.0.1:${MONGODB_PORT}/`; const connectDB = async () => { try { await mongoose.disconnect(); mongoServer = await MongoMemoryServer.create({ instance: { - port: +MONGO_PORT, + port: +MONGODB_PORT, }, }); - dbInstance = await mongoose.connect(MONGO_URL); + dbInstance = await mongoose.connect(MONGODB_URL); } catch (error) { - console.log("Mongo db connect error: ", error); + console.error("Mongo db connect error: ", error); process.exit(1); } }; export const clearDB = async (collectionName = null) => { if (!dbInstance) { - dbInstance = await mongoose.connect(MONGO_URL); + dbInstance = await mongoose.connect(MONGODB_URL); } const connection = mongoose.connection; if (collectionName) { From 2f3a14f869590223d0543a303127fc2aad3d4656 Mon Sep 17 00:00:00 2001 From: Shrey Dadhaniya Date: Fri, 9 Feb 2024 23:32:53 +0530 Subject: [PATCH 4/6] refactor: change env variable name and update db.js --- .env.sample | 2 +- e2e/db.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.env.sample b/.env.sample index cddd0574..1a639931 100644 --- a/.env.sample +++ b/.env.sample @@ -1,6 +1,6 @@ # ################# REQUIRED ENV VARS START ################# PORT=8080 -MONGODB_PORT=10000 # mongodb port for e2e testing +MONGO_MEMORY_SERVER_PORT=10000 # mongodb port for e2e testing MONGODB_URI=mongodb://mongodb:27017 # `mongodb://localhost:27017` in case using local mongodb NODE_ENV=development # changing this will avoid stack traces in the error response EXPRESS_SESSION_SECRET=7fdOMCFRSLD9cv1k-5n3Dz5n3DmVmVHVIg9GG_OGTUkBfLNdgZAwKDNtoCJ0X0cyqaM0ogR80-zh9kx0Mkx # ok to change diff --git a/e2e/db.js b/e2e/db.js index 47b6a8b3..fd83b7e7 100644 --- a/e2e/db.js +++ b/e2e/db.js @@ -1,17 +1,18 @@ import mongoose, { mongo } from "mongoose"; import { MongoMemoryServer } from "mongodb-memory-server"; +const MONGO_MEMORY_SERVER_PORT = process.env.MONGO_MEMORY_SERVER_PORT || 10000; +const MONGODB_URL = `mongodb://127.0.0.1:${MONGO_MEMORY_SERVER_PORT}/`; + let mongoServer = null; let dbInstance = undefined; -let MONGODB_PORT = process.env.MONGODB_PORT || 10000; -let MONGODB_URL = `mongodb://127.0.0.1:${MONGODB_PORT}/`; const connectDB = async () => { try { await mongoose.disconnect(); mongoServer = await MongoMemoryServer.create({ instance: { - port: +MONGODB_PORT, + port: +MONGO_MEMORY_SERVER_PORT, }, }); dbInstance = await mongoose.connect(MONGODB_URL); From d86f61f10714bdab280c78c0adfad467e8b3e329 Mon Sep 17 00:00:00 2001 From: Shrey Dadhaniya Date: Sat, 10 Feb 2024 00:06:33 +0530 Subject: [PATCH 5/6] refactor: change SET to set in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 35192d79..8cb2ba37 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "pre-commit": "lint-staged", "prepare": "node prepare.js", "start:test-server": "node -r dotenv/config --experimental-json-modules e2e/test-server.js", - "test:playwright": "SET NODE_OPTIONS=--experimental-vm-modules -r dotenv/config --experimental-json-modules && npx playwright test" + "test:playwright": "set NODE_OPTIONS=--experimental-vm-modules -r dotenv/config --experimental-json-modules && npx playwright test" }, "repository": { "type": "git", From b4559372cf4a782b6cf10aa12e5e042c169bf79b Mon Sep 17 00:00:00 2001 From: Shrey Dadhaniya Date: Mon, 12 Feb 2024 20:57:33 +0530 Subject: [PATCH 6/6] refactor: change import file logic in generated-credentials --- e2e/routes/seeds/generated-credentials.test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/e2e/routes/seeds/generated-credentials.test.js b/e2e/routes/seeds/generated-credentials.test.js index 63bb4602..988287ac 100644 --- a/e2e/routes/seeds/generated-credentials.test.js +++ b/e2e/routes/seeds/generated-credentials.test.js @@ -1,5 +1,5 @@ +import fs from "fs"; import { test, expect } from "@playwright/test"; -import seedCredentials from "../../../public/temp/seed-credentials.json" assert { type: "json" }; import { getApiContext } from "../../common.js"; let apiContext; @@ -16,6 +16,11 @@ test.describe("Get credentials", () => { test("should return public/temp/seed-credentials.json content", async ({ page, }) => { + const seedCredentialsText = fs.readFileSync( + "./public/temp/seed-credentials.json", + "utf8" + ); + const seedCredentials = JSON.parse(seedCredentialsText); const res = await apiContext.get("/api/v1/seed/generated-credentials"); const json = await res.json(); expect(res.status()).toEqual(200);