Skip to content

Commit

Permalink
test: fix first run speed (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
niktverd authored Nov 9, 2023
1 parent 79cb2c2 commit ee58f65
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/Feed/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/components/FeedHeader/components/Controls/Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Paginator/Paginator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/components/PostInfo/components/Save.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/components/PostInfo/components/Sharing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
40 changes: 22 additions & 18 deletions src/counters/metrika.js → src/counters/metrika.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,23 @@ const Goal = {

const HIT_COUNTERS = ['main', 'cross-site', 'scale'];

const counterIds = {};
const counterIds: Record<string, string> = {};

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<string, any>)['yaCounter' + counterId];
}

export function initCounters(configs) {
export function initCounters(configs: Record<string, string>[]) {
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);

Expand All @@ -63,7 +65,8 @@ function hit(...args) {
});
}

function params(...args) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function params(...args: Record<string, any>[]) {
const counter = getCounter('main');

if (!counter) {
Expand All @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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';
Expand Down Expand Up @@ -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}`;
}

Expand Down
8 changes: 8 additions & 0 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@gravity-ui/tsconfig",
"compilerOptions": {
"resolveJsonModule": true,
"module": "CommonJS",
"jsx": "react"
}
}

0 comments on commit ee58f65

Please sign in to comment.