Feature/grs 1955 change commonjs imports (#1995)

* 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>
This commit is contained in:
rsk2andrickstaa authored and GitHub committed 2022-09-24 10:20:54 +02:00
1 parent 40735124ed
commit 107f7ca52c
49 files changed
+338 -475

No files matched your search

@@ -1,180 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Test Render Wakatime Card should render correctly 1`] = `
"
<svg
width=\\"495\\"
height=\\"150\\"
viewBox=\\"0 0 495 150\\"
fill=\\"none\\"
xmlns=\\"http://www.w3.org/2000/svg\\"
role=\\"img\\"
aria-labelledby=\\"descId\\"
>
<title id=\\"titleId\\"></title>
<desc id=\\"descId\\"></desc>
<style>
.header {
font: 600 18px 'Segoe UI', Ubuntu, Sans-Serif;
fill: #2f80ed;
animation: fadeInAnimation 0.8s ease-in-out forwards;
}
@supports(-moz-appearance: auto) {
/* Selector detects Firefox */
.header { font-size: 15.5px; }
}
.stat {
font: 600 14px 'Segoe UI', Ubuntu, \\"Helvetica Neue\\", Sans-Serif; fill: #434d58;
}
@supports(-moz-appearance: auto) {
/* Selector detects Firefox */
.stat { font-size:12px; }
}
.stagger {
opacity: 0;
animation: fadeInAnimation 0.3s ease-in-out forwards;
}
.rank-text {
font: 800 24px 'Segoe UI', Ubuntu, Sans-Serif; fill: #434d58;
animation: scaleInAnimation 0.3s ease-in-out forwards;
}
.not_bold { font-weight: 400 }
.bold { font-weight: 700 }
.icon {
fill: #4c71f2;
display: none;
}
.rank-circle-rim {
stroke: #2f80ed;
fill: none;
stroke-width: 6;
opacity: 0.2;
}
.rank-circle {
stroke: #2f80ed;
stroke-dasharray: 250;
fill: none;
stroke-width: 6;
stroke-linecap: round;
opacity: 0.8;
transform-origin: -10px 8px;
transform: rotate(-90deg);
animation: rankAnimation 1s forwards ease-in-out;
}
.lang-name { font: 400 11px 'Segoe UI', Ubuntu, Sans-Serif; fill: #434d58 }
</style>
<rect
data-testid=\\"card-bg\\"
x=\\"0.5\\"
y=\\"0.5\\"
rx=\\"4.5\\"
height=\\"99%\\"
stroke=\\"#e4e2e2\\"
width=\\"494\\"
fill=\\"#fffefe\\"
stroke-opacity=\\"1\\"
/>
<g
data-testid=\\"card-title\\"
transform=\\"translate(25, 35)\\"
>
<g transform=\\"translate(0, 0)\\">
<text
x=\\"0\\"
y=\\"0\\"
class=\\"header\\"
data-testid=\\"header\\"
>Wakatime Stats</text>
</g>
</g>
<g
data-testid=\\"main-card-body\\"
transform=\\"translate(0, 55)\\"
>
<svg x=\\"0\\" y=\\"0\\" width=\\"100%\\">
<g transform=\\"translate(0, 0)\\">
<g class=\\"stagger\\" style=\\"animation-delay: NaNms\\" transform=\\"translate(25, 0)\\">
<text class=\\"stat bold\\" y=\\"12.5\\" data-testid=\\"Other\\">Other:</text>
<text
class=\\"stat\\"
x=\\"350\\"
y=\\"12.5\\"
>19 mins</text>
<svg width=\\"220\\" x=\\"110\\" y=\\"4\\">
<rect rx=\\"5\\" ry=\\"5\\" x=\\"0\\" y=\\"0\\" width=\\"220\\" height=\\"8\\" fill=\\"#434d58\\"></rect>
<rect
height=\\"8\\"
fill=\\"#2f80ed\\"
rx=\\"5\\" ry=\\"5\\" x=\\"0\\" y=\\"0\\"
data-testid=\\"lang-progress\\"
width=\\"2%\\"
>
</rect>
</svg>
</g>
</g><g transform=\\"translate(0, 25)\\">
<g class=\\"stagger\\" style=\\"animation-delay: NaNms\\" transform=\\"translate(25, 0)\\">
<text class=\\"stat bold\\" y=\\"12.5\\" data-testid=\\"TypeScript\\">TypeScript:</text>
<text
class=\\"stat\\"
x=\\"350\\"
y=\\"12.5\\"
>1 min</text>
<svg width=\\"220\\" x=\\"110\\" y=\\"4\\">
<rect rx=\\"5\\" ry=\\"5\\" x=\\"0\\" y=\\"0\\" width=\\"220\\" height=\\"8\\" fill=\\"#434d58\\"></rect>
<rect
height=\\"8\\"
fill=\\"#2f80ed\\"
rx=\\"5\\" ry=\\"5\\" x=\\"0\\" y=\\"0\\"
data-testid=\\"lang-progress\\"
width=\\"2%\\"
>
</rect>
</svg>
</g>
</g>
</svg>
</g>
</svg>
"
`;
exports[`Test Render Wakatime Card should render correctly 1`] = `[Function]`;
exports[`Test Render Wakatime Card should render correctly with compact layout 1`] = `
"
<svg
width=\\"495\\"
height=\\"115\\"
viewBox=\\"0 0 495 115\\"
fill=\\"none\\"
xmlns=\\"http://www.w3.org/2000/svg\\"
role=\\"img\\"
aria-labelledby=\\"descId\\"
width="495"
height="115"
viewBox="0 0 495 115"
fill="none"
xmlns="http://www.w3.org/2000/svg"
role="img"
aria-labelledby="descId"
>
<title id=\\"titleId\\"></title>
<desc id=\\"descId\\"></desc>
<title id="titleId"></title>
<desc id="descId"></desc>
<style>
.header {
font: 600 18px 'Segoe UI', Ubuntu, Sans-Serif;
@@ -188,7 +28,7 @@ exports[`Test Render Wakatime Card should render correctly with compact layout 1
.stat {
font: 600 14px 'Segoe UI', Ubuntu, \\"Helvetica Neue\\", Sans-Serif; fill: #434d58;
font: 600 14px 'Segoe UI', Ubuntu, "Helvetica Neue", Sans-Serif; fill: #434d58;
}
@supports(-moz-appearance: auto) {
/* Selector detects Firefox */
@@ -199,7 +39,7 @@ exports[`Test Render Wakatime Card should render correctly with compact layout 1
animation: fadeInAnimation 0.3s ease-in-out forwards;
}
.rank-text {
font: 800 24px 'Segoe UI', Ubuntu, Sans-Serif; fill: #434d58;
font: 800 24px 'Segoe UI', Ubuntu, Sans-Serif; fill: #434d58;
animation: scaleInAnimation 0.3s ease-in-out forwards;
}
@@ -209,7 +49,7 @@ exports[`Test Render Wakatime Card should render correctly with compact layout 1
fill: #4c71f2;
display: none;
}
.rank-circle-rim {
stroke: #2f80ed;
fill: none;
@@ -239,75 +79,75 @@ exports[`Test Render Wakatime Card should render correctly with compact layout 1
<rect
data-testid=\\"card-bg\\"
x=\\"0.5\\"
y=\\"0.5\\"
rx=\\"4.5\\"
height=\\"99%\\"
stroke=\\"#e4e2e2\\"
width=\\"494\\"
fill=\\"#fffefe\\"
stroke-opacity=\\"1\\"
data-testid="card-bg"
x="0.5"
y="0.5"
rx="4.5"
height="99%"
stroke="#e4e2e2"
width="494"
fill="#fffefe"
stroke-opacity="1"
/>
<g
data-testid=\\"card-title\\"
transform=\\"translate(25, 35)\\"
data-testid="card-title"
transform="translate(25, 35)"
>
<g transform=\\"translate(0, 0)\\">
<g transform="translate(0, 0)">
<text
x=\\"0\\"
y=\\"0\\"
class=\\"header\\"
data-testid=\\"header\\"
x="0"
y="0"
class="header"
data-testid="header"
>Wakatime Stats</text>
</g>
</g>
<g
data-testid=\\"main-card-body\\"
transform=\\"translate(0, 55)\\"
data-testid="main-card-body"
transform="translate(0, 55)"
>
<svg x=\\"0\\" y=\\"0\\" width=\\"100%\\">
<svg x="0" y="0" width="100%">
<mask id=\\"rect-mask\\">
<rect x=\\"25\\" y=\\"0\\" width=\\"440\\" height=\\"8\\" fill=\\"white\\" rx=\\"5\\" />
<mask id="rect-mask">
<rect x="25" y="0" width="440" height="8" fill="white" rx="5" />
</mask>
<rect
mask=\\"url(#rect-mask)\\"
data-testid=\\"lang-progress\\"
x=\\"0\\"
y=\\"0\\"
width=\\"6.6495\\"
height=\\"8\\"
fill=\\"#858585\\"
mask="url(#rect-mask)"
data-testid="lang-progress"
x="0"
y="0"
width="6.6495"
height="8"
fill="#858585"
/>
<rect
mask=\\"url(#rect-mask)\\"
data-testid=\\"lang-progress\\"
x=\\"6.6495\\"
y=\\"0\\"
width=\\"0.465\\"
height=\\"8\\"
fill=\\"#2b7489\\"
mask="url(#rect-mask)"
data-testid="lang-progress"
x="6.6495"
y="0"
width="0.465"
height="8"
fill="#2b7489"
/>
<g transform=\\"translate(25, 25)\\">
<circle cx=\\"5\\" cy=\\"6\\" r=\\"5\\" fill=\\"#858585\\" />
<text data-testid=\\"lang-name\\" x=\\"15\\" y=\\"10\\" class='lang-name'>
<g transform="translate(25, 25)">
<circle cx="5" cy="6" r="5" fill="#858585" />
<text data-testid="lang-name" x="15" y="10" class='lang-name'>
Other - 19 mins
</text>
</g>
<g transform=\\"translate(230, 25)\\">
<circle cx=\\"5\\" cy=\\"6\\" r=\\"5\\" fill=\\"#2b7489\\" />
<text data-testid=\\"lang-name\\" x=\\"15\\" y=\\"10\\" class='lang-name'>
<g transform="translate(230, 25)">
<circle cx="5" cy="6" r="5" fill="#2b7489" />
<text data-testid="lang-name" x="15" y="10" class='lang-name'>
TypeScript - 1 min
</text>
</g>
+7 -7
View File
@@ -1,10 +1,10 @@
require("@testing-library/jest-dom");
const axios = require("axios");
const MockAdapter = require("axios-mock-adapter");
const api = require("../api/index");
const renderStatsCard = require("../src/cards/stats-card");
const { renderError, CONSTANTS } = require("../src/common/utils");
const calculateRank = require("../src/calculateRank");
import { jest } from "@jest/globals";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import api from "../api/index";
import calculateRank from "../src/calculateRank";
import renderStatsCard from "../src/cards/stats-card";
import { CONSTANTS, renderError } from "../src/common/utils";
const stats = {
name: "Anurag Hazra",
+2 -2
View File
@@ -1,5 +1,5 @@
require("@testing-library/jest-dom");
const calculateRank = require("../src/calculateRank");
import "@testing-library/jest-dom";
import calculateRank from "../src/calculateRank";
describe("Test calculateRank", () => {
it("should calculate rank correctly", () => {
+6 -6
View File
@@ -1,9 +1,9 @@
require("@testing-library/jest-dom");
const cssToObject = require("@uppercod/css-to-object").cssToObject;
const Card = require("../src/common/Card");
const icons = require("../src/common/icons");
const { getCardColors } = require("../src/common/utils");
const { queryByTestId } = require("@testing-library/dom");
import { queryByTestId } from "@testing-library/dom";
import "@testing-library/jest-dom";
import { cssToObject } from "@uppercod/css-to-object";
import Card from "../src/common/Card";
import icons from "../src/common/icons";
import { getCardColors } from "../src/common/utils";
describe("Card", () => {
it("should hide border", () => {
+4 -4
View File
@@ -1,7 +1,7 @@
require("@testing-library/jest-dom");
const axios = require("axios");
const MockAdapter = require("axios-mock-adapter");
const fetchRepo = require("../src/fetchers/repo-fetcher");
import "@testing-library/jest-dom";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import fetchRepo from "../src/fetchers/repo-fetcher";
const data_repo = {
repository: {
+6 -11
View File
@@ -1,8 +1,8 @@
require("@testing-library/jest-dom");
const axios = require("axios");
const MockAdapter = require("axios-mock-adapter");
const fetchStats = require("../src/fetchers/stats-fetcher");
const calculateRank = require("../src/calculateRank");
import "@testing-library/jest-dom";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import calculateRank from "../src/calculateRank";
import fetchStats from "../src/fetchers/stats-fetcher";
const data = {
data: {
@@ -141,12 +141,7 @@ describe("Test fetchStats", () => {
.onGet("https://api.github.com/search/commits?q=author:anuraghazra")
.reply(200, { total_count: 1000 });
let stats = await fetchStats(
"anuraghazra",
true,
true,
(exclude_repo = ["test-repo-1"]),
);
let stats = await fetchStats("anuraghazra", true, true, ["test-repo-1"]);
const rank = calculateRank({
totalCommits: 1050,
totalRepos: 5,
+5 -8
View File
@@ -1,7 +1,7 @@
require("@testing-library/jest-dom");
const axios = require("axios");
const MockAdapter = require("axios-mock-adapter");
const fetchTopLanguages = require("../src/fetchers/top-languages-fetcher");
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);
@@ -81,10 +81,7 @@ describe("FetchTopLanguages", () => {
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",
(exclude_repo = ["test-repo-1"]),
);
let repo = await fetchTopLanguages("anuraghazra", ["test-repo-1"]);
expect(repo).toStrictEqual({
HTML: {
color: "#0f0",
+16 -16
View File
@@ -1,7 +1,7 @@
require("@testing-library/jest-dom");
const axios = require("axios");
const MockAdapter = require("axios-mock-adapter");
const { fetchWakatimeStats } = require("../src/fetchers/wakatime-fetcher");
import "@testing-library/jest-dom";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import { fetchWakatimeStats } from "../src/fetchers/wakatime-fetcher";
const mock = new MockAdapter(axios);
afterEach(() => {
@@ -111,9 +111,9 @@ describe("Wakatime fetcher", () => {
const repo = await fetchWakatimeStats({ username });
expect(repo).toMatchInlineSnapshot(`
Object {
"categories": Array [
Object {
{
"categories": [
{
"digital": "22:40",
"hours": 22,
"minutes": 40,
@@ -127,8 +127,8 @@ describe("Wakatime fetcher", () => {
"daily_average_including_other_language": 16329,
"days_including_holidays": 7,
"days_minus_holidays": 5,
"editors": Array [
Object {
"editors": [
{
"digital": "22:40",
"hours": 22,
"minutes": 40,
@@ -150,8 +150,8 @@ describe("Wakatime fetcher", () => {
"is_other_usage_visible": true,
"is_stuck": false,
"is_up_to_date": true,
"languages": Array [
Object {
"languages": [
{
"digital": "0:19",
"hours": 0,
"minutes": 19,
@@ -160,7 +160,7 @@ describe("Wakatime fetcher", () => {
"text": "19 mins",
"total_seconds": 1170.434361,
},
Object {
{
"digital": "0:01",
"hours": 0,
"minutes": 1,
@@ -169,7 +169,7 @@ describe("Wakatime fetcher", () => {
"text": "1 min",
"total_seconds": 83.293809,
},
Object {
{
"digital": "0:00",
"hours": 0,
"minutes": 0,
@@ -179,8 +179,8 @@ describe("Wakatime fetcher", () => {
"total_seconds": 54.975151,
},
],
"operating_systems": Array [
Object {
"operating_systems": [
{
"digital": "22:40",
"hours": 22,
"minutes": 40,
@@ -212,4 +212,4 @@ describe("Wakatime fetcher", () => {
});
});
module.exports = { wakaTimeData };
export { wakaTimeData };
+1 -1
View File
@@ -1,4 +1,4 @@
const { flexLayout } = require("../src/common/utils");
import { flexLayout } from "../src/common/utils";
describe("flexLayout", () => {
it("should work with row & col layouts", () => {
+7 -6
View File
@@ -1,9 +1,10 @@
require("@testing-library/jest-dom");
const axios = require("axios");
const MockAdapter = require("axios-mock-adapter");
const pin = require("../api/pin");
const renderRepoCard = require("../src/cards/repo-card");
const { renderError } = require("../src/common/utils");
import { jest } from "@jest/globals";
import "@testing-library/jest-dom";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import pin from "../api/pin";
import renderRepoCard from "../src/cards/repo-card";
import { renderError } from "../src/common/utils";
const data_repo = {
repository: {
+5 -5
View File
@@ -1,9 +1,9 @@
require("@testing-library/jest-dom");
const cssToObject = require("@uppercod/css-to-object").cssToObject;
const renderRepoCard = require("../src/cards/repo-card");
import { queryByTestId } from "@testing-library/dom";
import "@testing-library/jest-dom";
import { cssToObject } from "@uppercod/css-to-object";
import renderRepoCard from "../src/cards/repo-card";
const { queryByTestId } = require("@testing-library/dom");
const themes = require("../themes");
import { themes } from "../themes";
const data_repo = {
repository: {
+9 -8
View File
@@ -1,13 +1,14 @@
require("@testing-library/jest-dom");
const cssToObject = require("@uppercod/css-to-object").cssToObject;
const renderStatsCard = require("../src/cards/stats-card");
const {
import {
getByTestId,
queryByTestId,
queryAllByTestId,
} = require("@testing-library/dom");
const themes = require("../themes");
queryByTestId,
} from "@testing-library/dom";
import { cssToObject } from "@uppercod/css-to-object";
import renderStatsCard from "../src/cards/stats-card";
// adds special assertions like toHaveTextContent
import "@testing-library/jest-dom";
import { themes } from "../themes";
describe("Test renderStatsCard", () => {
const stats = {
+13 -9
View File
@@ -1,9 +1,13 @@
require("@testing-library/jest-dom");
const cssToObject = require("@uppercod/css-to-object").cssToObject;
const renderTopLanguages = require("../src/cards/top-languages-card");
import { queryAllByTestId, queryByTestId } from "@testing-library/dom";
import { cssToObject } from "@uppercod/css-to-object";
import {
MIN_CARD_WIDTH,
renderTopLanguages,
} from "../src/cards/top-languages-card";
// adds special assertions like toHaveTextContent
import "@testing-library/jest-dom";
const { queryByTestId, queryAllByTestId } = require("@testing-library/dom");
const themes = require("../themes");
import { themes } from "../themes";
describe("Test renderTopLanguages", () => {
const langs = {
@@ -108,13 +112,13 @@ describe("Test renderTopLanguages", () => {
expect(document.querySelector("svg")).toHaveAttribute(
"width",
renderTopLanguages.MIN_CARD_WIDTH.toString(),
MIN_CARD_WIDTH.toString(),
);
document.body.innerHTML = renderTopLanguages(langs, { card_width: 100 });
expect(document.querySelector("svg")).toHaveAttribute(
"width",
renderTopLanguages.MIN_CARD_WIDTH.toString(),
MIN_CARD_WIDTH.toString(),
);
});
@@ -247,7 +251,7 @@ describe("Test renderTopLanguages", () => {
});
it("should render langs with specified langs_count", async () => {
options = {
const options = {
langs_count: 1,
};
document.body.innerHTML = renderTopLanguages(langs, { ...options });
@@ -257,7 +261,7 @@ describe("Test renderTopLanguages", () => {
});
it("should render langs with specified langs_count even when hide is set", async () => {
options = {
const options = {
hide: ["HTML"],
langs_count: 2,
};
+6 -7
View File
@@ -1,14 +1,13 @@
require("@testing-library/jest-dom");
const { queryByTestId } = require("@testing-library/dom");
const renderWakatimeCard = require("../src/cards/wakatime-card");
const { wakaTimeData } = require("./fetchWakatime.test");
import { queryByTestId } from "@testing-library/dom";
import "@testing-library/jest-dom";
import renderWakatimeCard from "../src/cards/wakatime-card";
import { getCardColors } from "../src/common/utils";
import { wakaTimeData } from "./fetchWakatime.test";
describe("Test Render Wakatime Card", () => {
it("should render correctly", () => {
const card = renderWakatimeCard(wakaTimeData.data);
expect(card).toMatchSnapshot();
expect(getCardColors).toMatchSnapshot();
});
it("should render correctly with compact layout", () => {
+4 -3
View File
@@ -1,6 +1,7 @@
require("@testing-library/jest-dom");
const retryer = require("../src/common/retryer");
const { logger } = require("../src/common/utils");
import { jest } from "@jest/globals";
import "@testing-library/jest-dom";
import retryer from "../src/common/retryer";
import { logger } from "../src/common/utils";
const fetcher = jest.fn((variables, token) => {
logger.log(variables, token);
+7 -6
View File
@@ -1,9 +1,10 @@
require("@testing-library/jest-dom");
const axios = require("axios");
const MockAdapter = require("axios-mock-adapter");
const topLangs = require("../api/top-langs");
const renderTopLanguages = require("../src/cards/top-languages-card");
const { renderError } = require("../src/common/utils");
import { jest } from "@jest/globals";
import "@testing-library/jest-dom";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import topLangs from "../api/top-langs";
import { renderTopLanguages } from "../src/cards/top-languages-card";
import { renderError } from "../src/common/utils";
const data_langs = {
data: {
+9 -9
View File
@@ -1,14 +1,12 @@
require("@testing-library/jest-dom");
const {
kFormatter,
import { queryByTestId } from "@testing-library/dom";
import "@testing-library/jest-dom";
import {
encodeHTML,
renderError,
flexLayout,
getCardColors,
kFormatter,
renderError,
wrapTextMultiline,
} = require("../src/common/utils");
const { queryByTestId } = require("@testing-library/dom");
} from "../src/common/utils";
describe("Test utils.js", () => {
it("should test kFormatter", () => {
@@ -32,7 +30,9 @@ describe("Test utils.js", () => {
expect(
queryByTestId(document.body, "message").children[0],
).toHaveTextContent(/Something went wrong/gim);
expect(queryByTestId(document.body, "message").children[1]).toBeEmpty(2);
expect(
queryByTestId(document.body, "message").children[1],
).toBeEmptyDOMElement(2);
// Secondary message
document.body.innerHTML = renderError(