You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a function that wraps getCollection to manipulate the result before returning it in getStaticPaths to avoid repeats. I want to test that function to be sure nothing is broken.
Now, if no Markdown files use a cover (from the example above), Vitest can run the tests successfully. However if a Markdown file defines a cover, Vitest will fail to run the tests that calls the image helper:
I know, I should probably extract the manipulation in another function and only test that function. So there is a workaround and this is a minor bug. Nonetheless, I think the image helper should not break the tests.
Steps to reproduce:
I included a Stackblitz link with a minimal reproduction. The added files are in src/assets, in src/content and in src/utils (+ vitest.config.ts).
However, its seems it is not possible to run Vitest from the command line (no output). So you need to:
Download the project
Run npm i to install the dependencies
Run npm run test to execute Vitest and to see the error
Edit src/content/pages/page-with-cover.md to remove the cover from the frontmatter
Run again npm run test to execute Vitest and to see no errors
What's the expected result?
Be able to run tests with Vitest for functions that involves Astro's own functions (like getCollection) when the image helper is used with content collections.
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
The issue:
Astro offers an image helper to validate the content collections schema using Zod:
I have a function that wraps
getCollection
to manipulate the result before returning it ingetStaticPaths
to avoid repeats. I want to test that function to be sure nothing is broken.Now, if no Markdown files use a
cover
(from the example above), Vitest can run the tests successfully. However if a Markdown file defines acover
, Vitest will fail to run the tests that calls the image helper:I know, I should probably extract the manipulation in another function and only test that function. So there is a workaround and this is a minor bug. Nonetheless, I think the image helper should not break the tests.
Steps to reproduce:
I included a Stackblitz link with a minimal reproduction. The added files are in
src/assets
, insrc/content
and insrc/utils
(+vitest.config.ts
).However, its seems it is not possible to run Vitest from the command line (no output). So you need to:
npm i
to install the dependenciesnpm run test
to execute Vitest and to see the errorsrc/content/pages/page-with-cover.md
to remove thecover
from the frontmatternpm run test
to execute Vitest and to see no errorsWhat's the expected result?
Be able to run tests with Vitest for functions that involves Astro's own functions (like
getCollection
) when the image helper is used with content collections.Link to Minimal Reproducible Example
https://stackblitz.com/edit/astro-vitest-image-content-collections?file=src%2Futils%2Fcollections.test.ts
Participation
The text was updated successfully, but these errors were encountered: