diff --git a/jest.config.js b/jest.config.js index 722fe38b..c01c4169 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,7 +3,7 @@ module.exports = { moduleFileExtensions: ['js', 'json', 'ts', 'tsx'], rootDir: '.', transform: { - '^.+\\.[jt]sx?$': 'ts-jest', + '^.+\\.[jt]sx?$': ['ts-jest', {tsconfig: './tsconfig.test.json'}], }, transformIgnorePatterns: ['node_modules/(?!(@gravity-ui|tinygesture)/)'], coverageDirectory: './coverage', diff --git a/src/blocks/Feed/Feed.tsx b/src/blocks/Feed/Feed.tsx index f617c344..1d96d522 100644 --- a/src/blocks/Feed/Feed.tsx +++ b/src/blocks/Feed/Feed.tsx @@ -15,7 +15,7 @@ import {RouterContext} from '../../contexts/RouterContext'; /** * @deprecated Metrika will be deleted after launch of analyticsEvents */ -import metrika from '../../counters/metrika.js'; +import metrika from '../../counters/metrika'; import {MetrikaCounter} from '../../counters/utils'; import {FeedProps} from '../../models/blocks'; import {DefaultEventNames, FetchArgs, HandleChangeQueryParams} from '../../models/common'; diff --git a/src/components/FeedHeader/components/Controls/Controls.tsx b/src/components/FeedHeader/components/Controls/Controls.tsx index 46a917a0..d845fce9 100644 --- a/src/components/FeedHeader/components/Controls/Controls.tsx +++ b/src/components/FeedHeader/components/Controls/Controls.tsx @@ -8,7 +8,7 @@ import {Button, Icon, Select} from '@gravity-ui/uikit'; */ import {BlogMetrikaGoalIds} from '../../../../constants'; import {LikesContext} from '../../../../contexts/LikesContext'; -import metrika from '../../../../counters/metrika.js'; +import metrika from '../../../../counters/metrika'; import {MetrikaCounter} from '../../../../counters/utils'; import {Keyset, i18} from '../../../../i18n'; import {Save} from '../../../../icons/Save'; diff --git a/src/components/Paginator/Paginator.tsx b/src/components/Paginator/Paginator.tsx index cb45789d..a5ad95ff 100644 --- a/src/components/Paginator/Paginator.tsx +++ b/src/components/Paginator/Paginator.tsx @@ -6,7 +6,7 @@ import {BlogMetrikaGoalIds} from '../../constants'; /** * @deprecated Metrika will be deleted after launch of analyticsEvents */ -import metrika from '../../counters/metrika.js'; +import metrika from '../../counters/metrika'; import {MetrikaCounter} from '../../counters/utils'; import {DefaultEventNames} from '../../models/common'; import {block} from '../../utils/cn'; diff --git a/src/components/PostInfo/components/Save.tsx b/src/components/PostInfo/components/Save.tsx index 9b8a5e8b..18fe6007 100644 --- a/src/components/PostInfo/components/Save.tsx +++ b/src/components/PostInfo/components/Save.tsx @@ -4,7 +4,7 @@ import {useAnalytics} from '@gravity-ui/page-constructor'; import {Icon} from '@gravity-ui/uikit'; import {LikesContext} from '../../../contexts/LikesContext'; -import metrika from '../../../counters/metrika.js'; +import metrika from '../../../counters/metrika'; import {MetrikaCounter} from '../../../counters/utils'; import {Save as SaveIcon} from '../../../icons/Save'; import {SaveFilled} from '../../../icons/SaveFilled'; diff --git a/src/components/PostInfo/components/Sharing.tsx b/src/components/PostInfo/components/Sharing.tsx index f6ea653c..f1b90317 100644 --- a/src/components/PostInfo/components/Sharing.tsx +++ b/src/components/PostInfo/components/Sharing.tsx @@ -6,7 +6,7 @@ import {useAnalytics} from '@gravity-ui/page-constructor'; import {MobileContext} from '../../../contexts/MobileContext'; import {PostPageContext} from '../../../contexts/PostPageContext'; import {RouterContext} from '../../../contexts/RouterContext'; -import metrika from '../../../counters/metrika.js'; +import metrika from '../../../counters/metrika'; import {MetrikaCounter} from '../../../counters/utils'; import {Keyset, i18} from '../../../i18n'; import {ShareArrowUp} from '../../../icons/ShareArrowUp'; diff --git a/src/counters/metrika.js b/src/counters/metrika.ts similarity index 78% rename from src/counters/metrika.js rename to src/counters/metrika.ts index a6a9210a..8d3ea720 100644 --- a/src/counters/metrika.js +++ b/src/counters/metrika.ts @@ -37,21 +37,23 @@ const Goal = { const HIT_COUNTERS = ['main', 'cross-site', 'scale']; -const counterIds = {}; +const counterIds: Record = {}; -function getCounter(name) { +function getCounter(name: string) { const counterId = counterIds[name]; - return window['yaCounter' + counterId]; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return (window as unknown as Record)['yaCounter' + counterId]; } -export function initCounters(configs) { +export function initCounters(configs: Record[]) { configs.forEach((config) => { counterIds[config.name] = config.id; }); } -function hit(...args) { +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function hit(...args: any[]) { HIT_COUNTERS.forEach((counterName) => { const counter = getCounter(counterName); @@ -63,7 +65,8 @@ function hit(...args) { }); } -function params(...args) { +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function params(...args: Record[]) { const counter = getCounter('main'); if (!counter) { @@ -73,7 +76,8 @@ function params(...args) { counter.params(...args); } -function reachGoal(counterName, ...args) { +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function reachGoal(counterName: string, ...args: any[]) { const counter = getCounter(counterName); if (!counter) { @@ -83,7 +87,7 @@ function reachGoal(counterName, ...args) { counter.reachGoal(...args); } -function reachGoals(goals, counterName = 'main') { +function reachGoals(goals: string | object, counterName = 'main') { if (!goals) { return; } @@ -100,7 +104,7 @@ function reachGoals(goals, counterName = 'main') { } // eslint-disable-next-line complexity -function getServicePrefix(id) { +function getServicePrefix(id: string) { switch (id) { case 'compute': return 'CMPT'; @@ -149,39 +153,39 @@ function getServicePrefix(id) { return undefined; } -function getMarketPlacePrefix(id) { +function getMarketPlacePrefix(id: string) { return `product_${id}_`; } -function goalGoToConsole(prefix) { +function goalGoToConsole(prefix: string) { return prefix && `${prefix}GOTOCONSOLE`; } -function goalGoToForm(prefix) { +function goalGoToForm(prefix: string) { return prefix && `${prefix}GOTOFORM`; } -function goalGoToDocs(prefix) { +function goalGoToDocs(prefix: string) { return prefix && `${prefix}GOTODOCS`; } -function goalFormSubmit(prefix) { +function goalFormSubmit(prefix: string) { return prefix && `${prefix}FORMSUBMIT`; } -function goalEventFormSubmit(id) { +function goalEventFormSubmit(id: string) { return `event${id || 's'}_form_submit`; } -function goalEventVideoAction(id, action) { +function goalEventVideoAction(id: string, action: string) { return `event${id}_video_${action}`; } -function goalCaseFormSubmit(id) { +function goalCaseFormSubmit(id: string) { return `case${id ? `_${id}` : 's'}_form_submit`; } -function goalSwitchLang(place) { +function goalSwitchLang(place: string) { return `SWITCH_LANG_${place}`; } diff --git a/tsconfig.test.json b/tsconfig.test.json new file mode 100644 index 00000000..a24195dd --- /dev/null +++ b/tsconfig.test.json @@ -0,0 +1,8 @@ +{ + "extends": "@gravity-ui/tsconfig", + "compilerOptions": { + "resolveJsonModule": true, + "module": "CommonJS", + "jsx": "react" + } +}