From 5a59ecc5dfd0a3d71faf1c249333c80f49b47fef Mon Sep 17 00:00:00 2001 From: Rohan Godha Date: Tue, 24 Sep 2024 14:52:59 -0400 Subject: [PATCH] add map yaml test --- packages/astro/src/content/loaders/file.ts | 4 ++-- packages/astro/test/content-layer.test.js | 2 +- .../content-layer/src/content/config.ts | 1 - .../fixtures/content-layer/src/data/fish.yaml | 21 ++++++++++--------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/astro/src/content/loaders/file.ts b/packages/astro/src/content/loaders/file.ts index ed1701e11108c..d109f95b69940 100644 --- a/packages/astro/src/content/loaders/file.ts +++ b/packages/astro/src/content/loaders/file.ts @@ -11,7 +11,7 @@ export interface FileOptions { * */ parser?: ( text: string, - ) => Record | Array<{ id: string } & Record>; + ) => Record> | Array>; } /** @@ -46,7 +46,7 @@ export function file(fileName: string, options?: FileOptions): Loader { } async function syncData(filePath: string, { logger, parseData, store, config }: LoaderContext) { - let data: Array>; + let data: Array> | Record>; try { const contents = await fs.readFile(filePath, 'utf-8'); diff --git a/packages/astro/test/content-layer.test.js b/packages/astro/test/content-layer.test.js index 28a3c3811657b..dcd78d90ce376 100644 --- a/packages/astro/test/content-layer.test.js +++ b/packages/astro/test/content-layer.test.js @@ -99,7 +99,7 @@ describe('Content Layer', () => { assert.ok(json.hasOwnProperty('yamlLoader')); assert.ok(Array.isArray(json.yamlLoader)); - const ids = json.yamlLoader.map((item) => item.data.id); + const ids = json.yamlLoader.map((item) => item.id); assert.deepEqual(ids, [ 'bubbles', 'finn', diff --git a/packages/astro/test/fixtures/content-layer/src/content/config.ts b/packages/astro/test/fixtures/content-layer/src/content/config.ts index 6659dfdad39b4..931c04f8ad985 100644 --- a/packages/astro/test/fixtures/content-layer/src/content/config.ts +++ b/packages/astro/test/fixtures/content-layer/src/content/config.ts @@ -69,7 +69,6 @@ const cats = defineCollection({ const fish = defineCollection({ loader: file('src/data/fish.yaml'), schema: z.object({ - id: z.string(), name: z.string(), breed: z.string(), age: z.number(), diff --git a/packages/astro/test/fixtures/content-layer/src/data/fish.yaml b/packages/astro/test/fixtures/content-layer/src/data/fish.yaml index 5a49d9983c03f..a9ac4e4352b4b 100644 --- a/packages/astro/test/fixtures/content-layer/src/data/fish.yaml +++ b/packages/astro/test/fixtures/content-layer/src/data/fish.yaml @@ -1,40 +1,41 @@ -- id: "bubbles" +# map of ids to data +bubbles: name: "Bubbles" breed: "Goldfish" age: 2 -- id: "finn" +finn: name: "Finn" breed: "Betta" age: 1 -- id: "shadow" +shadow: name: "Shadow" breed: "Catfish" age: 3 -- id: "spark" +spark: name: "Spark" breed: "Tetra" age: 1 -- id: "splash" +splash: name: "Splash" breed: "Guppy" age: 2 -- id: "nemo" +nemo: name: "Nemo" breed: "Clownfish" age: 3 -- id: "angel-fish" +angel-fish: name: "Angel Fish" breed: "Angelfish" age: 4 -- id: "gold-stripe" +gold-stripe: name: "Gold Stripe" breed: "Molly" age: 1 -- id: "blue-tail" +blue-tail: name: "Blue Tail" breed: "Swordtail" age: 2 -- id: "bubble-buddy" +bubble-buddy: name: "Bubble Buddy" breed: "Betta" age: 3