-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dabf08a
commit 0d2262f
Showing
12 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import assert from 'node:assert/strict'; | ||
import { before, describe, it } from 'node:test'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('Content Intellisense', () => { | ||
/** @type {import("./test-utils.js").Fixture} */ | ||
let fixture; | ||
|
||
/** @type {string[]} */ | ||
let collectionsDir = []; | ||
|
||
/** @type {{collections: {hasSchema: boolean, name: string}[], entries: Record<string, string>}} */ | ||
let manifest = undefined; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ root: './fixtures/content-Intellisense/' }); | ||
await fixture.build(); | ||
|
||
collectionsDir = await fixture.readdir('../.astro/collections'); | ||
manifest = JSON.parse(await fixture.readFile('../.astro/collections/collections.json')); | ||
}); | ||
|
||
it('generate JSON schemas for content collections', async () => { | ||
assert.deepEqual(collectionsDir.includes('blog-cc.schema.json'), true); | ||
}); | ||
|
||
it('generate JSON schemas for content layer', async () => { | ||
assert.deepEqual(collectionsDir.includes('blog-cl.schema.json'), true); | ||
}); | ||
|
||
it('manifest exists', async () => { | ||
assert.notEqual(manifest, undefined); | ||
}); | ||
|
||
it('manifest has content collections', async () => { | ||
const manifestCollections = manifest.collections.map((collection) => collection.name); | ||
assert.equal( | ||
manifestCollections.includes('blog-cc'), | ||
true, | ||
"Expected 'blog-cc' collection in manifest", | ||
); | ||
}); | ||
|
||
it('manifest has content layer', async () => { | ||
const manifestCollections = manifest.collections.map((collection) => collection.name); | ||
assert.equal( | ||
manifestCollections.includes('blog-cl'), | ||
true, | ||
"Expected 'blog-cl' collection in manifest", | ||
); | ||
}); | ||
|
||
it('has entries for content collections', async () => { | ||
const collectionEntries = Object.entries(manifest.entries).filter((entry) => | ||
entry[0].includes( | ||
'/astro/packages/astro/test/fixtures/content-intellisense/src/content/blog-cc/', | ||
), | ||
); | ||
assert.equal(collectionEntries.length, 3, "Expected 3 entries for 'blog-cc' collection"); | ||
assert.equal( | ||
collectionEntries.every((entry) => entry[1] === 'blog-cc'), | ||
true, | ||
"Expected 3 entries for 'blog-cc' collection to have 'blog-cc' as collection", | ||
); | ||
}); | ||
|
||
it('has entries for content layer', async () => { | ||
const collectionEntries = Object.entries(manifest.entries).filter((entry) => | ||
entry[0].includes( | ||
'/astro/packages/astro/test/fixtures/content-intellisense/src/content/blog-cl/', | ||
), | ||
); | ||
assert.equal(collectionEntries.length, 3, "Expected 3 entries for 'blog-cl' collection"); | ||
assert.equal( | ||
collectionEntries.every((entry) => entry[1] === 'blog-cl'), | ||
true, | ||
"Expected 3 entries for 'blog-cl' collection to have 'blog-cl' as collection name", | ||
); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
packages/astro/test/fixtures/content-intellisense/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import markdoc from "@astrojs/markdoc"; | ||
import mdx from '@astrojs/mdx'; | ||
import { defineConfig } from 'astro/config'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
integrations: [mdx(), markdoc()], | ||
experimental: { | ||
contentLayer: true, | ||
contentIntellisense: true | ||
} | ||
}); |
10 changes: 10 additions & 0 deletions
10
packages/astro/test/fixtures/content-intellisense/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "@test/content-intellisense", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*", | ||
"@astrojs/mdx": "workspace:*", | ||
"@astrojs/markdoc": "workspace:*" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/astro/test/fixtures/content-intellisense/src/blog-cl/entry.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: "Markdown" | ||
--- |
3 changes: 3 additions & 0 deletions
3
packages/astro/test/fixtures/content-intellisense/src/blog-cl/entry2.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: "MDX" | ||
--- |
3 changes: 3 additions & 0 deletions
3
packages/astro/test/fixtures/content-intellisense/src/blog-cl/entry3.mdoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: "Markdoc" | ||
--- |
3 changes: 3 additions & 0 deletions
3
packages/astro/test/fixtures/content-intellisense/src/content/blog-cc/entry.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: "Markdown" | ||
--- |
3 changes: 3 additions & 0 deletions
3
packages/astro/test/fixtures/content-intellisense/src/content/blog-cc/entry2.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: "MDX" | ||
--- |
3 changes: 3 additions & 0 deletions
3
packages/astro/test/fixtures/content-intellisense/src/content/blog-cc/entry3.mdoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: "Markdoc" | ||
--- |
24 changes: 24 additions & 0 deletions
24
packages/astro/test/fixtures/content-intellisense/src/content/config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { glob } from 'astro/loaders'; | ||
import { defineCollection, z } from 'astro:content'; | ||
|
||
const blogCC = defineCollection({ | ||
type: 'content', | ||
schema: z.object({ | ||
title: z.string(), | ||
description: z.string().optional(), | ||
}), | ||
}); | ||
|
||
const blogCL = defineCollection({ | ||
// By default the ID is a slug, generated from the path of the file relative to `base` | ||
loader: glob({ pattern: "**/*", base: "./src/blog-cl" }), | ||
schema: z.object({ | ||
title: z.string(), | ||
description: z.string().optional(), | ||
}), | ||
}); | ||
|
||
export const collections = { | ||
"blog-cc": blogCC, | ||
"blog-cl": blogCL, | ||
}; |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/content-intellisense/src/utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function stripRenderFn(entryWithRender) { | ||
const { render, ...entry } = entryWithRender; | ||
return entry; | ||
} | ||
|
||
export function stripAllRenderFn(collection = []) { | ||
return collection.map(stripRenderFn); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.