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

Content Collection getEntry does not work with Astro 5.1 + Vitest. #12836

Open
1 task
NewGyu opened this issue Dec 27, 2024 · 1 comment
Open
1 task

Content Collection getEntry does not work with Astro 5.1 + Vitest. #12836

NewGyu opened this issue Dec 27, 2024 · 1 comment
Labels
needs triage Issue needs to be triaged

Comments

@NewGyu
Copy link

NewGyu commented Dec 27, 2024

Astro Info

Astro                    v5.1.1
Node                     v18.20.3
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

My util function uses getEntry internally.

import { getEntry } from 'astro:content';

export const getRamen = async (name: string) => {
  return await getEntry('ramen', name);
};

It works well in astro page.

---
import { getRamen } from '../util';
const r = await getRamen('ichiran');
---

<html lang="en">
	<head>
		<meta charset="utf-8" />
		<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
		<meta name="viewport" content="width=device-width" />
		<meta name="generator" content={Astro.generator} />
		<title>Astro</title>
	</head>
	<body>
		<h1>Astro</h1>
		<p>{r.data.taste}</p>
	</body>
</html>

However, npm test on GitHub Actions Job is failed.

https://github.com/NewGyu/astro5-with-vitest/actions/runs/12513338337/job/34907813726#step:5:14

The collection "ramen" does not exist. Please ensure it is defined in your content config.

Why? It seems to be related to .astro/data-store.json.

Executing npm run dev once before npm test improves this problem. The reason is that npm run dev makes .astro/data-store.json file when DevServer is booted.

In the case of npm test on GitHub actions, the file .astro/data-store.json does not exist when the test running, so it seems that getEntry causes the error The collection "ramen" does not exist..

What's the expected result?

ramen content entry should be retrieved even if npm test is run as GitHub actions job.

Link to Minimal Reproducible Example

https://stackblitz.com/~/github.com/NewGyu/astro5-with-vitest

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Dec 27, 2024
@NewGyu
Copy link
Author

NewGyu commented Dec 27, 2024

I've tried to insert npm run build step before test step, but it haven't solved this.
https://github.com/NewGyu/astro5-with-vitest/actions/runs/12513596606/job/34908446824

npm run build task generated .astro directory, but data-store.json was not made. As a workaround, how can I generate data-store.json file without running npm run dev?

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

No branches or pull requests

1 participant