Skip to content

Commit

Permalink
Add ts-jest settings
Browse files Browse the repository at this point in the history
  • Loading branch information
HwangTaehyun committed Oct 3, 2022
1 parent 3809ffe commit 4cd1884
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 31 deletions.
8 changes: 4 additions & 4 deletions api/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { renderStatsCard } from "@/src/cards/stats-card";
import blacklist from "@/src/common/blacklist";
import {
clampValue,
CONSTANTS,
isLocaleAvailable,
parseArray,
parseBoolean,
renderError,
} from "@/index.js";
import renderStatsCard from "@/src/cards/stats-card";
import blacklist from "@/src/common/blacklist";
} from "@/src/common/utils";
import fetchStats from "@/src/fetchers/stats-fetcher";
import { isLocaleAvailable } from "@/src/translations";
import * as dotenv from "dotenv";
import express from "express";

Expand Down
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
presets: ["@babel/preset-env"],
};
14 changes: 13 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
export default {
transform: {
"^.+\\.[t|j]s$": [
"ts-jest",
{
useESM: true,
},
],
},
extensionsToTreatAsEsm: [".ts"],
clearMocks: true,
transform: {},
testEnvironment: "jsdom",
coverageProvider: "v8",
testPathIgnorePatterns: ["<rootDir>/node_modules/", "<rootDir>/tests/e2e/"],
Expand All @@ -9,4 +17,8 @@ export default {
"<rootDir>/node_modules/",
"<rootDir>/tests/E2E/",
],
moduleNameMapper: {
"^@/(.*)$": "<rootDir>/$1",
},
modulePaths: ["<rootDir>"],
};
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
"devDependencies": {
"@actions/core": "^1.9.1",
"@actions/github": "^4.0.0",
"@babel/core": "^7.19.3",
"@babel/preset-env": "^7.19.3",
"@testing-library/dom": "^8.17.1",
"@testing-library/jest-dom": "^5.16.5",
"@types/jest": "^29.1.1",
"@uppercod/css-to-object": "^1.1.1",
"axios-mock-adapter": "^1.18.1",
"babel-jest": "^29.1.2",
"color-contrast-checker": "^2.1.0",
"hjson": "^3.2.2",
"husky": "^4.2.5",
Expand All @@ -35,7 +39,9 @@
"lodash.snakecase": "^4.1.1",
"parse-diff": "^0.7.0",
"prettier": "^2.1.2",
"ts-jest": "^29.0.3",
"ts-loader": "^9.4.1",
"tsconfig-paths-jest": "^0.0.1",
"tsconfig-paths-webpack-plugin": "^4.0.0",
"typescript": "^4.8.4",
"webpack": "^5.74.0",
Expand All @@ -50,5 +56,9 @@
"upgrade": "^1.1.0",
"word-wrap": "^1.2.3"
},
"husky": {}
"husky": {
"hooks": {
"pre-commit": "npm test"
}
}
}
13 changes: 0 additions & 13 deletions src/calculateRank.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@ function normalcdf(mean, sigma, to) {
return (1 / 2) * (1 + sign * erf);
}

/**
* Calculates the users rank.
*
* @param {number} totalRepos
* @param {number} totalCommits
* @param {number} contributions
* @param {number} followers
* @param {number} prs
* @param {number} issues
* @param {number} stargazers
* @returns {{level: string, score: number}}} The users rank.
*/
function calculateRank({
totalRepos,
totalCommits,
Expand Down Expand Up @@ -97,4 +85,3 @@ function calculateRank({
}

export { calculateRank };
export default calculateRank;
1 change: 0 additions & 1 deletion src/cards/stats-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,3 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
};

export { renderStatsCard };
export default renderStatsCard;
14 changes: 7 additions & 7 deletions src/cards/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type CommonOptions = {
title_color: string;
icon_color: string;
text_color: string;
text_bold: boolean;
text_bold: boolean | string;
bg_color: string;
theme: ThemeNames;
border_radius: number;
Expand All @@ -14,15 +14,15 @@ export type CommonOptions = {

export type StatCardOptions = CommonOptions & {
hide: string[];
show_icons: boolean;
hide_title: boolean;
hide_border: boolean;
show_icons: boolean | string;
hide_title: boolean | string;
hide_border: boolean | string;
card_width: number;
hide_rank: boolean;
include_all_commits: boolean;
hide_rank: boolean | string;
include_all_commits: boolean | string;
line_height: number | string;
custom_title: string;
disable_animations: boolean;
disable_animations: boolean | string;
};

export type RepoCardOptions = CommonOptions & {
Expand Down
4 changes: 2 additions & 2 deletions src/fetchers/stats-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ const totalCommitsFetcher = async (username) => {

/**
* @param {string} username
* @param {boolean} count_private
* @param {boolean} include_all_commits
* @param {boolean | string} count_private
* @param {boolean | string} include_all_commits
* @returns {Promise<import("./types").StatsData>}
*/
async function fetchStats(
Expand Down
4 changes: 2 additions & 2 deletions tests/api.test.js → tests/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import api from "@/api/index";
import { jest } from "@jest/globals";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import api from "../api/index.js";
import { calculateRank } from "../src/calculateRank.js";
import { renderStatsCard } from "../src/cards/stats-card.js";
import { CONSTANTS, renderError } from "../src/common/utils.js";
Expand All @@ -13,7 +13,7 @@ const stats = {
totalIssues: 300,
totalPRs: 400,
contributedTo: 500,
rank: null,
rank: { level: "S+", score: 99.9 },
};
stats.rank = calculateRank({
totalCommits: stats.totalCommits,
Expand Down

0 comments on commit 4cd1884

Please sign in to comment.