Improve stress test benchmark (#8225)

This commit is contained in:
Bjorn Lu 2023-08-25 21:00:51 +08:00 committed by GitHub
parent acf652fc1d
commit 0ae3b7a7ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View file

@ -1,6 +1,9 @@
import { createRequire } from 'module'; import { createRequire } from 'node:module';
import path from 'node:path';
export const astroBin = createRequire(import.meta.url).resolve('astro'); const astroPkgPath = createRequire(import.meta.url).resolve('astro/package.json');
export const astroBin = path.resolve(astroPkgPath, '../astro.js');
/** @typedef {{ avg: number, stdev: number, max: number }} Stat */ /** @typedef {{ avg: number, stdev: number, max: number }} Stat */

View file

@ -7,11 +7,13 @@ import { loremIpsum } from './_util.js';
export async function run(projectDir) { export async function run(projectDir) {
await fs.rm(projectDir, { recursive: true, force: true }); await fs.rm(projectDir, { recursive: true, force: true });
await fs.mkdir(new URL('./src/pages', projectDir), { recursive: true }); await fs.mkdir(new URL('./src/pages', projectDir), { recursive: true });
await fs.mkdir(new URL('./src/components', projectDir), { recursive: true });
await fs.writeFile( await fs.writeFile(
new URL('./src/pages/index.astro', projectDir), new URL('./src/pages/index.astro', projectDir),
`\ `\
--- ---
import Paragraph from '../components/Paragraph.astro'
const content = "${loremIpsum}" const content = "${loremIpsum}"
--- ---
@ -25,13 +27,22 @@ const content = "${loremIpsum}"
<body> <body>
<h1>Astro</h1> <h1>Astro</h1>
<div> <div>
${Array.from({ length: 60 }).map(() => '<p>{content}</p>')} ${Array.from({ length: 100 }).map(() => '<p>{content}</p>').join('\n')}
</div>
<div>
${Array.from({ length: 50 }).map((_, i) => '<Paragraph num={' + i + '} str={content} />').join('\n')}
</div> </div>
</body> </body>
</html>`, </html>`,
'utf-8' 'utf-8'
); );
await fs.writeFile(
new URL('./src/components/Paragraph.astro', projectDir),
`<div>{Astro.props.num} {Astro.props.str}</div>`,
'utf-8'
);
await fs.writeFile( await fs.writeFile(
new URL('./astro.config.js', projectDir), new URL('./astro.config.js', projectDir),
`\ `\