aboutsummaryrefslogtreecommitdiff
path: root/benchmark/make-project
diff options
context:
space:
mode:
authorGravatar bluwy <bjornlu.dev@gmail.com> 2024-11-06 23:17:39 +0800
committerGravatar bluwy <bjornlu.dev@gmail.com> 2024-11-06 23:17:39 +0800
commit7db86cf2b75c547b5947bc1a10f21d2e3e56e9da (patch)
tree115d93a2565958a069462d4e39446059e6395339 /benchmark/make-project
parentc280655655cc6c22121f32c5f7c76836adf17230 (diff)
parente10b03e88c22592fbb42d7245b65c4f486ab736d (diff)
downloadastro-7db86cf2b75c547b5947bc1a10f21d2e3e56e9da.tar.gz
astro-7db86cf2b75c547b5947bc1a10f21d2e3e56e9da.tar.zst
astro-7db86cf2b75c547b5947bc1a10f21d2e3e56e9da.zip
Merge branch 'main' into next
Diffstat (limited to '')
-rw-r--r--benchmark/make-project/render-bench.js132
1 files changed, 132 insertions, 0 deletions
diff --git a/benchmark/make-project/render-bench.js b/benchmark/make-project/render-bench.js
new file mode 100644
index 000000000..9d10d9bf5
--- /dev/null
+++ b/benchmark/make-project/render-bench.js
@@ -0,0 +1,132 @@
+import fs from 'node:fs/promises';
+import { loremIpsumHtml, loremIpsumMd } from './_util.js';
+
+// Map of files to be generated and tested for rendering.
+// Ideally each content should be similar for comparison.
+const renderFiles = {
+ 'components/ListItem.astro': `\
+---
+const { className, item, attrs } = Astro.props;
+const nested = item !== 0;
+---
+ <li class={className}>
+ <a
+ href={item}
+ aria-current={item === 0}
+ class:list={[{ large: !nested }, className]}
+ {...attrs}
+ >
+ <span>{item}</span>
+ </a>
+ </li>
+ `,
+ 'components/Sublist.astro': `\
+---
+import ListItem from '../components/ListItem.astro';
+const { items } = Astro.props;
+const className = "text-red-500";
+const style = { color: "red" };
+---
+<ul style={style}>
+{items.map((item) => (
+ <ListItem className={className} item={item} attrs={{}} />
+))}
+</ul>
+ `,
+ 'pages/astro.astro': `\
+---
+const className = "text-red-500";
+const style = { color: "red" };
+const items = Array.from({ length: 10000 }, (_, i) => ({i}));
+---
+<html>
+ <head>
+ <title>My Site</title>
+ </head>
+ <body>
+ <h1 class={className + ' text-lg'}>List</h1>
+ <ul style={style}>
+ {items.map((item) => (
+ <li class={className}>
+ <a
+ href={item.i}
+ aria-current={item.i === 0}
+ class:list={[{ large: item.i === 0 }, className]}
+ {...({})}
+ >
+ <span>{item.i}</span>
+ </a>
+ </li>
+ ))}
+ </ul>
+ ${Array.from({ length: 1000 })
+ .map(() => `<p>${loremIpsumHtml}</p>`)
+ .join('\n')}
+ </body>
+</html>`,
+ 'pages/md.md': `\
+# List
+
+${Array.from({ length: 1000 }, (_, i) => i)
+ .map((v) => `- ${v}`)
+ .join('\n')}
+
+${Array.from({ length: 1000 })
+ .map(() => loremIpsumMd)
+ .join('\n\n')}
+`,
+ 'pages/mdx.mdx': `\
+export const className = "text-red-500";
+export const style = { color: "red" };
+export const items = Array.from({ length: 1000 }, (_, i) => i);
+
+# List
+
+<ul style={style}>
+ {items.map((item) => (
+ <li class={className}>{item}</li>
+ ))}
+</ul>
+
+${Array.from({ length: 1000 })
+ .map(() => loremIpsumMd)
+ .join('\n\n')}
+`,
+};
+
+export const renderPages = [];
+for (const file of Object.keys(renderFiles)) {
+ if (file.startsWith('pages/')) {
+ renderPages.push(file.replace('pages/', ''));
+ }
+}
+
+/**
+ * @param {URL} projectDir
+ */
+export async function run(projectDir) {
+ await fs.rm(projectDir, { recursive: true, force: true });
+ await fs.mkdir(new URL('./src/pages', projectDir), { recursive: true });
+ await fs.mkdir(new URL('./src/components', projectDir), { recursive: true });
+
+ await Promise.all(
+ Object.entries(renderFiles).map(([name, content]) => {
+ return fs.writeFile(new URL(`./src/${name}`, projectDir), content, 'utf-8');
+ })
+ );
+
+ await fs.writeFile(
+ new URL('./astro.config.js', projectDir),
+ `\
+import { defineConfig } from 'astro/config';
+import adapter from '@benchmark/adapter';
+import mdx from '@astrojs/mdx';
+
+export default defineConfig({
+ integrations: [mdx()],
+ output: 'server',
+ adapter: adapter(),
+});`,
+ 'utf-8'
+ );
+}