Use `vitest` for backend tests: - `bench` script now uses [vitest's `bench`](https://vitest.dev/api/#bench) - e2e test fails with same error happening now with jest:`data-testid` attribute not present. vitest left, jest right <img width="1264" height="603" alt="image" src="https://github.com/user-attachments/assets/56fc43a6-e143-4208-bf14-7e016aae7fa9" />
83 lines
1.9 KiB
JavaScript
83 lines
1.9 KiB
JavaScript
import axios from "axios";
|
|
import MockAdapter from "axios-mock-adapter";
|
|
import { bench, describe, vi } from "vitest";
|
|
|
|
import api from "../../api-renamed/index.js";
|
|
|
|
const stats = {
|
|
name: "Anurag Hazra",
|
|
totalStars: 100,
|
|
totalCommits: 200,
|
|
totalIssues: 300,
|
|
totalPRs: 400,
|
|
totalPRsMerged: 320,
|
|
mergedPRsPercentage: 80,
|
|
totalReviews: 50,
|
|
totalDiscussionsStarted: 10,
|
|
totalDiscussionsAnswered: 40,
|
|
contributedTo: 50,
|
|
rank: null,
|
|
};
|
|
|
|
const data_stats = {
|
|
data: {
|
|
user: {
|
|
name: stats.name,
|
|
repositoriesContributedTo: { totalCount: stats.contributedTo },
|
|
commits: {
|
|
totalCommitContributions: stats.totalCommits,
|
|
},
|
|
reviews: {
|
|
totalPullRequestReviewContributions: stats.totalReviews,
|
|
},
|
|
pullRequests: { totalCount: stats.totalPRs },
|
|
mergedPullRequests: { totalCount: stats.totalPRsMerged },
|
|
openIssues: { totalCount: stats.totalIssues },
|
|
closedIssues: { totalCount: 0 },
|
|
followers: { totalCount: 0 },
|
|
repositoryDiscussions: { totalCount: stats.totalDiscussionsStarted },
|
|
repositoryDiscussionComments: {
|
|
totalCount: stats.totalDiscussionsAnswered,
|
|
},
|
|
repositories: {
|
|
totalCount: 1,
|
|
nodes: [{ stargazers: { totalCount: 100 } }],
|
|
pageInfo: {
|
|
hasNextPage: false,
|
|
endCursor: "cursor",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const mock = new MockAdapter(axios);
|
|
|
|
const faker = (query, data) => {
|
|
const req = {
|
|
query: {
|
|
username: "anuraghazra",
|
|
...query,
|
|
},
|
|
};
|
|
const res = {
|
|
setHeader: vi.fn(),
|
|
send: vi.fn(),
|
|
};
|
|
mock.onPost("https://api.github.com/graphql").replyOnce(200, data);
|
|
|
|
return { req, res };
|
|
};
|
|
|
|
describe("/api", () => {
|
|
bench(
|
|
"base",
|
|
async () => {
|
|
const { req, res } = faker({}, data_stats);
|
|
|
|
await api(req, res);
|
|
},
|
|
{ warmupIterations: 50 },
|
|
);
|
|
});
|