Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate from jest to vitest #518

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
"ignorePatterns": [
// node_modules is implicitly always ignored
"dist",
"coverage",
"vite.config.mts",
"jest.config.ts",
"jest.setup.ts"
"vitest.config.mts",
"vitest.setup.mts"
],
"rules": {
"prettier/prettier": "warn",
"curly": "error",
"no-console": "off",
"react/jsx-props-no-spreading": "off",
"react/require-default-props": "off",
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }]
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"import/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*.test.ts", "**/*.test.tsx"]}]
}
}
24 changes: 0 additions & 24 deletions jest.config.ts

This file was deleted.

12,079 changes: 4,472 additions & 7,607 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"build": "tsc && vite build",
"build:pack": "tsc && vite build && npm pack",
"prepublishOnly": "npm run build",
"test": "jest",
"test:coverage": "jest --coverage",
"test:watch": "jest --watch",
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"test:watch": "vitest watch",
"lint": "eslint . --ext js,mjs,jsx,ts,mts,tsx --max-warnings 0",
"licenses-check": "license-checker --summary --excludePrivatePackages --production --onlyAllow \"$( jq -r .onlyAllow[] license-checker-config.json | tr '\n' ';')\" --excludePackages \"$( jq -r .excludePackages[] license-checker-config.json | tr '\n' ';')\""
},
Expand All @@ -45,18 +45,18 @@
"uuid": "^9.0.1"
},
"peerDependencies": {
"@mui/system": "^5.15.15",
"@mui/x-tree-view": "^6.17.0",
"papaparse": "^5.4.1",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.0",
"@hookform/resolvers": "^3.3.4",
"@mui/icons-material": "^5.15.14",
"@mui/lab": "5.0.0-alpha.169",
"@mui/material": "^5.15.14",
"@mui/system": "^5.15.15",
"@mui/x-tree-view": "^6.17.0",
"ag-grid-community": "^31.0.0",
"ag-grid-react": "^31.2.0",
"notistack": "^3.0.1",
"papaparse": "^5.4.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.51.2",
Expand All @@ -74,11 +74,11 @@
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@hookform/resolvers": "^3.3.4",
"@jest/globals": "^29.7.0",
"@mui/icons-material": "^5.15.14",
"@mui/lab": "5.0.0-alpha.169",
"@mui/material": "^5.15.14",
"@react-hook/window-size": "^3.1.1",
"@testing-library/react": "^16.0.0",
"@types/autosuggest-highlight": "^3.2.3",
"@types/eslint": "^8.56.7",
"@types/eslint-config-prettier": "^6.11.3",
Expand All @@ -96,6 +96,7 @@
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"@vitejs/plugin-react": "^4.2.1",
"@vitest/coverage-v8": "^2.0.2",
"ag-grid-community": "^31.0.0",
"ag-grid-react": "^31.2.0",
"babel-eslint": "^10.1.0",
Expand All @@ -115,8 +116,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"glob": "^10.3.12",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jsdom": "^24.1.0",
"license-checker": "^25.0.1",
"notistack": "^3.0.1",
"prettier": "^2.8.8",
Expand All @@ -136,6 +136,7 @@
"vite-plugin-eslint": "^1.8.1",
"vite-plugin-lib-inject-css": "^2.0.1",
"vite-plugin-svgr": "^4.2.0",
"vitest": "^2.0.2",
"yup": "^1.4.0"
},
"author": "gridsuite team",
Expand Down
4 changes: 2 additions & 2 deletions src/components/TopBar/TopBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { IntlProvider } from 'react-intl';

import { red } from '@mui/material/colors';
import { createTheme, ThemeProvider } from '@mui/material';
import { afterEach, beforeEach, expect, it } from '@jest/globals';
import { afterEach, beforeEach, expect, it } from 'vitest';
import TopBar, { LANG_ENGLISH } from './TopBar';
import { CommonMetadata, top_bar_en } from '../..';

import PowsyblLogo from '../images/powsybl_logo.svg?react';
import PowsyblLogo from '../../_mocks_/svg';

let container: Element;

Expand Down
22 changes: 22 additions & 0 deletions vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

/// <reference types="vitest" />
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
plugins: [react()],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need to redefine a vitestconfig file ?
"f you are using Vite and have a vite.config file, Vitest will read it to match with the plugins and setup as your Vite app. If you want to have a different configuration for testing [...] you could [...] create vitest.config.ts"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on other project, we set this directly on vite.config file with those parameters
test: { globals: true, environment: 'jsdom', setupFiles: './src/testSetup.ts', },
and the setup file, define a default config, like after afterEach(() => { cleanup() });

test: {
environment: 'jsdom',
globals: true,
setupFiles: './vitest.setup.mts',
coverage: {
provider: 'v8',
},
},
});
9 changes: 6 additions & 3 deletions jest.setup.ts → vitest.setup.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { TextEncoder, TextDecoder } from 'util';
import { afterEach } from 'vitest';
import { cleanup } from '@testing-library/react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there was already a PR to add @testing-library/react https://github.com/gridsuite/commons-ui/pull/216/files?w=1 it simplifies the code we should use it if we add testing-library


// fix for ReferenceError: TextDecoder / TextEncoder is not defined
Object.assign(global, { TextDecoder, TextEncoder });
// runs a clean after each test case (e.g. clearing jsdom)
afterEach(() => {
cleanup();
});
Loading