Skip to content

Commit

Permalink
finish tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rgodha24 committed Sep 20, 2024
1 parent d156fe0 commit d3056dd
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 15 deletions.
54 changes: 45 additions & 9 deletions packages/astro/test/content-layer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ describe('Content Layer', () => {
assert.equal(json.customLoader.length, 5);
});

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

const ids = json.fileLoader.map((item) => item.data.id);
const ids = json.jsonLoader.map((item) => item.data.id);
assert.deepEqual(ids, [
'labrador-retriever',
'german-shepherd',
Expand Down Expand Up @@ -87,6 +87,42 @@ describe('Content Layer', () => {
]);
});

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

const ids = json.yamlLoader.map((item) => item.data.id);
assert.deepEqual(ids, [
'bubbles',
'finn',
'shadow',
'spark',
'splash',
'nemo',
'angel-fish',
'gold-stripe',
'blue-tail',
'bubble-buddy',
]);
});

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

const ids = json.tomlLoader.map((item) => item.data.id);
assert.deepEqual(ids, [
'crown',
'nikes-on-my-feet',
'stars',
'never-let-me-down',
'no-church-in-the-wild',
'family-ties',
'somebody',
'honest',
]);
});

it('Returns data entry by id', async () => {
assert.ok(json.hasOwnProperty('dataEntry'));
assert.equal(json.dataEntry.filePath?.split(sep).join(posixSep), 'src/data/dogs.json');
Expand Down Expand Up @@ -249,10 +285,10 @@ describe('Content Layer', () => {
});

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

const ids = json.fileLoader.map((item) => item.data.id);
const ids = json.jsonLoader.map((item) => item.data.id);
assert.deepEqual(ids, [
'labrador-retriever',
'german-shepherd',
Expand Down Expand Up @@ -303,7 +339,7 @@ describe('Content Layer', () => {
it('updates collection when data file is changed', async () => {
const rawJsonResponse = await fixture.fetch('/collections.json');
const initialJson = devalue.parse(await rawJsonResponse.text());
assert.equal(initialJson.fileLoader[0].data.temperament.includes('Bouncy'), false);
assert.equal(initialJson.jsonLoader[0].data.temperament.includes('Bouncy'), false);

await fixture.editFile('/src/data/dogs.json', (prev) => {
const data = JSON.parse(prev);
Expand All @@ -314,7 +350,7 @@ describe('Content Layer', () => {
await fixture.onNextDataStoreChange();
const updatedJsonResponse = await fixture.fetch('/collections.json');
const updated = devalue.parse(await updatedJsonResponse.text());
assert.ok(updated.fileLoader[0].data.temperament.includes('Bouncy'));
assert.ok(updated.jsonLoader[0].data.temperament.includes('Bouncy'));
await fixture.resetAllFiles();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export async function GET() {
const customLoader = await getCollection('blog', (entry) => {
return entry.data.id < 6;
});
const fileLoader = await getCollection('dogs');
const jsonLoader = await getCollection('dogs');

const dataEntry = await getEntry('dogs', 'beagle');

Expand All @@ -19,17 +19,24 @@ export async function GET() {
const increment = await getEntry('increment', 'value');

const images = await getCollection('images');

const yamlLoader = await getCollection('fish');

const tomlLoader = await getCollection('songs');

return new Response(
devalue.stringify({
customLoader,
fileLoader,
jsonLoader,
dataEntry,
simpleLoader,
entryWithReference,
entryWithImagePath,
referencedEntry,
increment,
images
})
images,
yamlLoader,
tomlLoader,
}),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ interface Props {
}
const { song, artists } = Astro.props;
console.log(artists);
---

<h1>{song.name}</h1>
Expand Down

0 comments on commit d3056dd

Please sign in to comment.