From 4516560bf30d00d71f468d4f9cbfc39b62d511fa Mon Sep 17 00:00:00 2001 From: Christopher Bellanger Date: Sat, 27 Jan 2024 18:44:56 +0100 Subject: [PATCH] Fix broken test (#83) * fix test * fix export --- app/utils/http.test.ts | 4 ++++ mocks/handlers.js | 14 +++++++------- mocks/index.js | 10 +++------- vitest.config.ts | 2 +- 4 files changed, 15 insertions(+), 15 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..776e844 100644 --- a/mocks/index.js +++ b/mocks/index.js @@ -1,15 +1,11 @@ -const { setupServer } = require("msw/node"); +import { setupServer } from "msw/node"; -const { handlers } = require("./handlers"); +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, -}; 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: {