Skip to content

Commit 51a697d

Browse files
authored
chore: fix content collection tests (#14431)
1 parent 24380c7 commit 51a697d

File tree

14 files changed

+25
-41
lines changed

14 files changed

+25
-41
lines changed

packages/astro/e2e/fixtures/actions-blog/db/seed.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { db, Likes, Comment } from "astro:db";
33
// https://astro.build/db/seed
44
export default async function seed() {
55
await db.insert(Likes).values({
6-
postId: "first-post.md",
6+
postId: "first-post",
77
likes: 10,
88
});
99

1010
await db.insert(Comment).values({
11-
postId: "first-post.md",
11+
postId: "first-post",
1212
author: "Alice",
1313
body: "Great post!",
1414
});

packages/astro/e2e/fixtures/actions-react-19/db/seed.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { db, Likes, Comment } from "astro:db";
33
// https://astro.build/db/seed
44
export default async function seed() {
55
await db.insert(Likes).values({
6-
postId: "first-post.md",
6+
postId: "first-post",
77
likes: 10,
88
});
99

1010
await db.insert(Comment).values({
11-
postId: "first-post.md",
11+
postId: "first-post",
1212
author: "Alice",
1313
body: "Great post!",
1414
});

packages/astro/e2e/fixtures/actions-react-19/src/pages/blog/[...slug].astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
import { type CollectionEntry, getCollection, getEntry } from 'astro:content';
2+
import { type CollectionEntry, getCollection, getEntry, render } from 'astro:content';
33
import BlogPost from '../../layouts/BlogPost.astro';
44
import { db, eq, Likes } from 'astro:db';
55
import { Like, LikeWithActionState } from '../../components/Like';
@@ -17,7 +17,7 @@ export async function getStaticPaths() {
1717
type Props = CollectionEntry<'blog'>;
1818
1919
const post = await getEntry('blog', Astro.params.slug)!;
20-
const { Content } = await post.render();
20+
const { Content } = await render(post)
2121
2222
const likesRes = await db.select().from(Likes).where(eq(Likes.postId, post.id)).get()!;
2323
---

packages/astro/test/content-collections-render.test.js

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,23 @@ describe('Content Collections - render()', () => {
142142
it('getCollection should return new instances of the array to be mutated safely', async () => {
143143
const app = await fixture.loadTestAdapterApp();
144144

145-
let request = new Request('http://example.com/sort-blog-collection');
145+
let request = new Request('http://example.com/');
146146
let response = await app.render(request);
147147
let html = await response.text();
148148
let $ = cheerio.load(html);
149-
assert.equal($('li').first().text(), 'Launch week!');
149+
const firstText = $('li').first().text();
150+
151+
request = new Request('http://example.com/sort-blog-collection');
152+
response = await app.render(request);
153+
html = await response.text();
154+
$ = cheerio.load(html);
155+
assert.notEqual($('li').first().text(), firstText);
150156

151157
request = new Request('http://example.com/');
152158
response = await app.render(request);
153159
html = await response.text();
154160
$ = cheerio.load(html);
155-
assert.equal($('li').first().text(), 'Hello world');
161+
assert.equal($('li').first().text(), firstText);
156162
});
157163
});
158164

@@ -212,24 +218,5 @@ describe('Content Collections - render()', () => {
212218
assert.equal(h2.length, 1);
213219
assert.equal(h2.attr('data-components-export-applied'), 'true');
214220
});
215-
216-
it.skip('Supports layout prop with recursive getCollection() call - DEPRECATED: layout props removed in Astro 5', async () => {
217-
const response = await fixture.fetch('/with-layout-prop', { method: 'GET' });
218-
assert.equal(response.status, 200);
219-
220-
const html = await response.text();
221-
const $ = cheerio.load(html);
222-
223-
const body = $('body');
224-
assert.equal(body.attr('data-layout-prop'), 'true');
225-
226-
const h1 = $('h1');
227-
assert.equal(h1.length, 1);
228-
assert.equal(h1.text(), 'With Layout Prop');
229-
230-
const h2 = $('h2');
231-
assert.equal(h2.length, 1);
232-
assert.equal(h2.text(), 'Content with a layout prop');
233-
});
234221
});
235222
});

packages/astro/test/content-collections.test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,7 @@ describe('Content Collections', () => {
233233
} catch (e) {
234234
error = e.message;
235235
}
236-
assert.equal(
237-
error,
238-
'Found legacy content config file in "src/content/config.mjs". Please move this file to "src/content.config.mjs" and ensure each collection has a loader defined.',
239-
);
236+
assert.ok(error.startsWith('Found legacy content config file in'));
240237
});
241238
});
242239

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Hello world
2+
title: 1 Hello world
33
description: Just a demo
44
---
55
This is a post
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: 'Launch week!'
2+
title: '2 Launch week!'
33
description: 'Join us for the exciting launch of SPACE BLOG'
44
publishedDate: 'Sat May 21 2022 00:00:00 GMT-0400 (Eastern Daylight Time)'
55
tags: ['announcement']
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: 'Launch week!'
2+
title: '3 Launch week!'
33
description: 'Join us for the exciting launch of SPACE BLOG'
44
publishedDate: 'Sat May 21 2022 00:00:00 GMT-0400 (Eastern Daylight Time)'
55
tags: ['announcement']

packages/astro/test/fixtures/content/src/content/blog/promo/launch-week.mdx renamed to packages/astro/test/fixtures/content/src/content/blog/promo/4-launch-week.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: 'Launch week!'
2+
title: '4 Launch week!'
33
description: 'Join us for the exciting launch of SPACE BLOG'
44
publishedDate: 'Sat May 21 2022 00:00:00 GMT-0400 (Eastern Daylight Time)'
55
tags: ['announcement']

packages/astro/test/fixtures/content/src/pages/launch-week-component-scripts.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
import { getEntry, render } from 'astro:content';
33
4-
const entry = await getEntry('blog', 'promo/launch-week-component-scripts');
4+
const entry = await getEntry('blog', 'promo/2-launch-week-component-scripts');
55
const { Content } = await render(entry);
66
---
77
<html>

0 commit comments

Comments
 (0)