feat: setup tests env (#85)

This commit is contained in:
RustamRu 2025-02-15 19:45:37 +03:00
parent b2a067a644
commit 88242c5681
12 changed files with 15555 additions and 15263 deletions

View File

@ -0,0 +1,18 @@
import React, { PropsWithChildren } from 'react';
import { jest } from '@jest/globals';
import { BrowserRouter } from 'react-router-dom';
import { ChakraProvider, theme as chakraTheme } from '@chakra-ui/react';
import { Provider } from 'react-redux';
import ErrorBoundary from '../src/components/ErrorBoundary';
import { store } from '../src/__data__/store';
export const AppContext = jest.fn(({ children }: PropsWithChildren) => (
<Provider store={store}>
<ChakraProvider theme={chakraTheme}>
<ErrorBoundary>
<BrowserRouter>{children}</BrowserRouter>
</ErrorBoundary>
</ChakraProvider>
</Provider>
));

View File

@ -0,0 +1,18 @@
import { jest } from '@jest/globals';
jest.mock('@brojs/cli', () => ({
getConfigValue: jest.fn(() => '/api'),
getFeatures: jest.fn(() => ({
['order-view-status-polling']: { value: '3000' }
})),
getNavigationValue: jest.fn((navKey: string) => {
switch (navKey) {
case 'dry-wash.main':
return '/dry-wash';
case 'dry-wash.order.create':
return '/order';
case 'dry-wash.order.view':
return '/order/:orderId';
}
}),
}));

View File

@ -0,0 +1,6 @@
import { jest } from '@jest/globals';
import React from 'react';
jest.mock('@lottiefiles/react-lottie-player', () => ({
Player: jest.fn(() => <></>),
}));

View File

@ -1,9 +1,13 @@
import localeRu from '../locales/ru.json'; import localeRu from '../locales/ru.json';
module.exports = { module.exports = {
useTranslation: (_, { keyPrefix }) => { useTranslation: (_, options) => {
const { keyPrefix } = options ?? {};
return { return {
t: (key: string) => localeRu[`${keyPrefix}.${key}`], t: keyPrefix ? (key: string) => localeRu[`${keyPrefix}.${key}`] : undefined,
i18n: {
language: 'ru'
}
}; };
} }
}; };

View File

@ -0,0 +1,11 @@
import { jest } from '@jest/globals';
import React from 'react';
jest.mock('@pbe/react-yandex-maps', () => ({
YMaps: jest.fn(() => <></>),
Map: jest.fn(() => <></>),
Placemark: jest.fn(() => <></>),
GeolocationControl: jest.fn(() => <></>),
ZoomControl: jest.fn(() => <></>),
withYMaps: jest.fn(() => <></>),
}));

View File

@ -0,0 +1,20 @@
import { http, delay, HttpResponse } from 'msw';
import OrderPendingMock from '../../stubs/json/landing-order-view/id1-success-pending.json';
import OrderErrorMock from '../../stubs/json/landing-order-view/id1-error.json';
export const handlers = [
http.get('/api/order/:id', async ({ params }) => {
await delay();
const { id } = params;
if (id === 'id1') {
return HttpResponse.json(OrderPendingMock);
}
return new HttpResponse(null, {
status: 500,
statusText: OrderErrorMock.message
});
})
];

View File

@ -0,0 +1,5 @@
import { setupServer } from 'msw/node';
import { handlers } from './handlers';
export const server = setupServer(...handlers);

1
__mocks__/style-mock.ts Normal file
View File

@ -0,0 +1 @@
module.exports = {};

View File

@ -1,4 +1,5 @@
module.exports = { module.exports = {
preset: 'ts-jest',
transform: { transform: {
'^.+\\.tsx?$': 'babel-jest', '^.+\\.tsx?$': 'babel-jest',
}, },
@ -8,7 +9,8 @@ module.exports = {
collectCoverage: true, collectCoverage: true,
clearMocks: true, clearMocks: true,
moduleNameMapper: { moduleNameMapper: {
'\\.(svg|webp)$': '<rootDir>/__mocks__/file', '\\.(svg|webp)$': '<rootDir>/__mocks__/file-mock',
'\\.(css|scss)$': '<rootDir>/__mocks__/style-mock',
'react-i18next': '<rootDir>/__mocks__/react-i18next', 'react-i18next': '<rootDir>/__mocks__/react-i18next',
}, },
testEnvironmentOptions: { testEnvironmentOptions: {
@ -16,4 +18,5 @@ module.exports = {
}, },
testEnvironment: 'jest-fixed-jsdom', testEnvironment: 'jest-fixed-jsdom',
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/e2e'], testPathIgnorePatterns: ['/node_modules/', '<rootDir>/e2e'],
setupFilesAfterEnv: ['<rootDir>/jest-preset-it/jest.setup.js', '<rootDir>/__mocks__/brojs-cli-mock.ts', '<rootDir>/__mocks__/lottiefiles-mock.tsx'],
}; };

View File

@ -0,0 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-require-imports, no-undef
require('@testing-library/jest-dom');
// eslint-disable-next-line no-undef
global.__webpack_public_path__ = '';

30718
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -58,8 +58,11 @@
"@eslint/js": "^9.14.0", "@eslint/js": "^9.14.0",
"@playwright/test": "^1.50.1", "@playwright/test": "^1.50.1",
"@stylistic/eslint-plugin": "^2.10.1", "@stylistic/eslint-plugin": "^2.10.1",
"@testing-library/jest-dom": "^6.6.3",
"@types/jest": "^29.5.14",
"@types/node": "^22.13.1", "@types/node": "^22.13.1",
"@types/react-dom": "^18.3.1", "@types/react-dom": "^18.3.1",
"@types/testing-library__jest-dom": "^5.14.9",
"eslint": "^9.14.0", "eslint": "^9.14.0",
"eslint-plugin-import": "^2.31.0", "eslint-plugin-import": "^2.31.0",
"eslint-plugin-react": "^7.37.2", "eslint-plugin-react": "^7.37.2",