fix: update astro dev global-setup with astro:content mock for vitest to improve consistency#691
Open
zastrowm wants to merge 1 commit intostrands-agents:mainfrom
Open
fix: update astro dev global-setup with astro:content mock for vitest to improve consistency#691zastrowm wants to merge 1 commit intostrands-agents:mainfrom
zastrowm wants to merge 1 commit intostrands-agents:mainfrom
Conversation
Contributor
Documentation Preview ReadyYour documentation preview has been successfully deployed! Preview URL: https://d3ehv1nix5p99z.cloudfront.net/pr-cms-691/docs/user-guide/quickstart/overview/ Updated at: 2026-03-20T22:13:33.981Z |
Contributor
Updated Review (v3 of PR)Assessment: ✅ Approve The core fix is sound — aliasing Review DetailsWhat changed from earlier versions:
Current approach:
Suggestion (non-blocking): Consider adding a brief comment in // globalSetup populates .astro/data-store.json if missing
// alias mocks astro:content since the virtual module doesn't resolve in vitestThe mock implementation itself is well-designed and the fix is valid. Approving as-is. |
37862e2 to
edfe59c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Tests that call
getCollection()fromastro:contentwere broken in vitest becauseastro:contentis a Vite virtual module — it only resolves inside Astro's build pipeline and depending on the version of astro may not work in tests.The fix aliases
astro:contentin vitest to a lightweight mock (test/__mocks__/astro-content.ts) that reads.astro/data-store.jsondirectly usingdevalue.unflatten— the same serialization format Astro uses internally — and implementsgetCollection/getEntryagainst that in-memory map.The
global-setup.tsis kept to populate the data store when it doesn't exist (e.g. fresh CI checkout) or local development.astro syncwas investigated as a lighter alternative but does not produce the data store. The setup is skipped when the data store is already present, so local re-runs are fast.The
__*__/gitignore pattern that was inadvertently suppressing the__mocks__directory is also removed.Related Issues
N/A
Type of Change
Checklist
npm run devBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.