Skip to content

Commit

Permalink
migrating AddOn tests to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
prayanshchh committed Nov 21, 2024
1 parent 17baee2 commit a117b91
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 17 deletions.
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Contains the PDF file of the Tag as JSON string, thus does not need to be linted

Check warning on line 1 in .eslintignore

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

File ignored by default.
src/components/CheckIn/tagTemplate.ts
src/components/CheckIn/tagTemplate.ts
package.json
package-lock.json
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@
"vite": "^5.4.8",
"vite-plugin-environment": "^1.1.3",
"vite-plugin-node-polyfills": "^0.22.0",
"vite-tsconfig-paths": "^5.1.2",
"vite-tsconfig-paths": "^5.1.3",
"web-vitals": "^4.2.4"
},
"scripts": {
"serve": "cross-env ESLINT_NO_DEV_ERRORS=true vite --config config/vite.config.ts",
"build": "tsc && vite build --config config/vite.config.ts",
"preview": "vite preview --config config/vite.config.ts",
"test:vitest": "vitest run",
"test:vitest:watch": "vitest",
"test:vitest:coverage": "vitest run --coverage",
"test": "cross-env NODE_ENV=test jest --env=./scripts/custom-test-env.js --watchAll --coverage",
"eject": "react-scripts eject",
"lint:check": "eslint \"**/*.{ts,tsx}\" --max-warnings=0 && python .github/workflows/eslint_disable_check.py",
Expand Down Expand Up @@ -112,7 +115,7 @@
"@babel/preset-env": "^7.26.0",
"@babel/preset-react": "^7.25.7",
"@babel/preset-typescript": "^7.26.0",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^12.1.10",
"@types/inquirer": "^9.0.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,33 @@ import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';
import { MockedProvider } from '@apollo/react-testing';
import { I18nextProvider } from 'react-i18next';

import '@testing-library/jest-dom';
import { describe, test, expect, vi } from 'vitest';
import { store } from 'state/store';

import AddOn from './AddOn';
import i18nForTest from 'utils/i18nForTest';
import { StaticMockLink } from 'utils/StaticMockLink';

const link = new StaticMockLink([], true);
describe('Testing Addon component', () => {

vi.mock('state/store', () => ({
store: {
// Mock store configuration if needed
getState: vi.fn(),
subscribe: vi.fn(),
dispatch: vi.fn(),
},
}));

vi.mock('utils/i18nForTest', () => ({
__esModule: true,
default: vi.fn(() => ({
t: (key: string) => key,
})),
}));

describe('Testing AddOn component', () => {
const props = {
children: 'This is a dummy text',
};
Expand Down
File renamed without changes.
13 changes: 9 additions & 4 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import tsconfigPaths from 'vite-tsconfig-paths';
import path from 'path';

export default defineConfig({
plugins: [
react(),
nodePolyfills({
include: ['events'],
}),
tsconfigPaths(),
],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'), // Alias for src/
},
},
test: {
include: [
'src/**/__tests__/**/*.{js,jsx,ts,tsx}',
'src/**/*.{spec,test}.{js,jsx,ts,tsx}',
],
include: ['src/**/*.{spec,test}.{js,jsx,ts,tsx}'],
globals: true,
environment: 'jsdom',
coverage: {
Expand Down

0 comments on commit a117b91

Please sign in to comment.