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__ = '';

198
package-lock.json generated
View File

@ -50,8 +50,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",
@ -61,6 +64,13 @@
"typescript-eslint": "^8.12.2" "typescript-eslint": "^8.12.2"
} }
}, },
"node_modules/@adobe/css-tools": {
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.4.2.tgz",
"integrity": "sha512-baYZExFpsdkBNuvGKTKWCwKH57HRZLVtycZS05WTQNVOiXVSeAki3nU35zlRbToeMW8aHlJfyS+1C4BOv27q0A==",
"dev": true,
"license": "MIT"
},
"node_modules/@ampproject/remapping": { "node_modules/@ampproject/remapping": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz",
@ -3815,6 +3825,77 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/@testing-library/jest-dom": {
"version": "6.6.3",
"resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-6.6.3.tgz",
"integrity": "sha512-IteBhl4XqYNkM54f4ejhLRJiZNqcSCoXUOG2CPK7qbD322KjQozM4kHQOfkG2oln9b9HTYqs+Sae8vBATubxxA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@adobe/css-tools": "^4.4.0",
"aria-query": "^5.0.0",
"chalk": "^3.0.0",
"css.escape": "^1.5.1",
"dom-accessibility-api": "^0.6.3",
"lodash": "^4.17.21",
"redent": "^3.0.0"
},
"engines": {
"node": ">=14",
"npm": ">=6",
"yarn": ">=1"
}
},
"node_modules/@testing-library/jest-dom/node_modules/ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"license": "MIT",
"dependencies": {
"color-convert": "^2.0.1"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
"node_modules/@testing-library/jest-dom/node_modules/chalk": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz",
"integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==",
"dev": true,
"license": "MIT",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@testing-library/jest-dom/node_modules/dom-accessibility-api": {
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.6.3.tgz",
"integrity": "sha512-7ZgogeTnjuHbo+ct10G9Ffp0mif17idi0IyWNVA/wcwcm7NPOD/WEHVP3n7n3MhXqxoIYm8d6MuZohYWIZ4T3w==",
"dev": true,
"license": "MIT"
},
"node_modules/@testing-library/jest-dom/node_modules/supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"license": "MIT",
"dependencies": {
"has-flag": "^4.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@testing-library/react": { "node_modules/@testing-library/react": {
"version": "16.2.0", "version": "16.2.0",
"resolved": "https://registry.npmjs.org/@testing-library/react/-/react-16.2.0.tgz", "resolved": "https://registry.npmjs.org/@testing-library/react/-/react-16.2.0.tgz",
@ -3977,6 +4058,52 @@
"@types/istanbul-lib-report": "*" "@types/istanbul-lib-report": "*"
} }
}, },
"node_modules/@types/jest": {
"version": "29.5.14",
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.14.tgz",
"integrity": "sha512-ZN+4sdnLUbo8EVvVc2ao0GFW6oVrQRPn4K2lglySj7APvSrgzxHiNNK99us4WDMi57xxA2yggblIAMNhXOotLQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"expect": "^29.0.0",
"pretty-format": "^29.0.0"
}
},
"node_modules/@types/jest/node_modules/ansi-styles": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz",
"integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
"node_modules/@types/jest/node_modules/pretty-format": {
"version": "29.7.0",
"resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz",
"integrity": "sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@jest/schemas": "^29.6.3",
"ansi-styles": "^5.0.0",
"react-is": "^18.0.0"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
}
},
"node_modules/@types/jest/node_modules/react-is": {
"version": "18.3.1",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz",
"integrity": "sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/jsdom": { "node_modules/@types/jsdom": {
"version": "20.0.1", "version": "20.0.1",
"resolved": "https://registry.npmjs.org/@types/jsdom/-/jsdom-20.0.1.tgz", "resolved": "https://registry.npmjs.org/@types/jsdom/-/jsdom-20.0.1.tgz",
@ -4065,6 +4192,16 @@
"resolved": "https://registry.npmjs.org/@types/statuses/-/statuses-2.0.5.tgz", "resolved": "https://registry.npmjs.org/@types/statuses/-/statuses-2.0.5.tgz",
"integrity": "sha512-jmIUGWrAiwu3dZpxntxieC+1n/5c3mjrImkmOSQ2NC5uP6cYO4aAZDdSmRcI5C1oiTmqlZGHC+/NmJrKogbP5A==" "integrity": "sha512-jmIUGWrAiwu3dZpxntxieC+1n/5c3mjrImkmOSQ2NC5uP6cYO4aAZDdSmRcI5C1oiTmqlZGHC+/NmJrKogbP5A=="
}, },
"node_modules/@types/testing-library__jest-dom": {
"version": "5.14.9",
"resolved": "https://registry.npmjs.org/@types/testing-library__jest-dom/-/testing-library__jest-dom-5.14.9.tgz",
"integrity": "sha512-FSYhIjFlfOpGSRyVoMBMuS3ws5ehFQODymf3vlI7U1K8c7PHwWwFY7VREfmsuzHSOnoKs/9/Y983ayOs7eRzqw==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/jest": "*"
}
},
"node_modules/@types/tough-cookie": { "node_modules/@types/tough-cookie": {
"version": "4.0.5", "version": "4.0.5",
"resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.5.tgz", "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.5.tgz",
@ -5945,6 +6082,13 @@
"node": ">=10" "node": ">=10"
} }
}, },
"node_modules/css.escape": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/css.escape/-/css.escape-1.5.1.tgz",
"integrity": "sha512-YUifsXXuknHlUsmlgyY0PKzgPOr7/FjCePfHNt0jxm83wHZi44VDMQ7/fGNkjY3/jV1MC+1CmZbaHzugyeRtpg==",
"dev": true,
"license": "MIT"
},
"node_modules/cssesc": { "node_modules/cssesc": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz", "resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz",
@ -8674,6 +8818,16 @@
"node": ">=0.8.19" "node": ">=0.8.19"
} }
}, },
"node_modules/indent-string": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz",
"integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/inflight": { "node_modules/inflight": {
"version": "1.0.6", "version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
@ -11255,6 +11409,13 @@
"url": "https://github.com/sponsors/sindresorhus" "url": "https://github.com/sponsors/sindresorhus"
} }
}, },
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"dev": true,
"license": "MIT"
},
"node_modules/lodash.debounce": { "node_modules/lodash.debounce": {
"version": "4.0.8", "version": "4.0.8",
"resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz",
@ -11445,6 +11606,16 @@
"node": ">=6" "node": ">=6"
} }
}, },
"node_modules/min-indent": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz",
"integrity": "sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=4"
}
},
"node_modules/minimatch": { "node_modules/minimatch": {
"version": "9.0.5", "version": "9.0.5",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz",
@ -12999,6 +13170,20 @@
"recursive-watch": "bin.js" "recursive-watch": "bin.js"
} }
}, },
"node_modules/redent": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz",
"integrity": "sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg==",
"dev": true,
"license": "MIT",
"dependencies": {
"indent-string": "^4.0.0",
"strip-indent": "^3.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/redux": { "node_modules/redux": {
"version": "5.0.1", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/redux/-/redux-5.0.1.tgz", "resolved": "https://registry.npmjs.org/redux/-/redux-5.0.1.tgz",
@ -13803,6 +13988,19 @@
"node": ">=6" "node": ">=6"
} }
}, },
"node_modules/strip-indent": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-3.0.0.tgz",
"integrity": "sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"min-indent": "^1.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/strip-json-comments": { "node_modules/strip-json-comments": {
"version": "3.1.1", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz",

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",