mirror of
https://github.com/System-End/github-readme-stats.git
synced 2026-04-19 19:55:16 +00:00
76 lines
1.8 KiB
JavaScript
76 lines
1.8 KiB
JavaScript
import { benchmarkSuite } from "jest-bench";
|
|
import api from "../../api/index.js";
|
|
import axios from "axios";
|
|
import MockAdapter from "axios-mock-adapter";
|
|
import { jest } from "@jest/globals";
|
|
|
|
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 },
|
|
contributionsCollection: {
|
|
totalCommitContributions: stats.totalCommits,
|
|
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: jest.fn(),
|
|
send: jest.fn(),
|
|
};
|
|
mock.onPost("https://api.github.com/graphql").replyOnce(200, data);
|
|
|
|
return { req, res };
|
|
};
|
|
|
|
benchmarkSuite("test /api", {
|
|
["simple request"]: async () => {
|
|
const { req, res } = faker({}, data_stats);
|
|
|
|
await api(req, res);
|
|
},
|
|
});
|