Skip to content

Commit

Permalink
Migrate from jest to vite
Browse files Browse the repository at this point in the history
  • Loading branch information
reglim committed Aug 30, 2023
1 parent 8bb27d1 commit 697fc91
Show file tree
Hide file tree
Showing 5 changed files with 689 additions and 22 deletions.
5 changes: 4 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
"@types/react-dom": "^18.0.10",
"@typescript-eslint/parser": "^5.54.1",
"@vitejs/plugin-react-swc": "^3.3.2",
"@vitest/coverage-v8": "^0.34.3",
"eslint": "^8.0.1",
"fuse.js": "^6.6.2",
"http-proxy-middleware": "^2.0.6",
"jsdom": "^22.1.0",
"lodash": "^4.17.21",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand All @@ -33,13 +35,14 @@
"vite": "^4.4.9",
"vite-plugin-svgr": "^3.2.0",
"vite-tsconfig-paths": "^4.2.0",
"vitest": "^0.34.3",
"web-vitals": "^3.1.1"
},
"scripts": {
"start": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"test": "vite test --watchAll=false --testMatch **/src/**/*.test.ts",
"test": "vitest --watch=false",
"lint": "eslint ./src --ext .js,.jsx,.ts,.tsx"
},
"eslintConfig": {
Expand Down
8 changes: 4 additions & 4 deletions web/src/tests/repositories/ProjectRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import ProjectRepository from '../../repositories/ProjectRepository'
import ProjectDetails from '../../models/ProjectDetails'
import { Project } from '../../models/ProjectsResponse'
const mockFetchData = (fetchData: any): void => {
global.fetch = jest.fn().mockImplementation(async () => await Promise.resolve({
global.fetch = vi.fn().mockImplementation(async () => await Promise.resolve({
ok: true,
json: async () => await Promise.resolve(fetchData)
}))
}

const mockFetchError = (errorMsg = 'Error'): void => {
global.fetch = jest.fn().mockImplementation(async () => await Promise.resolve({
global.fetch = vi.fn().mockImplementation(async () => await Promise.resolve({
ok: false,
json: async () => await Promise.resolve({ message: errorMsg })
}))
}

const mockFetchStatus = (status: number, message?: string): void => {
global.fetch = jest.fn().mockImplementation(async () => await Promise.resolve({
global.fetch = vi.fn().mockImplementation(async () => await Promise.resolve({
ok: false,
status,
json: async () => await Promise.resolve({ message: message ?? 'Error' })
Expand All @@ -44,7 +44,7 @@ describe('get versions', () => {
const projectName = 'test'

mockFetchError('Test Error')
console.error = jest.fn()
console.error = vi.fn()

const result = await ProjectRepository.getVersions(projectName)

Expand Down
2 changes: 1 addition & 1 deletion web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"types": ["vite/client", "vite-plugin-svgr/client"]
"types": ["vite/client", "vite-plugin-svgr/client", "vitest/globals"]
},
"include": [
"src"
Expand Down
11 changes: 11 additions & 0 deletions web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,16 @@ export default defineConfig({
secure: false,
}
}
},
test: {
globals: true,
environment: 'jsdom',
css: true,
reporters: ['verbose'],
coverage: {
reporter: ['text', 'json', 'html'],
include: ['src/**/*'],
exclude: [],
}
}
})
Loading

0 comments on commit 697fc91

Please sign in to comment.