-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use a new fixture to fix tests
- Loading branch information
Showing
20 changed files
with
223 additions
and
31 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
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
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 |
---|---|---|
@@ -1,42 +1,42 @@ | ||
import assert from 'node:assert/strict'; | ||
import { after, before, describe, it } from 'node:test'; | ||
|
||
import { loadFixture } from './test-utils.js'; | ||
describe('Content Layer', () => { | ||
|
||
describe('Content Layer dev', () => { | ||
/** @type {import("./test-utils.js").Fixture} */ | ||
let fixture; | ||
|
||
describe('Dev', () => { | ||
let devServer; | ||
before(async () => { | ||
fixture = await loadFixture({ root: './fixtures/content-layer/' }); | ||
devServer = await fixture.startDevServer(); | ||
}); | ||
let devServer; | ||
before(async () => { | ||
fixture = await loadFixture({ root: './fixtures/content-layer-rendering/' }); | ||
devServer = await fixture.startDevServer(); | ||
}); | ||
|
||
after(async () => { | ||
devServer?.stop(); | ||
}); | ||
after(async () => { | ||
devServer?.stop(); | ||
}); | ||
|
||
it('Render an MDX file', async () => { | ||
const html = await fixture.fetch('/reptiles/iguana').then((r) => r.text()); | ||
it('Render an MDX file', async () => { | ||
const html = await fixture.fetch('/reptiles/iguana').then((r) => r.text()); | ||
|
||
assert.match(html, /Iguana/); | ||
assert.match(html, /This is a rendered entry/); | ||
}); | ||
assert.match(html, /Iguana/); | ||
assert.match(html, /This is a rendered entry/); | ||
}); | ||
}); | ||
|
||
describe('Build', () => { | ||
before(async () => { | ||
fixture = await loadFixture({ root: './fixtures/content-layer/' }); | ||
await fixture.build(); | ||
}); | ||
|
||
describe('Content Layer build', () => { | ||
/** @type {import("./test-utils.js").Fixture} */ | ||
let fixture; | ||
before(async () => { | ||
fixture = await loadFixture({ root: './fixtures/content-layer/' }); | ||
fixture = await loadFixture({ root: './fixtures/content-layer/' }); | ||
await fixture.build(); | ||
}); | ||
|
||
it('Render an MDX file', async () => { | ||
const html = await fixture.readFile('/reptiles/iguana/index.html'); | ||
it('Render an MDX file', async () => { | ||
const html = await fixture.readFile('/reptiles/iguana/index.html'); | ||
|
||
assert.match(html, /Iguana/); | ||
assert.match(html, /This is a rendered entry/); | ||
}); | ||
assert.match(html, /Iguana/); | ||
assert.match(html, /This is a rendered entry/); | ||
}); | ||
}); |
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
14 changes: 14 additions & 0 deletions
14
packages/astro/test/fixtures/content-layer-rendering/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,14 @@ | ||
import mdx from '@astrojs/mdx'; | ||
import { defineConfig } from 'astro/config'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
export default defineConfig({ | ||
integrations: [mdx()], | ||
vite: { | ||
resolve: { | ||
alias: { | ||
'@images': fileURLToPath(new URL('./images', import.meta.url)) | ||
} | ||
}, | ||
} | ||
}); |
File renamed without changes.
File renamed without changes
Binary file added
BIN
+73.2 KB
packages/astro/test/fixtures/content-layer-rendering/images/atlantis.avif
Binary file not shown.
Binary file added
BIN
+71.8 KB
packages/astro/test/fixtures/content-layer-rendering/images/launch.webp
Binary file not shown.
Binary file added
BIN
+170 KB
packages/astro/test/fixtures/content-layer-rendering/images/shuttle.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions
9
packages/astro/test/fixtures/content-layer-rendering/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,9 @@ | ||
{ | ||
"name": "@test/content-layer-rendering", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*", | ||
"@astrojs/mdx": "workspace:*" | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/astro/test/fixtures/content-layer-rendering/src/components/H2.astro
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,4 @@ | ||
--- | ||
--- | ||
|
||
<h2 data-components-export-applied="true"><slot /></h2> |
2 changes: 2 additions & 0 deletions
2
packages/astro/test/fixtures/content-layer-rendering/src/components/H3.astro
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,2 @@ | ||
<style>h3 { margin: 1rem }</style> | ||
<h3><slot /></h3> |
39 changes: 39 additions & 0 deletions
39
packages/astro/test/fixtures/content-layer-rendering/src/components/LayoutProp.astro
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,39 @@ | ||
--- | ||
import { CollectionEntry, getCollection } from 'astro:content'; | ||
import H3 from './H3.astro' | ||
// Test for recursive `getCollection()` calls | ||
const blog = await getCollection('blog'); | ||
type Props = { | ||
content: CollectionEntry<'blog'>['data']; | ||
}; | ||
const { | ||
content: { title }, | ||
} = Astro.props; | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" /> | ||
<meta name="viewport" content="width=device-width" /> | ||
<meta name="generator" content={Astro.generator} /> | ||
<title>With Layout Prop</title> | ||
</head> | ||
<body data-layout-prop="true"> | ||
<h1>{title}</h1> | ||
<H3>H3 inserted in the layout</H3> | ||
<nav> | ||
<ul> | ||
{blog.map((post) => ( | ||
<li> | ||
<a href={post.slug}>{post.data.title}</a> | ||
</li> | ||
))} | ||
</ul> | ||
</nav> | ||
<slot /> | ||
</body> | ||
</html> | ||
|
11 changes: 11 additions & 0 deletions
11
packages/astro/test/fixtures/content-layer-rendering/src/components/WithScripts.astro
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,11 @@ | ||
<p id="update-me">Hoisted script didn't update me :(</p> | ||
|
||
<p id="update-me-inline">Inline script didn't update me :(</p> | ||
|
||
<script> | ||
document.querySelector('#update-me').innerText = 'Updated client-side with hoisted script!'; | ||
</script> | ||
|
||
<script is:inline data-is-inline> | ||
document.querySelector('#update-me-inline').innerText = 'Updated client-side with inline script!'; | ||
</script> |
19 changes: 19 additions & 0 deletions
19
packages/astro/test/fixtures/content-layer-rendering/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,19 @@ | ||
import { defineCollection, z, reference } from 'astro:content'; | ||
import { file, glob } from 'astro/loaders'; | ||
|
||
const reptiles = defineCollection({ | ||
type: 'experimental_content', | ||
loader: glob({ | ||
pattern: '*.mdx', | ||
base: new URL('../../content-outside-src-mdx', import.meta.url), | ||
}), | ||
schema: () => | ||
z.object({ | ||
title: z.string(), | ||
description: z.string(), | ||
publishedDate: z.coerce.date(), | ||
tags: z.array(z.string()), | ||
}), | ||
}); | ||
|
||
export const collections = { reptiles }; |
30 changes: 30 additions & 0 deletions
30
packages/astro/test/fixtures/content-layer-rendering/src/pages/collections.json.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,30 @@ | ||
import { getCollection, getEntry } from 'astro:content'; | ||
import * as devalue from 'devalue'; | ||
|
||
export async function GET() { | ||
const customLoader = await getCollection('blog', (entry) => { | ||
return entry.data.id < 6; | ||
}); | ||
const fileLoader = await getCollection('dogs'); | ||
|
||
const dataEntry = await getEntry('dogs', 'beagle'); | ||
|
||
const simpleLoader = await getCollection('cats'); | ||
|
||
const entryWithReference = await getEntry('spacecraft', 'columbia-copy'); | ||
const referencedEntry = await getEntry(entryWithReference.data.cat); | ||
|
||
const increment = await getEntry('increment', 'value'); | ||
|
||
return new Response( | ||
devalue.stringify({ | ||
customLoader, | ||
fileLoader, | ||
dataEntry, | ||
simpleLoader, | ||
entryWithReference, | ||
referencedEntry, | ||
increment, | ||
}) | ||
); | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/astro/test/fixtures/content-layer-rendering/src/pages/index.astro
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,31 @@ | ||
--- | ||
import { getCollection, getDataEntryById } from 'astro:content'; | ||
const blog = await getCollection('blog'); | ||
const first = await getDataEntryById('blog', 1); | ||
const dogs = await getCollection('dogs'); | ||
const reptiles = await getCollection('reptiles'); | ||
--- | ||
<html> | ||
<head> | ||
<title>Index</title> | ||
</head> | ||
<body> | ||
|
||
<h1>Dogs</h1> | ||
<ul> | ||
{dogs.map(dog => ( | ||
<li><a href={`/dogs/${dog.id}`}>{ dog.data?.breed }</a></li> | ||
))} | ||
</ul> | ||
<h1>Blog Posts</h1> | ||
|
||
<h2>{first.data.title}</h2> | ||
<ul> | ||
{blog.map(post => ( | ||
<li><a href={`/blog/${post.id}`}>{ post.data?.title }</a></li> | ||
))} | ||
</ul> | ||
|
||
</body> | ||
</html> |
25 changes: 25 additions & 0 deletions
25
packages/astro/test/fixtures/content-layer-rendering/src/pages/reptiles/[slug].astro
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,25 @@ | ||
--- | ||
import type { GetStaticPaths } from "astro"; | ||
import { getCollection, render } from "astro:content" | ||
import { Image } from "astro:assets" | ||
export const getStaticPaths = (async () => { | ||
const collection = await getCollection("reptiles"); | ||
if(!collection) return [] | ||
return collection.map((reptile) => ({ | ||
params: { | ||
slug: `/${reptile.id}` | ||
}, | ||
props: { | ||
reptile | ||
} | ||
})); | ||
}) satisfies GetStaticPaths; | ||
const { reptile } = Astro.props as any | ||
const { Content } = await render(reptile) | ||
--- | ||
<meta charset="utf-8"> | ||
<h1>{reptile.data.title}</h1> | ||
<Content /> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.