Skip to content

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
zastrowm:remove_stub_page
Open

fix: update astro dev global-setup with astro:content mock for vitest to improve consistency#691
zastrowm wants to merge 1 commit intostrands-agents:mainfrom
zastrowm:remove_stub_page

Conversation

@zastrowm
Copy link
Member

@zastrowm zastrowm commented Mar 20, 2026

Description

Tests that call getCollection() from astro:content were broken in vitest because astro:content is 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:content in vitest to a lightweight mock (test/__mocks__/astro-content.ts) that reads .astro/data-store.json directly using devalue.unflatten — the same serialization format Astro uses internally — and implements getCollection/getEntry against that in-memory map.

The global-setup.ts is kept to populate the data store when it doesn't exist (e.g. fresh CI checkout) or local development. astro sync was 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

  • Bug fix

Checklist

  • I have read the CONTRIBUTING document
  • My changes follow the project's documentation style
  • I have tested the documentation locally using npm run dev
  • Links in the documentation are valid and working

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 20, 2026

Documentation Preview Ready

Your 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

@zastrowm zastrowm changed the title fix: replace astro dev global-setup with astro:content mock for vitest fix: update astro dev global-setup with astro:content mock for vitest to improve consistency Mar 20, 2026
@strands-agents strands-agents deleted a comment from github-actions bot Mar 20, 2026
@strands-agents strands-agents deleted a comment from github-actions bot Mar 20, 2026
@github-actions
Copy link
Contributor

Updated Review (v3 of PR)

Assessment: ✅ Approve

The core fix is sound — aliasing astro:content to a lightweight mock correctly addresses the Vite virtual module resolution issue that was breaking tests.

Review Details

What changed from earlier versions:

  • global-setup.ts is now kept (populates data store on fresh checkouts)
  • Documentation updates to AGENTS.md/SITE-ARCHITECTURE.md were removed
  • CI workflow changes were removed

Current approach:

  • globalSetup → ensures .astro/data-store.json exists (spawns astro dev if missing)
  • alias → mock reads data store directly, bypassing virtual module issues

Suggestion (non-blocking): Consider adding a brief comment in vitest.config.ts explaining why both globalSetup and the alias are needed, since this hybrid approach isn't immediately obvious to future maintainers:

// globalSetup populates .astro/data-store.json if missing
// alias mocks astro:content since the virtual module doesn't resolve in vitest

The mock implementation itself is well-designed and the fix is valid. Approving as-is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant