From 0445cb8df099e7507c86d73024d4005604a1349d Mon Sep 17 00:00:00 2001 From: Syed Ali Ul Hasan Date: Mon, 27 Jan 2025 21:17:39 +0530 Subject: [PATCH] Refactored src/components/GroupChatDetails from jest to vitest (#3453) * Refactored src/components/GroupChatDetails from jest to vitest * removed all instances and files related to jest * removed all instances and files related to jest * cleanup to eradicate jest fully * chore!: port to exclude instead ignore * refactor! path --------- Co-authored-by: Vamshi Maskuri <117595548+varshith257@users.noreply.github.com> --- .eslintrc.json | 4 - .github/workflows/pull-request.yml | 39 +-------- .github/workflows/scripts/countline.py | 2 +- jest-preview.config.ts | 5 -- jest.config.js | 86 ------------------- ...ils.test.tsx => GroupChatDetails.spec.tsx} | 23 ++--- 6 files changed, 14 insertions(+), 145 deletions(-) delete mode 100644 jest-preview.config.ts delete mode 100644 jest.config.js rename src/components/GroupChatDetails/{GroupChatDetails.test.tsx => GroupChatDetails.spec.tsx} (97%) diff --git a/.eslintrc.json b/.eslintrc.json index 39df0ff68d..9540d1c86f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -8,7 +8,6 @@ "extends": [ "plugin:react/recommended", "eslint:recommended", - "plugin:jest/recommended", "plugin:prettier/recommended", "plugin:@typescript-eslint/recommended", "eslint-config-prettier", @@ -30,7 +29,6 @@ "plugins": [ "react", "@typescript-eslint", - "jest", "import", "eslint-plugin-tsdoc", "prettier" @@ -128,8 +126,6 @@ "react/jsx-equals-spacing": ["warn", "never"], "react/no-this-in-sfc": "error", - "jest/expect-expect": 0, - "react/no-unstable-nested-components": ["error", { "allowAsProps": true }], "react/function-component-definition": [ 0, diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index c53b6536fd..6e30334217 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -243,22 +243,6 @@ jobs: - name: Get changed TypeScript files id: changed-files uses: tj-actions/changed-files@v45 - - - name: Run Jest Tests - if: steps.changed-files.outputs.any_changed == 'true' - env: - NODE_V8_COVERAGE: './coverage/jest' - run: | - npm run test -- --watchAll=false --coverage - - - name: Upload Jest Coverage to Codecov - if: steps.changed-files.outputs.any_changed == 'true' - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: ./coverage/jest/lcov.info - flags: jest - fail_ci_if_error: true - name: Run Vitest Tests if: steps.changed-files.outputs.any_changed == 'true' @@ -266,28 +250,13 @@ jobs: NODE_V8_COVERAGE: './coverage/vitest' run: | npm run test:vitest:coverage - - - name: Upload Vitest Coverage to Codecov - if: steps.changed-files.outputs.any_changed == 'true' - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: ./coverage/vitest/lcov.info - flags: vitest - fail_ci_if_error: true - - - name: Merge Jest and Vitest Coverage Reports - run: | - mkdir -p ./coverage - npx lcov-result-merger './coverage/*/lcov.info' './coverage/lcov.info' - - name: Upload Combined Coverage to Codecov + - name: Upload Coverage to Codecov uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} - gcov_ignore: 'docs/' - files: ./coverage/lcov.info - flags: combined + exclude: 'docs/' + files: ./coverage/vitest/lcov.info fail_ci_if_error: true - name: TypeScript compilation for changed files @@ -301,7 +270,7 @@ jobs: - name: Test acceptable level of code coverage uses: VeryGoodOpenSource/very_good_coverage@v3 with: - path: "./coverage/lcov.info" + path: "./coverage/vitest/lcov.info" min_coverage: 0 # Graphql-Inspector: diff --git a/.github/workflows/scripts/countline.py b/.github/workflows/scripts/countline.py index 5c3ee5d117..2372edcc3e 100755 --- a/.github/workflows/scripts/countline.py +++ b/.github/workflows/scripts/countline.py @@ -41,7 +41,7 @@ def _valid_filename(filepath): """ # Initialize key variables - invalid_filenames = [".test.", ".spec."] + invalid_filenames = [".spec."] result = True # Test diff --git a/jest-preview.config.ts b/jest-preview.config.ts deleted file mode 100644 index 0bcc13d4c7..0000000000 --- a/jest-preview.config.ts +++ /dev/null @@ -1,5 +0,0 @@ -export default { - moduleNameMapper: { - '^@mui/(.*)$': '/node_modules/@mui/$1', - }, -}; diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index dffec5db18..0000000000 --- a/jest.config.js +++ /dev/null @@ -1,86 +0,0 @@ -export default { - roots: ['/src'], - collectCoverageFrom: [ - 'src/**/*.{ts,tsx}', - '!src/index.tsx', - '!node_modules', - '!dist', - '!**/*.{spec,test}.{js,jsx,ts,tsx}', - '!coverage/**', - '!**/index.{js,ts}', - '!**/*.d.ts', - '!src/test/**', - '!vitest.config.ts', - ], - // setupFiles: ['react-app-polyfill/jsdom'], - setupFiles: ['whatwg-fetch'], - setupFilesAfterEnv: ['/src/setupTests.ts'], - testMatch: [ - '/src/**/__tests__/**/*.{js,jsx,ts,tsx}', - '/src/**/*.test.{js,jsx,ts,tsx}', - ], - testEnvironment: 'jsdom', - transform: { - '^.+\\.(js|jsx|ts|tsx)$': [ - 'babel-jest', - { configFile: './config/babel.config.cjs' }, - ], // Use babel-jest for JavaScript and TypeScript files - '^.+\\.(css|scss|sass|less)$': 'jest-preview/transforms/css', // CSS transformations - '^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': 'jest-preview/transforms/file', // File transformations - }, - transformIgnorePatterns: [ - '[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$', - ], - modulePaths: [ - '/Users/prathamesh/Desktop/Open-Source/palisadoes/talawa-admin/src', - '/src', - ], - moduleNameMapper: { - '\\.(css|scss|sass|less)$': 'identity-obj-proxy', - '^react-native$': 'react-native-web', - '^@dicebear/core$': '/scripts/__mocks__/@dicebear/core.ts', - '^@dicebear/collection$': - '/scripts/__mocks__/@dicebear/collection.ts', - '\\.svg\\?react$': '/scripts/__mocks__/fileMock.js', - '\\.svg$': '/scripts/__mocks__/fileMock.js', - '^@pdfme/generator$': '/scripts/__mocks__/@pdfme/generator.ts', - '\\.(css|less|scss|sass)$': 'identity-obj-proxy', - }, - moduleFileExtensions: [ - 'web.js', - 'js', - 'web.ts', - 'ts', - 'web.tsx', - 'tsx', - 'json', - 'web.jsx', - 'jsx', - 'node', - ], - // watchPlugins: [ - // 'jest-watch-typeahead/filename', - // 'jest-watch-typeahead/testname', - // ], - resetMocks: false, - coveragePathIgnorePatterns: [ - 'src/state/index.ts', - 'src/components/plugins/index.ts', - 'src/components/AddOn/support/services/Render.helper.ts', - 'src/components/SecuredRoute/SecuredRoute.tsx', - 'src/reportWebVitals.ts', - ], - coverageThreshold: { - global: { - lines: 1, - statements: 1, - }, - }, - testPathIgnorePatterns: [ - '/node_modules/', - '/build/', - '/public/', - ], - coverageDirectory: './coverage/jest', - coverageReporters: ['text', 'html', 'text-summary', 'lcov'], -}; diff --git a/src/components/GroupChatDetails/GroupChatDetails.test.tsx b/src/components/GroupChatDetails/GroupChatDetails.spec.tsx similarity index 97% rename from src/components/GroupChatDetails/GroupChatDetails.test.tsx rename to src/components/GroupChatDetails/GroupChatDetails.spec.tsx index 4a4aa73b61..bc4af27c5f 100644 --- a/src/components/GroupChatDetails/GroupChatDetails.test.tsx +++ b/src/components/GroupChatDetails/GroupChatDetails.spec.tsx @@ -2,8 +2,6 @@ import React from 'react'; import { render, screen, - // fireEvent, - // waitFor, act, fireEvent, waitFor, @@ -18,6 +16,7 @@ import { USERS_CONNECTION_LIST } from 'GraphQl/Queries/Queries'; import { I18nextProvider, initReactI18next } from 'react-i18next'; import i18n from 'i18next'; import { useLocalStorage } from 'utils/useLocalstorage'; +import { vi } from 'vitest'; const { setItem } = useLocalStorage(); @@ -432,10 +431,10 @@ describe('GroupChatDetails', () => { , @@ -456,10 +455,10 @@ describe('GroupChatDetails', () => { , @@ -518,10 +517,10 @@ describe('GroupChatDetails', () => { , @@ -558,8 +557,6 @@ describe('GroupChatDetails', () => { await act(async () => { fireEvent.click(await screen.findByTestId('addUserBtn')); }); - - await wait(10000); }); // test case for updating group chat image it('update group chat image', async () => { @@ -567,10 +564,10 @@ describe('GroupChatDetails', () => { , @@ -597,7 +594,5 @@ describe('GroupChatDetails', () => { }); fireEvent.change(fileInput); - - await wait(10000); }); });