-
-
Notifications
You must be signed in to change notification settings - Fork 718
fix userCollections?.docs #3205
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
base: main
Are you sure you want to change the base?
Conversation
- check `userCollections?.docs` - add starlight-page example for test
|
✅ Deploy Preview for astro-starlight ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @sgalcheung! I don’t think we need to add a full example for this though, so we should remove the examples/starlight-page/
addition.
In this case, this doesn't have any huge effect, but we could use this example for StarlightPage in the future. |
Thanks for your contribution 🙌 Small follow-up after Chris's review and your last comments:
Examples are meant to be installable, e.g. using I think it would also be very weird to have a Starlight example not having the Starlight expected In this case, it looks like the only benefit of the example seems to be testing but we should be able to test that without having to add a new example. Starlight already contains some tests:
When it comes to I only tested quickly but it looks like a test similar to the following should work: test('adds data to route shape when the `docs` collection is not defined', async () => {
// Mock the collection config in this test to simulate the absence of the `docs` collection.
vi.doMock('virtual:starlight/collection-config', () => ({ collections: {} }));
const data = await generateStarlightPageRouteData({
props: starlightPageProps,
context: getRouteDataTestContext(starlightPagePathname),
});
expect(data.entry.data.title).toBe(starlightPageProps.frontmatter.title);
// Undo the mock to restore the original behavior.
vi.doUnmock('virtual:starlight/collection-config');
}); Before the changes from this PR, we get the expected error:
After the changes from this PR and using Chris's suggestion, we no longer get the error and data is properly added to the route data. |
Thank you for improving the unit test @HiDeoo ! Could you commit this test code? |
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
userCollections?.docs
Description
Capture docs as undefined.