17c02925c5
* wip: config migration * fix: formatting * refactor: projectRoot -> root * refactor: pageUrlFormat -> format * refactor: buildOptions.site -> site * refactor: public -> publicDir * refactor: dist -> outDir * refactor: styleOptions -> style * fix: some dist tests -> outDir * refactor: remove legacyBuild (with TODOs) * refactor: more legacyBuild cleanup * refactor: server host and port * fix: remove experimentalStaticBuild CLI flag * refactor: src -> srcDir * refactor: devOptions.trailing -> trailing * refactor: remove sitemap + related flags * refactor: experimentalSSR -> experimental.ssr * fix: last devOptions * refactor: drafts -> markdown.drafts * fix: TS error on port as const * refactor: remove pages * refactor: more --project-root updates * refactor: markdownOptions -> markdown * fix: remaining type errors * feat: update AstroUserConfig * refactor: update CLI flag mapper + server mapper * fix: loadFixture projectRoot * fix: merge CLI flags before validating / transforming * wip: attempt to fix bad createRouteManifest config * refactor: combine config.base and config.site * fix: skip route manifest test for now * fix: site and base handling * refactor: update failing config testes * fix: build failure * feat: update config types with migration help * chore: update types * fix(deno): update deno fixture * chore: remove config migration logic * chore: remove logLevel * chore: clean-up config types * chore: update config warning * chore: add changeset * Sitemap Integration (#2965) * feat: add sitemap filter config option * feat: add canonicalURL sitemap config option * docs: update sitemap README * fix: update for new config * fix: filter not being applied * chore: changeset Co-authored-by: bholmesdev <hey@bholmes.dev> * fred pass * fix: Astro.resolve typo * fix: public => publicDir Co-authored-by: bholmesdev <hey@bholmes.dev> Co-authored-by: Fred K. Schott <fkschott@gmail.com>
70 lines
2.3 KiB
JavaScript
70 lines
2.3 KiB
JavaScript
import { fileURLToPath } from 'url';
|
|
import v8 from 'v8';
|
|
import dev from '../../packages/astro/dist/core/dev/index.js';
|
|
import { loadConfig } from '../../packages/astro/dist/core/config.js';
|
|
import prettyBytes from 'pretty-bytes';
|
|
|
|
if (!global.gc) {
|
|
console.error('ERROR: Node must be run with --expose-gc');
|
|
process.exit(1);
|
|
}
|
|
|
|
const isCI = process.argv.includes('--ci');
|
|
|
|
/** URL directory containing the entire project. */
|
|
const projDir = new URL('./project/', import.meta.url);
|
|
|
|
let config = await loadConfig({
|
|
cwd: fileURLToPath(projDir),
|
|
});
|
|
|
|
const server = await dev(config, { logging: { level: 'error' } });
|
|
|
|
// Prime the server so initial memory is created
|
|
await fetch(`http://localhost:3000/page-0`);
|
|
|
|
async function run() {
|
|
for (let i = 0; i < 100; i++) {
|
|
let path = `/page-${i}`;
|
|
await fetch(`http://localhost:3000${path}`);
|
|
}
|
|
}
|
|
|
|
global.gc();
|
|
const startSize = v8.getHeapStatistics().used_heap_size;
|
|
|
|
// HUMAN mode: Runs forever. Optimized for accurate results on each snapshot Slower than CI.
|
|
if (!isCI) {
|
|
console.log(`Greetings, human. This test will run forever. Run with the "--ci" flag to finish with a result.`);
|
|
let i = 1;
|
|
while (i++) {
|
|
await run();
|
|
global.gc();
|
|
const checkpoint = v8.getHeapStatistics().used_heap_size;
|
|
console.log(`Snapshot ${String(i).padStart(3, '0')}: ${(checkpoint / startSize) * 100}%`);
|
|
}
|
|
}
|
|
|
|
// CI mode: Runs 100 times. Optimized for speed with an accurate final result.
|
|
for (let i = 0; i < 100; i++) {
|
|
await run();
|
|
const checkpoint = v8.getHeapStatistics().used_heap_size;
|
|
console.log(`Estimate ${String(i).padStart(3, '0')}/100: ${(checkpoint / startSize) * 100}%`);
|
|
}
|
|
|
|
console.log(`Test complete. Running final garbage collection...`);
|
|
global.gc();
|
|
const endSize = v8.getHeapStatistics().used_heap_size;
|
|
|
|
// If the trailing average is higher than the median, see if it's more than 5% higher
|
|
let percentage = endSize / startSize;
|
|
const TEST_THRESHOLD = 1.5;
|
|
const isPass = percentage < TEST_THRESHOLD;
|
|
console.log(``);
|
|
console.log(`Result: ${isPass ? 'PASS' : 'FAIL'} (${percentage * 100}%)`);
|
|
console.log(`Memory usage began at ${prettyBytes(startSize)} and finished at ${prettyBytes(endSize)}.`);
|
|
console.log(`The threshold for a probable memory leak is ${TEST_THRESHOLD * 100}%`);
|
|
console.log(``);
|
|
console.log(`Exiting...`);
|
|
await server.stop();
|
|
process.exit(isPass ? 0 : 1);
|