()
| 583 | } |
| 584 | |
| 585 | async 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'), |
no test coverage detected