Skip to content

Comments

[fix] Jest 테스트 시 SVG import 오류 해결#422

Merged
oesnuj merged 2 commits intodevelop-fefrom
fix/#421-jest-svg-import-error
May 18, 2025
Merged

[fix] Jest 테스트 시 SVG import 오류 해결#422
oesnuj merged 2 commits intodevelop-fefrom
fix/#421-jest-svg-import-error

Conversation

@oesnuj
Copy link
Member

@oesnuj oesnuj commented May 16, 2025

#️⃣ 연관된 이슈

#421 (테스트 환경에서 이미지 파일 import 시 SyntaxError 발생)

📝 작업 내용

  • jest-transform-stub 라이브러리 설치
  • jest.config.js.svg, .png 등 이미지 파일에 대한 transform 설정 추가
  • 테스트 시 이미지 import 관련 SyntaxError(Unexpected token '<') 문제 해결

✅ 문제 상황

  • SNS_CONFIG 객체에 플랫폼별 아이콘(SVG/PNG)을 import하여 사용하는 로직이 추가되면서 테스트 실행 시 다음과 같은 에러 발생

    SyntaxError: Unexpected token '<'
  • 이는 Jest가 .svg 파일을 JS처럼 파싱하려다 실패한 문제로, 정적 파일에 대한 처리 설정이 누락된 상태였음

결론: Jest는 기본적으로 JS/TS만 이해하고, .svg, .png, .css 등 정적 자원은 이해 못 함

그래서 해결 방법은 이런 정적 파일들을 모두 가짜(mock) 파일로 치환하거나 특정 도구 (jest-transform-stub)로 처리 규칙을 명시해줘야함

🛠️ 해결 결과

  • jest-transform-stub을 도입하여 .svg, .png 등 정적 에셋을 mock 처리 - 쉽게 말하면 이미지를 문자열로 대체!!
  • Jest 설정 파일(jest.config.js)에 이미지 파일을 위한 transform 항목 추가

🫡 참고사항

oesnuj added 2 commits May 16, 2025 15:45
- SVG, PNG 등 정적 에셋 import 시 jest-transform-stub을 사용하도록 transform 설정 추가
@oesnuj oesnuj requested review from Copilot and seongwon030 May 16, 2025 06:50
@oesnuj oesnuj self-assigned this May 16, 2025
@oesnuj oesnuj added 💻 FE Frontend 🛠Fix 기능이 의도한 대로 동작하지 않는 버그를 수정 labels May 16, 2025
@netlify
Copy link

netlify bot commented May 16, 2025

Deploy Preview for moadong ready!

Name Link
🔨 Latest commit c01066b
🔍 Latest deploy log https://app.netlify.com/projects/moadong/deploys/6826e0450682260008640d0b
😎 Deploy Preview https://deploy-preview-422--moadong.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 39
Accessibility: 87
Best Practices: 92
SEO: 92
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 16, 2025

Walkthrough

Jest 설정 파일이 이미지 및 SVG 파일 확장자에 대해 jest-transform-stub을 사용하도록 업데이트되었습니다. 또한, jest-transform-stub 패키지가 프론트엔드 개발 의존성에 새로 추가되었습니다.

Changes

파일/경로 변경 요약
frontend/jest.config.js 이미지 및 SVG 파일 확장자(.svg, .png, .jpg, .jpeg, .gif)에 대해 jest-transform-stub 트랜스폼 규칙 추가
frontend/package.json jest-transform-stubdevDependencies에 버전 ^2.0.0으로 추가

Possibly related issues

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ad4cecb and c01066b.

⛔ Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • frontend/jest.config.js (1 hunks)
  • frontend/package.json (1 hunks)
🔇 Additional comments (2)
frontend/package.json (1)

78-78: jest-transform-stub 개발 의존성 추가가 적절합니다.

SVG 및 이미지 파일을 테스트 환경에서 올바르게 처리하기 위한 필수 패키지가 추가되었습니다. 현재 버전인 2.0.0은 안정적이며, Semver 호환성을 위해 캐럿(^) 표기법을 사용한 것이 좋습니다.

frontend/jest.config.js (1)

7-7:

Details

❓ Verification inconclusive

이미지 파일 변환 설정이 정확하게 구현되었습니다.

SVG, PNG, JPG, JPEG 및 GIF 파일에 대해 jest-transform-stub을 사용하도록 설정한 것이 PR 목표와 일치합니다. 이 설정은 Jest가 테스트 실행 중에 이미지 파일을 JavaScript로 잘못 해석하는 문제를 효과적으로 해결합니다.

정규식 패턴 \\.(svg|png|jpg|jpeg|gif)$는 모든 필요한 이미지 확장자를 포함하고 있어 적절합니다.

추가적으로 확인이 필요하다면, 다음 테스트 스크립트를 실행하여 SVG 파일 import가 정상적으로 동작하는지 검증할 수 있습니다:


🏁 Script executed:

#!/bin/bash
# SVG import 오류가 해결되었는지 확인
cd frontend
npm test

Length of output: 78


jest 설치 및 테스트 실행 확인 필요
이미지 파일 변환 설정(\\.(svg|png|jpg|jpeg|gif)$: jest-transform-stub) 자체는 올바르게 보입니다. 다만 npm test 실행 시 jest: not found 오류가 발생하여 실제 SVG import 동작 여부를 확인할 수 없었습니다. 아래 사항을 검토해 주세요:

  • frontend/package.jsondevDependenciesjest가 선언되어 있는지 확인
  • npm installnpm test 또는 npx jest 명령으로 테스트가 정상 실행되는지 검증
  • 테스트 내에서 SVG 등 이미지 파일 import가 기대한 대로 처리되는지 확인
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR resolves a SyntaxError encountered during Jest tests when importing image files by configuring Jest to handle static assets.

  • Installed the "jest-transform-stub" library
  • Updated Jest configuration to transform image file imports
  • Mitigates the SyntaxError by converting image assets to string stubs

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
frontend/package.json Added "jest-transform-stub" dependency
frontend/jest.config.js Configured Jest to transform image files using jest-transform-stub
Files not reviewed (1)
  • frontend/package-lock.json: Language not supported

@@ -4,6 +4,7 @@ module.exports = {
testEnvironment: 'jsdom',
transform: {
'^.+\\.tsx?$': ['ts-jest', {}],
Copy link

Copilot AI May 16, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider adding a comment to explain that the regex covers the image formats used in the project, and if additional formats are introduced later, the regex should be updated accordingly.

Suggested change
'^.+\\.tsx?$': ['ts-jest', {}],
'^.+\\.tsx?$': ['ts-jest', {}],
// This regex matches the image formats currently used in the project.
// If additional image formats are introduced, update this regex accordingly.

Copilot uses AI. Check for mistakes.
Copy link
Member

@seongwon030 seongwon030 left a comment

Choose a reason for hiding this comment

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

굳굳 좋습니다!

mock으로 처리하는 방법도 있긴 하네요잉 ~ 다음에 이 방법으로도 처리해볼게요

@oesnuj
Copy link
Member Author

oesnuj commented May 16, 2025

굳굳 좋습니다!

mock으로 처리하는 방법도 있긴 하네요잉 ~ 다음에 이 방법으로도 처리해볼게요

처음엔 mockFile.js 방식으로 치환을 시도했는데, 경로 인식 문제가 있는지 해결이 되지 않아서... 결국 라이브러리로 방향을 틀었습니다 😞

@seongwon030
Copy link
Member

굳굳 좋습니다!
mock으로 처리하는 방법도 있긴 하네요잉 ~ 다음에 이 방법으로도 처리해볼게요

처음엔 mockFile.js 방식으로 치환을 시도했는데, 경로 인식 문제가 있는지 해결이 되지 않아서... 결국 라이브러리로 방향을 틀었습니다 😞

아하.. 라이브러리 설치만 해 주면 되니까 이 방법이 더 편할 수도 있을 것 같습니당

@oesnuj oesnuj merged commit 8eb1dfe into develop-fe May 18, 2025
5 checks passed
@oesnuj oesnuj deleted the fix/#421-jest-svg-import-error branch May 21, 2025 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💻 FE Frontend 🛠Fix 기능이 의도한 대로 동작하지 않는 버그를 수정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants