Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiodxa committed Jan 30, 2024
1 parent 758c4fb commit 1aca03a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/utils/schemas.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe } from "vitest";
import { describe, test, expect } from "vitest";
import { z } from "zod";

import { Schemas } from "./schemas";
Expand Down
21 changes: 9 additions & 12 deletions mocks/github.mock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "node:fs/promises";
import { resolve } from "node:path";

import { rest } from "msw";
import { HttpResponse, http } from "msw";
import { z } from "zod";

async function existsFile(path: string) {
Expand All @@ -14,23 +14,20 @@ async function existsFile(path: string) {
}

export let github = [
rest.get(
http.get(
"https://raw.githubusercontent.com/:owner/:repo/main/:path*",
async (req, res, ctx) => {
let { path } = z.object({ path: z.string().array() }).parse(req.params);
async (request) => {
let { path } = z
.object({ path: z.string().array() })
.parse(request.params);

if (!(await existsFile(path.join("/")))) {
return res(
ctx.status(404),
ctx.json({
message: "Not Found",
})
);
return HttpResponse.json({ message: "Not Found" }, { status: 404 });
}

let content = await fs.readFile(resolve(path.join("/")), "utf-8");

return res(ctx.status(200), ctx.text(content));
}
return HttpResponse.json(JSON.parse(content), { status: 200 });
},
),
];
6 changes: 3 additions & 3 deletions mocks/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { rest } from "msw";
import { http, passthrough } from "msw";
import { setupServer } from "msw/node";

import { github } from "./github.mock";

let misc = [
rest.get(/http:\/\/localhost:\d+\/.*/, async (req) => req.passthrough()),
rest.post(/http:\/\/localhost:\d+\/.*/, async (req) => req.passthrough()),
http.get(/http:\/\/localhost:\d+\/.*/, passthrough),
http.post(/http:\/\/localhost:\d+\/.*/, passthrough),
];

export const server = setupServer(...misc, ...github);
2 changes: 1 addition & 1 deletion vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { afterAll, afterEach, beforeAll } from "vitest";

import { server } from "./mocks";

import "@testing-library/jest-dom/extend-expect";
import "@testing-library/jest-dom";

dotenv.config({ override: true });

Expand Down

0 comments on commit 1aca03a

Please sign in to comment.