mirror of
https://github.com/anuraghazra/github-readme-stats.git
synced 2025-01-06 13:32:26 +08:00
107f7ca52c
* GRS-1955: Using ES6 import/export in src files * GRS-1955: Using ES6 import/export in test files * GRS-1955: Using ES6 import/export in themes index.js * GRS-1955: Readding blank line at end of top-languages-card.js * feat: fix test es6 import errors This commit makes sure jest is set-up to support es6. It also fixes several test errors and sorts the imports. * test: update test node version This commit makes sure node 16 is used in the github actions. * refactor: run prettier Co-authored-by: rickstaa <rick.staa@outlook.com>
107 lines
2.5 KiB
JavaScript
107 lines
2.5 KiB
JavaScript
import "@testing-library/jest-dom";
|
|
import axios from "axios";
|
|
import MockAdapter from "axios-mock-adapter";
|
|
import fetchTopLanguages from "../src/fetchers/top-languages-fetcher";
|
|
|
|
const mock = new MockAdapter(axios);
|
|
|
|
afterEach(() => {
|
|
mock.reset();
|
|
});
|
|
|
|
const data_langs = {
|
|
data: {
|
|
user: {
|
|
repositories: {
|
|
nodes: [
|
|
{
|
|
name: "test-repo-1",
|
|
languages: {
|
|
edges: [{ size: 100, node: { color: "#0f0", name: "HTML" } }],
|
|
},
|
|
},
|
|
{
|
|
name: "test-repo-2",
|
|
languages: {
|
|
edges: [{ size: 100, node: { color: "#0f0", name: "HTML" } }],
|
|
},
|
|
},
|
|
{
|
|
name: "test-repo-3",
|
|
languages: {
|
|
edges: [
|
|
{ size: 100, node: { color: "#0ff", name: "javascript" } },
|
|
],
|
|
},
|
|
},
|
|
{
|
|
name: "test-repo-4",
|
|
languages: {
|
|
edges: [
|
|
{ size: 100, node: { color: "#0ff", name: "javascript" } },
|
|
],
|
|
},
|
|
},
|
|
],
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const error = {
|
|
errors: [
|
|
{
|
|
type: "NOT_FOUND",
|
|
path: ["user"],
|
|
locations: [],
|
|
message: "Could not resolve to a User with the login of 'noname'.",
|
|
},
|
|
],
|
|
};
|
|
|
|
describe("FetchTopLanguages", () => {
|
|
it("should fetch correct language data", async () => {
|
|
mock.onPost("https://api.github.com/graphql").reply(200, data_langs);
|
|
|
|
let repo = await fetchTopLanguages("anuraghazra");
|
|
expect(repo).toStrictEqual({
|
|
HTML: {
|
|
color: "#0f0",
|
|
name: "HTML",
|
|
size: 200,
|
|
},
|
|
javascript: {
|
|
color: "#0ff",
|
|
name: "javascript",
|
|
size: 200,
|
|
},
|
|
});
|
|
});
|
|
|
|
it("should fetch correct language data while excluding the 'test-repo-1' repository", async () => {
|
|
mock.onPost("https://api.github.com/graphql").reply(200, data_langs);
|
|
|
|
let repo = await fetchTopLanguages("anuraghazra", ["test-repo-1"]);
|
|
expect(repo).toStrictEqual({
|
|
HTML: {
|
|
color: "#0f0",
|
|
name: "HTML",
|
|
size: 100,
|
|
},
|
|
javascript: {
|
|
color: "#0ff",
|
|
name: "javascript",
|
|
size: 200,
|
|
},
|
|
});
|
|
});
|
|
|
|
it("should throw error", async () => {
|
|
mock.onPost("https://api.github.com/graphql").reply(200, error);
|
|
|
|
await expect(fetchTopLanguages("anuraghazra")).rejects.toThrow(
|
|
"Could not resolve to a User with the login of 'noname'.",
|
|
);
|
|
});
|
|
});
|