/
githubmirror
/
github-readme-stats
Обзор
Документация
Войти
/
githubmirror
/
github-readme-stats
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
tests/bench/api.bench.js
78 строк
2 KB
Chongyi Zheng
tests: use custom benchmarking solution instead of outdated `jest-bench` package (#4468)
01 окт 2025, 22:20
Не верифицирован
01 окт 2025, 22:20
0d60641
Код
Авторство
О чём код?
import api from "../../api/index.js"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; import { it, jest } from "@jest/globals"; import { runAndLogStats } from "./utils.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: jest.fn(), send: jest.fn(), }; mock.onPost("https://api.github.com/graphql").replyOnce(200, data); return { req, res }; }; it("test /api", async () => { await runAndLogStats("test /api", async () => { const { req, res } = faker({}, data_stats); await api(req, res); }); });