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

fix: sync content layer in dev #11365

Merged
merged 27 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
ascorbic committed Jun 27, 2024
commit 9de133f66a85ad98375682ef974927b8d955a5a5
89 changes: 89 additions & 0 deletions packages/astro/test/content-layer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { loadFixture } from './test-utils.js';

describe('Content Collections', () => {
describe('Query', () => {
let fixture;
before(async () => {
fixture = await loadFixture({ root: './fixtures/content-layer/' });
await fixture.build();
});

describe('Collection', () => {
let json;
before(async () => {
const rawJson = await fixture.readFile('/collections.json');
json = JSON.parse(rawJson);
});

it('Returns custom loader collection', async () => {
assert.ok(json.hasOwnProperty('customLoader'));
assert.ok(Array.isArray(json.customLoader));

const item = json.customLoader[0];
assert.deepEqual(item, {
id: '1',
collection: 'blog',
data: {
userId: 1,
id: 1,
title: 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit',
body: 'quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto',
},
type: 'experimental_data',
});
});

it('Returns file loader collection', async () => {
assert.ok(json.hasOwnProperty('fileLoader'));
assert.ok(Array.isArray(json.fileLoader));

const ids = json.fileLoader.map((item) => item.data.id);
assert.deepEqual(ids, [
'labrador-retriever',
'german-shepherd',
'golden-retriever',
'french-bulldog',
'bulldog',
'beagle',
'poodle',
'rottweiler',
'german-shorthaired-pointer',
'yorkshire-terrier',
'boxer',
'dachshund',
'siberian-husky',
'great-dane',
'doberman-pinscher',
'australian-shepherd',
'miniature-schnauzer',
'cavalier-king-charles-spaniel',
'shih-tzu',
'boston-terrier',
'bernese-mountain-dog',
'pomeranian',
'havanese',
'english-springer-spaniel',
'shetland-sheepdog',
]);
});

it('Returns data entry by id', async () => {
assert.ok(json.hasOwnProperty('dataEntryById'));
assert.deepEqual(json.dataEntryById, {
id: 'beagle',
collection: 'dogs',
data: {
breed: 'Beagle',
id: 'beagle',
size: 'Small to Medium',
origin: 'England',
lifespan: '12-15 years',
temperament: ['Friendly', 'Curious', 'Merry'],
},
});
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getCollection, getDataEntryById } from 'astro:content';

export async function GET() {
const customLoader = await getCollection('blog');
const fileLoader = await getCollection('dogs');

const dataEntryById = await getDataEntryById('dogs', 'beagle');

return new Response(
JSON.stringify({ customLoader, fileLoader, dataEntryById }),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ interface Props {

const { dog } = Astro.props

console.log({dog})

---

Expand Down
Loading