Skip to content

[feat] Add MSW setup for API mocking#115

Merged
karnelll merged 2 commits intorefactor/mainfrom
feature/msw-setup
Jan 15, 2025
Merged

[feat] Add MSW setup for API mocking#115
karnelll merged 2 commits intorefactor/mainfrom
feature/msw-setup

Conversation

@karnelll
Copy link
Contributor

#๏ธโƒฃ์—ฐ๊ด€ ์ด์Šˆ

ex) #์ด์Šˆ๋ฒˆํ˜ธ


๐Ÿ“์ž‘์—… ๋‚ด์šฉ

1. MSW(Mock Service Worker) ํ™˜๊ฒฝ ์„ธํŒ… ์™„๋ฃŒ

  • ์ฐธ๊ณ  ์ž๋ฃŒ:
    • ์ฒซ ๋ฒˆ์งธ ๋ธ”๋กœ๊ทธ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ํ™˜๊ฒฝ ์„ธํŒ… ์™„๋ฃŒ.
    • Mock API ์š”์ฒญ ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•œ ํ•ธ๋“ค๋Ÿฌ(GET, POST) ๊ตฌํ˜„.
    • ๋ธŒ๋ผ์šฐ์ € ๋ฐ ์„œ๋ฒ„ ํ™˜๊ฒฝ ์ง€์›๊ณผ React ํ†ตํ•ฉ ์™„๋ฃŒ.
แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2025-01-14 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 4 58 10

๐Ÿšจ์ถ”๊ฐ€ ์‚ฌํ•ญ

1. npm audit fix ์‹คํ–‰ ๋ณด๋ฅ˜

  • ์ƒํ™ฉ:
    ์ทจ์•ฝ์  ํ•ด๊ฒฐ์„ ์œ„ํ•ด npm audit fix ์‹คํ–‰ ์‹œ ์ƒˆ๋กœ์šด ๋นŒ๋“œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ์–ด ์‹คํ–‰ํ•˜์ง€ ์•Š์Œ.
  • ์กฐ์น˜ ํ•„์š”:
    ์ทจ์•ฝ์  ํ•ด๊ฒฐ ๋ฐฉ๋ฒ• ์žฌ๊ฒ€ํ†  ๋ฐ ์•ˆ์ „ํ•œ ์—…๋ฐ์ดํŠธ ๋ฐฉ์•ˆ ๋ชจ์ƒ‰.

2. MSW ํ™˜๊ฒฝ ์„ธํŒ… ๋ฐฉ์‹์˜ ๋‹ค์–‘์„ฑ

  • ์ƒํ™ฉ:
    • ๋‘ ๋ฒˆ์งธ ๋ธ”๋กœ๊ทธ์—์„œ MSW ์ตœ์‹  ๋ฒ„์ „๊ณผ TypeScript ์ ์šฉ ์‹œ ๋ชจ๋“ˆ ์ธ์‹ ์˜ค๋ฅ˜ ๋ฐœ์ƒ ๊ฐ€๋Šฅ์„ฑ ์–ธ๊ธ‰.
    • ์ฒซ ๋ฒˆ์งธ ๋ธ”๋กœ๊ทธ์˜ ๋ฐฉ๋ฒ•์œผ๋กœ ํ•ด๊ฒฐํ–ˆ์œผ๋‚˜, ๋‘ ๋ฒˆ์งธ ๋ธ”๋กœ๊ทธ๋Š” MSW ๋ฒ„์ „ ๋‹ค์šด๊ทธ๋ ˆ์ด๋“œ๋กœ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐ.
  • ์กฐ์น˜ ํ•„์š”:
    1. MSW ์ตœ์‹  ๋ฒ„์ „๊ณผ TypeScript ํ˜ธํ™˜์„ฑ ๊ฒ€ํ† .
    2. ํ•„์š” ์‹œ MSW ๋ฒ„์ „ ๋‹ค์šด๊ทธ๋ ˆ์ด๋“œ์™€ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ• ๊ฒ€ํ† .

3. MSW ์„ค์น˜ ๋ฐ devDependencies ๋ฌธ์ œ

  • ์ƒํ™ฉ:
    npm install msw --save ์‹คํ–‰ ํ›„์—๋„ MSW๊ฐ€ devDependencies๋กœ ์ธ์‹.
    ํŒจํ‚ค์ง€ ์žฌ์„ค์น˜(npm uninstall msw โ†’ npm install msw --save)๋ฅผ ์‹œ๋„ํ–ˆ์œผ๋‚˜ ๋นŒ๋“œ ์˜ค๋ฅ˜ ๋ฐœ์ƒ.

  • ์ž„์‹œ ์กฐ์น˜:

    • ESLint ๊ทœ์น™ ์ถ”๊ฐ€:

      mocks ๊ฒฝ๋กœ ๋‚ด ํŒŒ์ผ์—์„œ devDependencies ์‚ฌ์šฉ์„ ํ—ˆ์šฉํ•˜๋„๋ก ์„ค์ •.

      "rules": {
        "import/no-extraneous-dependencies": [
          "error",
          { "devDependencies": ["**/mocks/**"] }
        ]
      }

๐Ÿ’ฌ๋ฆฌ๋ทฐ ์š”๊ตฌ์‚ฌํ•ญ

  1. 'npm audit fix' ๊ด€๋ จ ์ทจ์•ฝ์  ํ•ด๊ฒฐ ๋ฐฉ๋ฒ• ์žฌ๊ฒ€ํ† .
  2. MSW ํ™˜๊ฒฝ ์„ธํŒ… ๋ฐฉ์‹ ๋น„๊ต ๋ฐ ์ตœ์ ์˜ ๋ฐฉ๋ฒ• ๋„์ถœ.
  3. TypeScript ํ˜ธํ™˜์„ฑ ๊ฒ€์ฆ.
  4. MSW ์„ค์น˜ ๋ฌธ์ œ ํ•ด๊ฒฐ ๋ฐ ESLint ์„ค์ • ์ ๊ฒ€.

@cr-gpt
Copy link

cr-gpt bot commented Jan 13, 2025

Seems you are using me but didn't get OPENAI_API_KEY seted in Variables/Secrets for this repo. you could follow readme for more information

@vercel
Copy link

vercel bot commented Jan 13, 2025

The latest updates on your projects. Learn more about Vercel for Git โ†—๏ธŽ

Name Status Preview Comments Updated (UTC)
pingping-fe โœ… Ready (Inspect) Visit Preview ๐Ÿ’ฌ Add feedback Jan 13, 2025 10:11pm

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code review by ChatGPT

@karnelll karnelll changed the title [feat] [feat] Add MSW setup for API mocking Jan 13, 2025
@karnelll karnelll requested a review from choihooo January 13, 2025 22:17
@karnelll karnelll self-assigned this Jan 13, 2025
@karnelll karnelll added the feat ๐ŸŒŸ ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ ์ถ”๊ฐ€ label Jan 13, 2025
@karnelll karnelll changed the base branch from main to refactor/main January 13, 2025 22:18
@choihooo
Copy link
Member

์Œ.. ์ฑ—์ง€ํ”ผํ‹ฐ ๋ฆฌ๋ทฐ๊ฐ€ ์ƒ๊ฐ๋ณด๋‹ค ํ€„์ด ๋†’๊ฒŒ ๋ฆฌ๋ทฐ ์ž˜ ํ•ด์ค€๊ฑฐ ๊ฐ™์•„์„œ ์ง€๊ธˆ ๋ถ€๋ถ„์—์„œ ๋” ๋ฆฌ๋ทฐํ• ๊ฑด ์—†๋Š” ๊ฑฐ ๊ฐ™์•„์š”.
๊ทธ๋ฆฌ๊ณ  ์ฐธ๊ณ ํ• ๋งŒํ•œ ๊ฒƒ๋“ค์„ ์ฐพ์•„๋ดค๋Š”๋ฐ

์ด๊ฑฐ ๋‘๊ฐœ ์ฐธ๊ณ ํ• ๋งŒํ•œ ๊ฑฐ ๊ฐ™๊ณ  ๋‘๋ฒˆ์งธ ๋ ˆํฌ๋Š” ์•ž์œผ๋กœ ํด๋”๊ตฌ์กฐ ๋ณ€๊ฒฝํ• ๋•Œ๋„ ์ฐธ๊ณ ํ•˜๋ฉด ์ข‹์„ ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค!
์•ž์œผ๋กœ๋„ ํ™”์ดํŒ…๐Ÿ‘

Copy link
Member

@choihooo choihooo left a comment

Choose a reason for hiding this comment

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

LGTM๐Ÿ‘

@karnelll karnelll merged commit d628905 into refactor/main Jan 15, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat ๐ŸŒŸ ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ ์ถ”๊ฐ€

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants