Skip to content

Commit

Permalink
Fix broken test (#83)
Browse files Browse the repository at this point in the history
* fix test

* fix export
  • Loading branch information
cricrio authored Jan 27, 2024
1 parent 1e72b19 commit 4516560
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 4 additions & 0 deletions app/utils/http.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @vitest-environment happy-dom
*/

import {
isGet,
getCurrentPath,
Expand Down
14 changes: 7 additions & 7 deletions mocks/handlers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { rest } = require("msw");
import { http } from "msw";

const { USER_EMAIL, USER_ID, USER_PASSWORD } = require("./user");

Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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({})),
),
];

Expand Down
10 changes: 3 additions & 7 deletions mocks/index.js
Original file line number Diff line number Diff line change
@@ -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");

Check warning on line 8 in mocks/index.js

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

Unexpected console statement

process.once("SIGINT", () => server.close());
process.once("SIGTERM", () => server.close());

module.exports = {
server,
};
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 4516560

Please sign in to comment.