MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / main

Function main

tooling/scripts/perf-web-runtime.mjs:585–1071  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

583}
584
585async function main() {
586 await prepareWebDist()
587
588 const tempRoot = configuredTempRoot ?? await mkdtemp(join(tmpdir(), 'zennotes-web-perf-'))
589 if (configuredTempRoot) await mkdir(tempRoot, { recursive: true })
590 const vaultRoot = externalVaultRoot ?? join(tempRoot, 'vault')
591 const chromeProfile = join(tempRoot, 'chrome-profile')
592 const serverBinary = join(
593 tempRoot,
594 process.platform === 'win32' ? 'zennotes-server.exe' : 'zennotes-server'
595 )
596 if (externalVaultRoot) await access(vaultRoot, constants.R_OK)
597 else await mkdir(vaultRoot, { recursive: true })
598 await mkdir(chromeProfile, { recursive: true })
599
600 const serverPort = await getFreePort()
601 const debugPort = await getFreePort()
602 let server = null
603 let chrome = null
604 let client = null
605
606 try {
607 const seedStartedAt = performance.now()
608 if (!externalVaultRoot) {
609 if (skipSyntheticSeed) await access(vaultRoot, constants.R_OK)
610 else await seedVault(vaultRoot, noteCount)
611 }
612 const seedMs = round(performance.now() - seedStartedAt)
613
614 await buildGoServer(serverBinary)
615 server = startGoServer({
616 vaultRoot,
617 bind: `127.0.0.1:${serverPort}`,
618 serverBinary,
619 configPath: join(tempRoot, 'zennotes-perf-server.json'),
620 disablePersistedMetaCache: Boolean(externalVaultRoot)
621 })
622 await waitForHttpOk(`http://127.0.0.1:${serverPort}/healthz`, 20000)
623 chrome = startChrome({ debugPort, userDataDir: chromeProfile })
624 client = await connectToPage(debugPort)
625
626 const consoleMessages = []
627 const networkScripts = []
628 client.on('Runtime.consoleAPICalled', (event) => {
629 const text = event.args?.map((arg) => arg.value ?? arg.description ?? '').join(' ') ?? ''
630 if (event.type === 'error' || text.includes('[zen:perf]')) {
631 consoleMessages.push({ type: event.type, text })
632 }
633 })
634 client.on('Network.requestWillBeSent', (event) => {
635 const script = scriptNameFromUrl(event.request?.url ?? '')
636 if (script) networkScripts.push(script)
637 })
638
639 await Promise.all([
640 client.send('Page.enable'),
641 client.send('Runtime.enable'),
642 client.send('Network.enable'),

Callers 1

Calls 15

prepareWebDistFunction · 0.85
buildGoServerFunction · 0.85
startGoServerFunction · 0.85
waitForHttpOkFunction · 0.85
startChromeFunction · 0.85
connectToPageFunction · 0.85
getFreePortFunction · 0.70
seedVaultFunction · 0.70
roundFunction · 0.70
scriptNameFromUrlFunction · 0.70
waitForExpressionFunction · 0.70
evaluateFunction · 0.70

Tested by

no test coverage detected