feat(frontend): add jest
This commit is contained in:
parent
10c0e5cf7c
commit
9cb8c376dd
1
frontend/__mocks__/jest/fileMock.js
Normal file
1
frontend/__mocks__/jest/fileMock.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
module.exports = 'test-file-stub';
|
||||||
3
frontend/__mocks__/jest/server.ts
Normal file
3
frontend/__mocks__/jest/server.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import { setupServer } from 'msw/node';
|
||||||
|
|
||||||
|
export const server = setupServer();
|
||||||
19
frontend/__mocks__/jest/wrappers/ReactQueryWrapper.tsx
Normal file
19
frontend/__mocks__/jest/wrappers/ReactQueryWrapper.tsx
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||||
|
|
||||||
|
import type { PropsWithChildren } from 'react';
|
||||||
|
|
||||||
|
export const createReactQueryWrapper = () => {
|
||||||
|
const queryClient = new QueryClient({
|
||||||
|
defaultOptions: {
|
||||||
|
queries: {
|
||||||
|
retry: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return ({ children }: PropsWithChildren) => (
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
|
{children}
|
||||||
|
</QueryClientProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
1
frontend/__mocks__/jest/wrappers/index.ts
Normal file
1
frontend/__mocks__/jest/wrappers/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { createReactQueryWrapper } from './ReactQueryWrapper';
|
||||||
30
frontend/configs/jest/jest-fixed-jsdom.ts
Normal file
30
frontend/configs/jest/jest-fixed-jsdom.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// eslint-disable-next-line import/no-import-module-exports
|
||||||
|
import JSDOMEnvironment from 'jest-environment-jsdom';
|
||||||
|
|
||||||
|
class FixedJSDOMEnvironment extends JSDOMEnvironment {
|
||||||
|
constructor(...args: unknown[]) {
|
||||||
|
// @ts-ignore
|
||||||
|
super(...args);
|
||||||
|
|
||||||
|
this.global.TextDecoder = TextDecoder;
|
||||||
|
this.global.TextEncoder = TextEncoder;
|
||||||
|
this.global.TextDecoderStream = TextDecoderStream;
|
||||||
|
this.global.TextEncoderStream = TextEncoderStream;
|
||||||
|
this.global.ReadableStream = ReadableStream;
|
||||||
|
|
||||||
|
this.global.Blob = Blob;
|
||||||
|
this.global.Headers = Headers;
|
||||||
|
// this.global.FormData = FormData;
|
||||||
|
this.global.Request = Request;
|
||||||
|
this.global.Response = Response;
|
||||||
|
this.global.fetch = fetch;
|
||||||
|
this.global.structuredClone = structuredClone;
|
||||||
|
this.global.URL = URL;
|
||||||
|
this.global.URLSearchParams = URLSearchParams;
|
||||||
|
|
||||||
|
this.global.BroadcastChannel = BroadcastChannel;
|
||||||
|
this.global.TransformStream = TransformStream;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = FixedJSDOMEnvironment;
|
||||||
6
frontend/configs/jest/setupTests.ts
Normal file
6
frontend/configs/jest/setupTests.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import '@testing-library/jest-dom';
|
||||||
|
import { server } from '@mocks/jest/server';
|
||||||
|
|
||||||
|
beforeAll(() => server.listen());
|
||||||
|
afterEach(() => server.resetHandlers());
|
||||||
|
afterAll(() => server.close());
|
||||||
@ -9,7 +9,7 @@ export default [
|
|||||||
{
|
{
|
||||||
rules: {
|
rules: {
|
||||||
'import/no-extraneous-dependencies': ['error', {
|
'import/no-extraneous-dependencies': ['error', {
|
||||||
devDependencies: ['eslint.config.ts', 'rsbuild.config.ts'],
|
devDependencies: ['eslint.config.ts', 'rsbuild.config.ts', 'configs/**/*'],
|
||||||
}],
|
}],
|
||||||
'import/no-anonymous-default-export': 'off',
|
'import/no-anonymous-default-export': 'off',
|
||||||
'import/order': [
|
'import/order': [
|
||||||
@ -80,6 +80,7 @@ export default [
|
|||||||
'@typescript-eslint/no-unnecessary-condition': 'off',
|
'@typescript-eslint/no-unnecessary-condition': 'off',
|
||||||
'jsx-a11y/click-events-have-key-events': 'off',
|
'jsx-a11y/click-events-have-key-events': 'off',
|
||||||
'jsx-a11y/no-static-element-interactions': 'off',
|
'jsx-a11y/no-static-element-interactions': 'off',
|
||||||
|
'jsx-a11y/no-noninteractive-element-interactions': 'off',
|
||||||
'@stylistic/indent': 'off',
|
'@stylistic/indent': 'off',
|
||||||
'@stylistic/jsx-one-expression-per-line': 'off',
|
'@stylistic/jsx-one-expression-per-line': 'off',
|
||||||
},
|
},
|
||||||
@ -87,4 +88,22 @@ export default [
|
|||||||
{
|
{
|
||||||
ignores: ['./src/shared/api/schema.ts'],
|
ignores: ['./src/shared/api/schema.ts'],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
files: [
|
||||||
|
'**/*.test.js',
|
||||||
|
'**/*.test.jsx',
|
||||||
|
'**/*.test.ts',
|
||||||
|
'**/*.test.tsx',
|
||||||
|
'**/__tests__/**',
|
||||||
|
'**/tests/**',
|
||||||
|
],
|
||||||
|
rules: {
|
||||||
|
'import/no-extraneous-dependencies': [
|
||||||
|
'error',
|
||||||
|
{ devDependencies: true }, // в тестах можно
|
||||||
|
],
|
||||||
|
'@typescript-eslint/no-unsafe-call': 'off',
|
||||||
|
'@typescript-eslint/no-unsafe-member-access': 'off',
|
||||||
|
},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
23
frontend/jest.config.ts
Normal file
23
frontend/jest.config.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import type { Config } from 'jest';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
transform: {
|
||||||
|
'^.+\\.(t|j)sx?$': ['@swc/jest', {
|
||||||
|
jsc: {
|
||||||
|
transform: {
|
||||||
|
react: {
|
||||||
|
runtime: 'automatic',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
testEnvironment: '<rootDir>/configs/jest/jest-fixed-jsdom.ts',
|
||||||
|
setupFilesAfterEnv: ['<rootDir>/configs/jest/setupTests.ts'],
|
||||||
|
moduleNameMapper: {
|
||||||
|
'@/(.*)': '<rootDir>/src/$1',
|
||||||
|
'@mocks/(.*)': '<rootDir>/__mocks__/$1',
|
||||||
|
'\\.(css|scss|sass|less)$': 'identity-obj-proxy',
|
||||||
|
'\\.(jpg|jpeg|png|gif|webp|svg)$': '<rootDir>/__mocks__/jest/fileMock.js',
|
||||||
|
},
|
||||||
|
} as Config;
|
||||||
6953
frontend/package-lock.json
generated
6953
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -8,6 +8,7 @@
|
|||||||
"dev": "rsbuild dev",
|
"dev": "rsbuild dev",
|
||||||
"preview": "rsbuild preview",
|
"preview": "rsbuild preview",
|
||||||
"lint": "eslint",
|
"lint": "eslint",
|
||||||
|
"test:unit": "jest",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"openapi:gen": "npx openapi-typescript http://localhost:3000/docs/swagger.json -o src/shared/api/schema.ts"
|
"openapi:gen": "npx openapi-typescript http://localhost:3000/docs/swagger.json -o src/shared/api/schema.ts"
|
||||||
},
|
},
|
||||||
@ -23,13 +24,25 @@
|
|||||||
"@rsbuild/plugin-eslint": "1.1.2",
|
"@rsbuild/plugin-eslint": "1.1.2",
|
||||||
"@rsbuild/plugin-react": "1.3.5",
|
"@rsbuild/plugin-react": "1.3.5",
|
||||||
"@rsbuild/plugin-type-check": "1.2.4",
|
"@rsbuild/plugin-type-check": "1.2.4",
|
||||||
|
"@swc/core": "1.13.5",
|
||||||
|
"@swc/jest": "0.2.39",
|
||||||
"@tanstack/eslint-plugin-query": "5.83.1",
|
"@tanstack/eslint-plugin-query": "5.83.1",
|
||||||
|
"@testing-library/dom": "10.4.1",
|
||||||
|
"@testing-library/jest-dom": "6.8.0",
|
||||||
|
"@testing-library/react": "16.3.0",
|
||||||
|
"@testing-library/user-event": "14.6.1",
|
||||||
|
"@types/jest": "30.0.0",
|
||||||
"@types/react": "19.1.9",
|
"@types/react": "19.1.9",
|
||||||
"@types/react-dom": "19.1.7",
|
"@types/react-dom": "19.1.7",
|
||||||
"@typescript-eslint/parser": "8.39.0",
|
"@typescript-eslint/parser": "8.39.0",
|
||||||
"eslint": "9.34.0",
|
"eslint": "9.34.0",
|
||||||
"eslint-config-ksv741": "0.2.0",
|
"eslint-config-ksv741": "0.2.0",
|
||||||
|
"identity-obj-proxy": "3.0.0",
|
||||||
|
"jest": "30.1.1",
|
||||||
|
"jest-environment-jsdom": "30.1.1",
|
||||||
|
"msw": "2.10.5",
|
||||||
"openapi-typescript": "7.9.1",
|
"openapi-typescript": "7.9.1",
|
||||||
|
"ts-node": "10.9.2",
|
||||||
"typescript": "5.9.2"
|
"typescript": "5.9.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"moduleDetection": "force",
|
"moduleDetection": "force",
|
||||||
"moduleResolution": "bundler",
|
"moduleResolution": "bundler",
|
||||||
"verbatimModuleSyntax": true,
|
"verbatimModuleSyntax": false,
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"allowImportingTsExtensions": true,
|
"allowImportingTsExtensions": true,
|
||||||
"noUncheckedSideEffectImports": true,
|
"noUncheckedSideEffectImports": true,
|
||||||
@ -21,12 +21,17 @@
|
|||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"noUnusedParameters": true,
|
"noUnusedParameters": true,
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["./src/*"]
|
"@/*": ["./src/*"],
|
||||||
}
|
"@mocks/*": ["./__mocks__/*"]
|
||||||
|
},
|
||||||
|
"types": ["jest", "@testing-library/jest-dom"]
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src",
|
"src",
|
||||||
|
"__mocks__",
|
||||||
|
"configs",
|
||||||
"eslint.config.ts",
|
"eslint.config.ts",
|
||||||
"rsbuild.config.ts"
|
"rsbuild.config.ts",
|
||||||
|
"jest.config.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user