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

[SCF-66] mock server init #67

Merged
merged 1 commit into from
Mar 27, 2024
Merged

[SCF-66] mock server init #67

merged 1 commit into from
Mar 27, 2024

Conversation

osydoo
Copy link
Collaborator

@osydoo osydoo commented Mar 27, 2024

  • RSC에서 동작 여부 확인 필요

Changes

Reason for change

Detailed Description

mention

@osydoo @HamInKyou

Resolves: #
See also: #

- RSC에서 동작 여부 확인 필요
}>) {
useEffect(() => {
(async () => {
if (typeof window !== "undefined" && process.env.NEXT_MOCK_SERVER) {
Copy link
Contributor

Choose a reason for hiding this comment

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

여기서 useEffect를 사용해서 mockServer를 클라이언트에서 마운트되고 시작하게 만든거군욥

Copy link
Collaborator Author

@osydoo osydoo Mar 27, 2024

Choose a reason for hiding this comment

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

저도 검색해서 사람들이 사용한 방식 채용한겁니다. env 값으로 msw를 쓸지말지 정하는 방식은 좋아보이더라고요.

Copy link
Contributor

@HamInKyou HamInKyou left a comment

Choose a reason for hiding this comment

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

잘봤습니다! 설정 관련해서는 아직 잘 모르다보니 이해하고 넘어가는 식으로 읽어보았어요

@@ -0,0 +1,14 @@
import { http, HttpResponse } from "msw";

const signIn = [
Copy link
Contributor

Choose a reason for hiding this comment

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

signIn -> sign으로 바꿔야할 것 같아욥

Copy link
Collaborator Author

@osydoo osydoo Mar 27, 2024

Choose a reason for hiding this comment

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

이 부분은 로그인 관련 테스트 코드 작업하면서 수정해놓겠습니다. 현재 PR의 중점은 MSW 기본 세팅위주로 잡은지라 수정될 여지가 많아서요.

import { http, HttpResponse } from "msw";

const signIn = [
http.post(`${process.env.NEXT_PUBLIC_API_KEY}/sign-in`, () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

첫번째 매개변수 통해 넘겨온 api를 mock이 탈취해서 HttpResponse.json 형태로 돌려주는 꼴 맞나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

네 맞습니다. 리턴 방식은 다양하게 바꿔줄 수 있습니다만, 임시로 공식문서에서 제안한 �리턴값을 넣어둔 상태입니다.

Copy link
Contributor

Choose a reason for hiding this comment

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

여기서 모든 mock handler들이 다 모이는거구요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

네네 맞습니다. node와 브라우저간 핸들러 다루는 함수(setupWorker)가 달라 이 둘은 나눠집니다.

Copy link
Contributor

Choose a reason for hiding this comment

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

mock handler들을 여기서 다 갖고와서 목업 서버를 셋팅하는거구요

Copy link
Contributor

Choose a reason for hiding this comment

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

요거는 외부의 공식 문서 같은거를 들고와서 그대로 사용하신 그런 느낌인것 같아요 맞아요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

정확히는 MSW 공식문서 Draft PR 상태로 남아있는
mswjs/examples#101
이 코드를 참조했습니다.

@osydoo osydoo merged commit d338d44 into main Mar 27, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants