From 3323453bdbac764ec6daa52d493ad2e8d868e477 Mon Sep 17 00:00:00 2001 From: Christopher Bellanger Date: Fri, 26 Jan 2024 20:34:21 +0100 Subject: [PATCH 1/2] fix test --- app/utils/http.test.ts | 4 ++++ mocks/handlers.js | 14 +++++++------- mocks/index.js | 4 ++-- vitest.config.ts | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/utils/http.test.ts b/app/utils/http.test.ts index 7dd881d..6bc8486 100644 --- a/app/utils/http.test.ts +++ b/app/utils/http.test.ts @@ -1,3 +1,7 @@ +/** + * @vitest-environment happy-dom + */ + import { isGet, getCurrentPath, diff --git a/mocks/handlers.js b/mocks/handlers.js index 65d390b..038cdff 100644 --- a/mocks/handlers.js +++ b/mocks/handlers.js @@ -1,4 +1,4 @@ -const { rest } = require("msw"); +import { http } from "msw"; const { USER_EMAIL, USER_ID, USER_PASSWORD } = require("./user"); @@ -29,7 +29,7 @@ const SUPABASE_AUTH_USER_API = "/auth/v1/user"; const SUPABASE_AUTH_ADMIN_USER_API = "/auth/v1/admin/users"; const handlers = [ - rest.post( + http.post( `${SUPABASE_URL}${SUPABASE_AUTH_TOKEN_API}`, async (req, res, ctx) => { const { email, password, refresh_token } = await req.json(); @@ -51,7 +51,7 @@ const handlers = [ return res(ctx.status(200), ctx.json(supabaseAuthSession)); }, ), - rest.get( + http.get( `${SUPABASE_URL}${SUPABASE_AUTH_USER_API}`, async (req, res, ctx) => { const token = req.headers @@ -66,13 +66,13 @@ const handlers = [ return res(ctx.status(200), ctx.json({ id: USER_ID })); }, ), - rest.post( + http.post( `${SUPABASE_URL}${SUPABASE_AUTH_ADMIN_USER_API}`, - async (req, res, ctx) => res(ctx.status(200), ctx.json(authAccount)), + async (_, res, ctx) => res(ctx.status(200), ctx.json(authAccount)), ), - rest.delete( + http.delete( `${SUPABASE_URL}${SUPABASE_AUTH_ADMIN_USER_API}/*`, - async (req, res, ctx) => res(ctx.status(200), ctx.json({})), + async (_, res, ctx) => res(ctx.status(200), ctx.json({})), ), ]; diff --git a/mocks/index.js b/mocks/index.js index 5442a18..1b65f35 100644 --- a/mocks/index.js +++ b/mocks/index.js @@ -1,6 +1,6 @@ -const { setupServer } = require("msw/node"); +import { setupServer } from "msw/node"; -const { handlers } = require("./handlers"); +import { handlers } from "./handlers"; const server = setupServer(...handlers); diff --git a/vitest.config.ts b/vitest.config.ts index 36d4e79..3cb46a5 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -9,7 +9,7 @@ export default defineConfig({ test: { globals: true, environment: "happy-dom", - // setupFiles: ["./test/setup-test-env.ts"], DISABLED because I have not had the time to upgrade MSW mocks + setupFiles: ["./test/setup-test-env.ts"], includeSource: ["app/**/*.{js,ts}"], exclude: ["node_modules", "mocks/**/*.{js,ts}"], coverage: { From 98f69c723fc852d6b8e4da7e9d771d1be5f593fb Mon Sep 17 00:00:00 2001 From: Christopher Bellanger Date: Fri, 26 Jan 2024 20:40:50 +0100 Subject: [PATCH 2/2] fix export --- mocks/index.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/mocks/index.js b/mocks/index.js index 1b65f35..776e844 100644 --- a/mocks/index.js +++ b/mocks/index.js @@ -2,14 +2,10 @@ import { setupServer } from "msw/node"; import { handlers } from "./handlers"; -const server = setupServer(...handlers); +export const server = setupServer(...handlers); server.listen({ onUnhandledRequest: "bypass" }); console.info("🔶 Mock server running"); process.once("SIGINT", () => server.close()); process.once("SIGTERM", () => server.close()); - -module.exports = { - server, -};