Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken test #83

Merged
merged 2 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading