-
Notifications
You must be signed in to change notification settings - Fork 0
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
Config/#3: Mock Service Worker 설치 및 설정 #10
Conversation
- ref: #3
- API 요청을 Mocking 할 핸들러 파일 생성 - MSW의 node.js 환경(vitest) 통합을 위한 server 파일 생성 - 테스트 시 MSW 사용을 위한 vitest.setup.ts 파일 수정 - 테스트 전 setup 파일 설정 - ref: #3
- 브라우저 환경 API 모킹을 위한 woker 생성(browser.ts) - 개발 환경에서 woker 실행을 위한 main.tsx 수정(조건부 msw 시작) - worker.start()는 비동기 작업으로, 브라우저에 서비스 워커를 등록하는 과정이 포함 필요(.then) - ref: #3
- 테스트를 위해 임시로 수정 - ref: #3
- tsconfig의 type을 추가하였습니다. - vitest.config.ts 오타 수정 - vitest.setup.ts에서 CJS인 jest-dom의 matcher를 모두 가져오도록 함. - @testing-library/user-event" 추가 설치 - ref: #3
- ref: #3
vitest.setup.ts
Outdated
import { cleanup } from '@testing-library/react'; | ||
import matchers from '@testing-library/jest-dom/matchers'; | ||
import * as matchers from '@testing-library/jest-dom/matchers'; | ||
import { server } from './src/mocks/server'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2 mocks
디렉토리도 절대 경로 별칭으로 등록한 후에, 나머지 상대 경로로 작성한 부분들 수정해 주세요~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵!
src/mocks/browser.ts
Outdated
import { setupWorker } from 'msw/browser'; | ||
import { handlers } from './handlers'; | ||
|
||
export const worker = setupWorker(...handlers); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 프로젝트 내에 import/prefer-default-export
규칙이 적용되어 있어요. 해당 규칙을 off
할 건지, 사용할 건지 논의해 보고 나머지 파일에서도 수정이 필요할 것 같아요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
해당 규칙은 그대로 가져가면 좋을 것 같아요. 규칙 확인에 좀 더 신경쓰겠습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 tsconfig.eslint.json
에 vitest.setup.ts
대신 vitest.workspace.ts
이 등록되어 있어요. 이 부분도 수정이 필요할 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정했습니다!!
- mocks 폴더의 절대 경로 별칭을 설정, 상대 경로 수정 - ESLint import/no-extraneous-dependencies 규칙을 off로 바꾸었습니다. - import/prefer-default-export에 맞게 파일들을 일부 수정했습니다. - ref: #3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
정상 작동 확인했습니다~ 고생하셨어요
📌 관련 이슈
🔑 주요 변경 사항
📸 스크린 샷 (선택 사항)
📖 참고 사항