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

bug: IonIcon giving error with vitest #1316

Open
3 tasks done
asifrahman112 opened this issue Jan 4, 2024 · 14 comments
Open
3 tasks done

bug: IonIcon giving error with vitest #1316

asifrahman112 opened this issue Jan 4, 2024 · 14 comments
Labels
triage New issues

Comments

@asifrahman112
Copy link

asifrahman112 commented Jan 4, 2024

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

While running vitest on the components using IonIcon, the test is failing with following error though the image is rendered properly in the project
Using IonIcon as: <IonIcon src="/assets/nozzle.svg"/>
error

It works fine when using ion icon with with inbuilt icons provided by ionic but causes issues when we try to use any image url with it.

Expected Behavior

The IonIcon should work with vitest properly when using image url with it.

Steps to Reproduce

  1. Create any react component in ionic framework.
  2. Use IonIcon inside the component as using image path as src in IonIcon.
  3. Run Vitest on the component

Code Reproduction URL

https://stackblitz.com/edit/ionic-react-vitest-example-qfvsxq?file=src%2Fcomponents%2FHeader.tsx

Run the App: npm run dev
Run test suite: npm run test

Ionic Info

Ionic:

"@ionic/react": "^7.0.10",
"@ionic/react-router": "^7.3.1"

vite:

"vite": "4.3.9",
"vite-plugin-dts": "2.3.0",
"vite-plugin-eslint": "^1.8.1",
"vite-plugin-svgr": "^4.2.0",
"vite-tsconfig-paths": "^4.0.2",
"vitest": "0.32.0"

Additional Information

No response

Copy link

ionitron-bot bot commented Jan 4, 2024

Thanks for the issue! This issue has been labeled as holiday triage. With the winter holidays quickly approaching, much of the Ionic Team will soon be taking time off. During this time, issue triaging and PR review will be delayed until the team begins to return. After this period, we will work to ensure that all new issues are properly triaged and that new PRs are reviewed. In the meantime, please read our Winter Holiday Triage Guide for information on how to ensure that your issue is triaged correctly. Thank you!

@rdlabo
Copy link

rdlabo commented Jan 4, 2024

@asifrahman112 Is the path /image.svg correct?
Angular copies everything under assets into the build file, so in most cases it should be /assets/image.svg or /assets/**/image.svg.

@asifrahman112
Copy link
Author

@asifrahman112 Is the path /image.svg correct? Angular copies everything under assets into the build file, so in most cases it should be /assets/image.svg or /assets/**/image.svg.

@rdlabo yes the path is correct...since its loading correctly in my project and I can access the image on that path. But the test fails with inavlid url message

@rdlabo
Copy link

rdlabo commented Jan 4, 2024

@asifrahman112 Thanks reply. Now, try moving your SVG files under /assets. The error text in the image says it is looking in /assets.

Failed to parse URL from /assets/nozzle.svg

@asifrahman112
Copy link
Author

@rdlabo The image is already placed in assets folder in the root public directory

@rdlabo
Copy link

rdlabo commented Jan 4, 2024

rdlabo/ionic-react-vite-src-icon@2d48a70

@asifrahman112 I had mistakenly commented on some of the configurations. Please check the project that we have made which is displayed correctly. This project is based https://github.com/ionic-team/starters/tree/main/react-vite

@liamdebeasi
Copy link
Contributor

@asifrahman112 Can you provide a GitHub repo with a minimal reproduction?

Copy link

ionitron-bot bot commented Jan 4, 2024

Thanks for the issue! This issue has been labeled as needs reproduction. This label is added to issues that need a code reproduction.

Please reproduce this issue in an Ionic starter application and provide a way for us to access it (GitHub repo, StackBlitz, etc). Without a reliable code reproduction, it is unlikely we will be able to resolve the issue, leading to it being closed.

If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was not enough for our team to reproduce the issue.

For a guide on how to create a good reproduction, see our Contributing Guide.

@asifrahman112
Copy link
Author

@rdlabo The image displays correctly in my project. Only the unit test fails on vitest with the error I have mentioned above

@asifrahman112
Copy link
Author

asifrahman112 commented Jan 5, 2024

@liamdebeasi I have added the stackblitz url for the issue reproduction
https://stackblitz.com/edit/ionic-react-vitest-example-qfvsxq?file=src%2Fcomponents%2FHeader.tsx

@liamdebeasi If you do npm run dev it works correctly, and the image is displayed properly but if you do npm run test it gives error

@liamdebeasi
Copy link
Contributor

There's likely an issue with the asset path either not being defined or being defined incorrectly when loading the Ionicon. I'm going to move this over to the Ionicons repo so we can take a closer look.

@liamdebeasi liamdebeasi transferred this issue from ionic-team/ionic-framework Jan 5, 2024
@sagarkm
Copy link

sagarkm commented Jan 8, 2024

I am facing the same issue in my project:
// Works when project runs and vitest passes as well
// Works when project runs, but fails in vitest : TypeError: Invalid URL

Important Update:
When running the vitest in Node 16.60.0 there seems to be no issue - test runs succesfully.
But when the same vitest is run in Node 18.18.0 the test fails with above issue.

@sofi-algoritcom
Copy link

I have the same problem. As @sagarkm mentioned above, the issue disappears when running the tests with node 16, it seems to be a problem with node 18. Any solution found to this? 🙏

@lichblitz
Copy link

The problem persists with node 20.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage New issues
Projects
None yet
Development

No branches or pull requests

7 participants