From c5b0b486fa6997891be79b2f906cf581d4b865c3 Mon Sep 17 00:00:00 2001 From: serendipty01 <34604329+serendipty01@users.noreply.github.com> Date: Tue, 7 Jul 2026 20:51:01 +0530 Subject: [PATCH] chore(client): migrate test setup to Vitest 4 (#550) --- client/.dockerignore | 1 + client/.eslintrc.cjs | 2 +- client/eslint/__tests__/customRules.test.js | 30 +++++++++++---------- client/package.json | 4 +-- client/tsconfig.json | 9 ++++++- client/tsconfig.test.json | 19 +++++++++++++ client/vite.config.ts | 3 +++ 7 files changed, 50 insertions(+), 18 deletions(-) create mode 100644 client/tsconfig.test.json diff --git a/client/.dockerignore b/client/.dockerignore index 3246d92..e898e62 100644 --- a/client/.dockerignore +++ b/client/.dockerignore @@ -10,3 +10,4 @@ !tailwind.config.js !tsconfig.json !nginx.conf +!tsconfig.test.json diff --git a/client/.eslintrc.cjs b/client/.eslintrc.cjs index e4993e9..f99eb06 100644 --- a/client/.eslintrc.cjs +++ b/client/.eslintrc.cjs @@ -23,7 +23,7 @@ module.exports = { extends: ['plugin:react/recommended', 'plugin:react-hooks/recommended'], parser: '@typescript-eslint/parser', parserOptions: { - project: ['./tsconfig.json'], + project: ['./tsconfig.json', './tsconfig.test.json'], tsconfigRootDir: __dirname, }, ignorePatterns: [ diff --git a/client/eslint/__tests__/customRules.test.js b/client/eslint/__tests__/customRules.test.js index bdd26c4..7b8f1bd 100644 --- a/client/eslint/__tests__/customRules.test.js +++ b/client/eslint/__tests__/customRules.test.js @@ -1,22 +1,24 @@ -const { Linter } = require('eslint'); -const rule = require('../no-casting-in-getFieldValueForRole'); +import tsParser from '@typescript-eslint/parser'; +import { Linter } from 'eslint'; -const linter = new Linter(); +import rule from '../no-casting-in-getFieldValueForRole.js'; + +const linter = new Linter({ configType: 'flat' }); const runLint = (code) => { - const messages = linter.verify(code, { - plugins: { - custom: { - rules: { - 'no-casting-in-getFieldValueForRole': rule, - }, + const messages = linter.verify(code, [ + { + plugins: { + local: { rules: { 'no-casting-in-getFieldValueForRole': rule } }, + }, + rules: { 'local/no-casting-in-getFieldValueForRole': 'error' }, + languageOptions: { + parser: tsParser, + ecmaVersion: 2015, + sourceType: 'module', }, }, - rules: { - 'custom/no-casting-in-getFieldValueForRole': 'error', - }, - languageOptions: { ecmaVersion: 2015, sourceType: 'module' }, - }); + ]); return messages; }; diff --git a/client/package.json b/client/package.json index 504c3df..3a3f004 100644 --- a/client/package.json +++ b/client/package.json @@ -7,9 +7,9 @@ "start": "vite --port 3000", "build": "vite build", "test": "vitest --passWithNoTests", - "test:prepush": "vitest --watchAll=false --passWithNoTests", + "test:prepush": "vitest run --passWithNoTests", "check:prepush": "npm run build && npm run test:prepush", - "lint": "tsc --noEmit && eslint ./src", + "lint": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json && eslint ./src", "storybook": "storybook dev -p 6006", "build-storybook": "storybook build", "knip": "knip" diff --git a/client/tsconfig.json b/client/tsconfig.json index 823c15c..fb0490d 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json @@ -21,5 +21,12 @@ "@/*": ["./src/*"] } }, - "include": ["src"] + "include": ["src"], + "exclude": [ + "src/**/*.test.ts", + "src/**/*.test.tsx", + "src/**/*.spec.ts", + "src/**/*.spec.tsx", + "src/setupTests.ts" + ] } diff --git a/client/tsconfig.test.json b/client/tsconfig.test.json new file mode 100644 index 0000000..73456ac --- /dev/null +++ b/client/tsconfig.test.json @@ -0,0 +1,19 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "types": [ + "vite/client", + "vite-plugin-svgr/client", + "vitest/globals", + "node" + ] + }, + "include": [ + "src/**/*.test.ts", + "src/**/*.test.tsx", + "src/**/*.spec.ts", + "src/**/*.spec.tsx", + "src/setupTests.ts" + ], + "exclude": ["node_modules"] +} diff --git a/client/vite.config.ts b/client/vite.config.ts index 2e29ca8..ba47330 100644 --- a/client/vite.config.ts +++ b/client/vite.config.ts @@ -34,5 +34,8 @@ export default defineConfig({ globals: true, environment: 'jsdom', setupFiles: './src/setupTests.ts', + typecheck: { + tsconfig: './tsconfig.test.json', + }, }, }); -- 2.51.2