Skip to content

Commit

Permalink
feat: add husky and init vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelDemey committed Oct 30, 2024
1 parent b547a44 commit 3c5ee53
Show file tree
Hide file tree
Showing 6 changed files with 6,269 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
yarn --cwd drama-queen run format:check
yarn --cwd drama-queen run lint
yarn --cwd drama-queen run test
5 changes: 4 additions & 1 deletion drama-queen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"_format": "prettier '**/*.{ts,tsx,json,md}'",
"format": "npm run _format -- --write",
"lint": "eslint src/",
"test": "vitest",
"format:check": "npm run _format -- --list-different"
},
"dependencies": {
Expand Down Expand Up @@ -48,13 +49,15 @@
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.37.2",
"globals": "^15.11.0",
"jsdom": "^25.0.1",
"prettier": "^3.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.6.2",
"typescript-eslint": "^8.11.0",
"vite": "^5.4.8",
"vite-envs": "^4.4.5",
"vite-plugin-pwa": "^0.19.8",
"vite-tsconfig-paths": "^4.3.2"
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^2.1.4"
}
}
67 changes: 67 additions & 0 deletions drama-queen/src/core/tools/axiosError.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { describe, it, expect, vi } from 'vitest'
import { handleAxiosError } from './axiosError'
import { AxiosError } from 'axios'

vi.mock('i18n', () => ({
getTranslation: () => ({ t: (keyMessage: string) => keyMessage }), // Remplacez par la logique de traduction souhaitée
}))

describe('handleAxiosError', () => {
it('should return a custom message for no response', () => {
const error: AxiosError = {
message: '',
name: '',
config: {},
isAxiosError: true,
toJSON: () => ({}),
response: undefined,
} as AxiosError

const result = handleAxiosError(error)
expect(result.message).toBe(
"Une erreur s'est produite lors du traitement de la requête. Veuillez réessayer plus tard."
)
})

it('should return the correct message for status 400', () => {
const error: AxiosError = {
response: { status: 400 } as any,
message: '',
name: '',
config: {},
isAxiosError: true,
toJSON: () => ({}),
} as AxiosError

const result = handleAxiosError(error)
expect(result.message).toBe('400') // Assurez-vous que la traduction pour '400' est correcte
})

it('should return the correct message for status 401', () => {
const error: AxiosError = {
response: { status: 401 } as any,
message: '',
name: '',
config: {},
isAxiosError: true,
toJSON: () => ({}),
} as AxiosError

const result = handleAxiosError(error)
expect(result.message).toBe('401') // Assurez-vous que la traduction pour '401' est correcte
})

it('should return the correct message for unknown status', () => {
const error: AxiosError = {
response: { status: 999 } as any,
message: '',
name: '',
config: {},
isAxiosError: true,
toJSON: () => ({}),
} as AxiosError

const result = handleAxiosError(error)
expect(result.message).toBe('longUnknownError') // Assurez-vous que la traduction pour 'longUnknownError' est correcte
})
})
6 changes: 6 additions & 0 deletions drama-queen/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="vitest" />
import federation from '@originjs/vite-plugin-federation'
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
Expand All @@ -7,6 +8,11 @@ import tsconfigPaths from 'vite-tsconfig-paths'

// https://vitejs.dev/config/
export default defineConfig({
test: {
globals: true,
environment: 'jsdom',
},

plugins: [
react(),
viteEnvs({
Expand Down
Loading

0 comments on commit 3c5ee53

Please sign in to comment.