74 lines
2.1 KiB
JavaScript
74 lines
2.1 KiB
JavaScript
import { spawnSync } from 'node:child_process'
|
|
import { resolve } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
import { getBenchOptions, measure, printResults } from './_shared.mjs'
|
|
|
|
const __dirname = fileURLToPath(new URL('.', import.meta.url))
|
|
const repoRoot = resolve(__dirname, '..', '..')
|
|
|
|
const options = getBenchOptions()
|
|
const generationProfiles = (process.env.BENCH_GENERATION_PROFILES ?? 'default,quick,standard,thorough')
|
|
.split(',')
|
|
.map((value) => value.trim())
|
|
.filter(Boolean)
|
|
|
|
function withGenerationProfile(baseArgs, profile) {
|
|
if (profile === 'default') {
|
|
return baseArgs
|
|
}
|
|
return [...baseArgs, '--generation-profile', profile]
|
|
}
|
|
|
|
const scenarios = [
|
|
{ name: 'cli.help', args: ['--help'] },
|
|
{ name: 'cli.version', args: ['--version'] },
|
|
{ name: 'cli.doctor', args: ['doctor', '--cwd', 'src/cli/__fixtures__/tiny-fastify', '--quiet'] },
|
|
{ name: 'cli.observe.check', args: ['observe', '--cwd', 'src/cli/__fixtures__/observe-config', '--profile', 'staging-observe', '--check-config', '--quiet'] },
|
|
...generationProfiles.map((profile) => ({
|
|
name: `cli.qualify.profile[${profile}]`,
|
|
args: withGenerationProfile(
|
|
['qualify', '--cwd', 'src/cli/__fixtures__/protocol-lab', '--profile', 'oauth-nightly', '--seed', '42', '--quiet'],
|
|
profile,
|
|
),
|
|
})),
|
|
]
|
|
|
|
async function run() {
|
|
const results = []
|
|
|
|
for (const scenario of scenarios) {
|
|
const row = await measure(
|
|
scenario.name,
|
|
async () => {
|
|
const proc = spawnSync(
|
|
process.execPath,
|
|
['dist/cli/index.js', ...scenario.args],
|
|
{
|
|
cwd: repoRoot,
|
|
stdio: 'pipe',
|
|
encoding: 'utf8',
|
|
env: { ...process.env, FORCE_COLOR: '0' },
|
|
}
|
|
)
|
|
|
|
if (proc.status !== 0) {
|
|
throw new Error(
|
|
`Scenario ${scenario.name} failed with code ${proc.status}\nstdout:\n${proc.stdout}\nstderr:\n${proc.stderr}`
|
|
)
|
|
}
|
|
},
|
|
options,
|
|
)
|
|
|
|
results.push(row)
|
|
}
|
|
|
|
printResults('CLI Benchmarks', results, options)
|
|
}
|
|
|
|
run().catch((error) => {
|
|
console.error(error)
|
|
process.exit(1)
|
|
})
|