import assert from 'node:assert/strict' import { execFileSync } from 'node:child_process' import { readFileSync } from 'node:fs' import { dirname, resolve } from 'node:path' import { performance } from 'node:perf_hooks' import { build } from 'esbuild' import { buildCounterbalancedSchedule } from './counterbalanced-benchmark-schedule.mjs' const baseline = process.argv[2] ?? '20ab9950654' const file = 'src/renderer/src/components/editor/markdown-rich-mode.ts' async function load(contents) { const result = await build({ stdin: { contents, loader: 'ts', resolveDir: dirname(resolve(file)) }, bundle: true, platform: 'node', format: 'esm', write: false, plugins: [ { name: 'cached-round-trip', setup(bundler) { bundler.onResolve({ filter: /markdown-round-trip$|^@\/i18n\/i18n$/ }, (args) => ({ path: args.path, namespace: 'bench' })) bundler.onLoad({ filter: /.*/, namespace: 'bench' }, (args) => ({ contents: args.path.endsWith('markdown-round-trip') ? 'export const getRichMarkdownRoundTripOutput = (content) => content' : 'export const translate = (_key, fallback) => fallback', loader: 'js' })) } } ] }) return import( `data:text/javascript;base64,${Buffer.from(result.outputFiles[0].text).toString('base64')}` ) } const arms = { before: await load(execFileSync('git', ['show', `${baseline}:${file}`], { encoding: 'utf8' })), after: await load(readFileSync(file, 'utf8')) } const results = [] for (const [name, content] of [ ['plain', '# Heading\nOrdinary prose with .'], ['complete', 'text'], ['unclosed-1000', '