From d1d4cc521129784032623976d668a78281512493 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Mon, 6 Mar 2023 13:02:43 -0500 Subject: [PATCH] fix: migrate mdoc perf benchmark to new config --- .../astro/performance/content-benchmark.mjs | 3 ++ .../fixtures/mdoc/astro.config.mjs | 33 ++++++++++++++++++- .../fixtures/mdoc/src/ContentRenderer.astro | 31 ++--------------- .../fixtures/mdx/src/ContentRenderer.astro | 2 +- .../performance/fixtures/mdx/src/Title.astro | 5 +++ .../performance/fixtures/utils/Heading.astro | 20 +++++++++++ .../performance/fixtures/utils/Title.astro | 8 ----- .../astro/performance/fixtures/utils/index.ts | 2 +- 8 files changed, 65 insertions(+), 39 deletions(-) create mode 100644 packages/astro/performance/fixtures/mdx/src/Title.astro create mode 100644 packages/astro/performance/fixtures/utils/Heading.astro delete mode 100644 packages/astro/performance/fixtures/utils/Title.astro diff --git a/packages/astro/performance/content-benchmark.mjs b/packages/astro/performance/content-benchmark.mjs index a0b78af31..40646ed03 100644 --- a/packages/astro/performance/content-benchmark.mjs +++ b/packages/astro/performance/content-benchmark.mjs @@ -60,6 +60,7 @@ async function benchmark({ fixtures, templates }) { console.log( `\n${bold('Simple')} ${dim(`${NUM_POSTS} posts (${formatsToString(fixtures)})`)}` ); + process.env.ASTRO_PERFORMANCE_TEST_NAME = 'simple'; await benchmark({ fixtures, templates: { @@ -77,6 +78,7 @@ async function benchmark({ fixtures, templates }) { `${NUM_POSTS} posts (${formatsToString(fixtures)})` )}` ); + process.env.ASTRO_PERFORMANCE_TEST_NAME = 'with-astro-components'; await benchmark({ fixtures, templates: { @@ -93,6 +95,7 @@ async function benchmark({ fixtures, templates }) { `${NUM_POSTS} posts (${formatsToString(fixtures)})` )}` ); + process.env.ASTRO_PERFORMANCE_TEST_NAME = 'with-react-components'; await benchmark({ fixtures, templates: { diff --git a/packages/astro/performance/fixtures/mdoc/astro.config.mjs b/packages/astro/performance/fixtures/mdoc/astro.config.mjs index 8d9b6c194..aae6ad223 100644 --- a/packages/astro/performance/fixtures/mdoc/astro.config.mjs +++ b/packages/astro/performance/fixtures/mdoc/astro.config.mjs @@ -4,5 +4,36 @@ import react from "@astrojs/react"; // https://astro.build/config export default defineConfig({ - integrations: [markdoc(), react()], + integrations: [markdoc({ + nodes: process.env.ASTRO_PERFORMANCE_TEST_NAME === 'with-astro-components' ? { + heading: { + render: 'Heading', + attributes: { + level: { type: Number }, + }, + } + } : {}, + tags: process.env.ASTRO_PERFORMANCE_TEST_NAME === 'with-astro-components' ? { + aside: { + render: 'Aside', + attributes: { + type: { type: String }, + title: { type: String }, + }, + } + } : process.env.ASTRO_PERFORMANCE_TEST_NAME === 'with-react-components' ? { + 'like-button': { + render: 'LikeButton', + attributes: { + liked: { type: Boolean }, + }, + }, + 'hydrated-like-button': { + render: 'HydratedLikeButton', + attributes: { + liked: { type: Boolean }, + }, + }, + } : {}, + }), react()], }); diff --git a/packages/astro/performance/fixtures/mdoc/src/ContentRenderer.astro b/packages/astro/performance/fixtures/mdoc/src/ContentRenderer.astro index 13b87c95c..3008f6119 100644 --- a/packages/astro/performance/fixtures/mdoc/src/ContentRenderer.astro +++ b/packages/astro/performance/fixtures/mdoc/src/ContentRenderer.astro @@ -1,5 +1,5 @@ --- -import { Title, Aside, LikeButton, HydratedLikeButton } from '@performance/utils'; +import { Heading, Aside, LikeButton, HydratedLikeButton } from '@performance/utils'; import type { CollectionEntry } from 'astro:content'; type Props = { @@ -11,33 +11,8 @@ const { Content } = await entry.render(); --- {entry.data.type === 'with-astro-components' - ? + ? : entry.data.type === 'with-react-components' - ? + ? : } diff --git a/packages/astro/performance/fixtures/mdx/src/ContentRenderer.astro b/packages/astro/performance/fixtures/mdx/src/ContentRenderer.astro index ddff3658b..42c2da57a 100644 --- a/packages/astro/performance/fixtures/mdx/src/ContentRenderer.astro +++ b/packages/astro/performance/fixtures/mdx/src/ContentRenderer.astro @@ -1,5 +1,5 @@ --- -import { Title } from '@performance/utils'; +import Title from './Title.astro'; import type { CollectionEntry } from 'astro:content'; type Props = { diff --git a/packages/astro/performance/fixtures/mdx/src/Title.astro b/packages/astro/performance/fixtures/mdx/src/Title.astro new file mode 100644 index 000000000..ede38c1aa --- /dev/null +++ b/packages/astro/performance/fixtures/mdx/src/Title.astro @@ -0,0 +1,5 @@ +--- +import { Heading } from '@performance/utils'; +--- + + diff --git a/packages/astro/performance/fixtures/utils/Heading.astro b/packages/astro/performance/fixtures/utils/Heading.astro new file mode 100644 index 000000000..a6c29cb88 --- /dev/null +++ b/packages/astro/performance/fixtures/utils/Heading.astro @@ -0,0 +1,20 @@ +--- +type Props = { + level: number; +} +const { level } = Astro.props; +--- + +{level === 1 &&

} +{level === 2 &&

} +{level === 3 &&

} +{level === 4 &&

} +{level === 5 &&
} +{level === 6 &&
} + + diff --git a/packages/astro/performance/fixtures/utils/Title.astro b/packages/astro/performance/fixtures/utils/Title.astro deleted file mode 100644 index f956ed0b1..000000000 --- a/packages/astro/performance/fixtures/utils/Title.astro +++ /dev/null @@ -1,8 +0,0 @@ -

- - diff --git a/packages/astro/performance/fixtures/utils/index.ts b/packages/astro/performance/fixtures/utils/index.ts index d6de0ce85..367ba9b9e 100644 --- a/packages/astro/performance/fixtures/utils/index.ts +++ b/packages/astro/performance/fixtures/utils/index.ts @@ -1,6 +1,6 @@ // @ts-nocheck export { default as RenderContent } from './RenderContent.astro'; export { default as Aside } from './Aside.astro'; -export { default as Title } from './Title.astro'; +export { default as Heading } from './Heading.astro'; export { default as LikeButton } from './LikeButton'; export { default as HydratedLikeButton } from './HydratedLikeButton.astro';