diff --git a/scripts/bench-file/src/main.ts b/scripts/bench-file/src/main.ts index 19cdcea1..93df81a7 100644 --- a/scripts/bench-file/src/main.ts +++ b/scripts/bench-file/src/main.ts @@ -2,6 +2,8 @@ import { type BenchmarkReport, reportToBenchmarkHandler, } from '@radashi-org/benchmarks/reporter.ts' +import * as fs from 'node:fs' +import * as path from 'node:path' import { createVitest } from 'vitest/node' main() @@ -9,11 +11,30 @@ main() async function main() { const reports: BenchmarkReport[] = [] + const rootDir = new URL('../../../', import.meta.url).pathname + const scriptDir = new URL('../', import.meta.url).pathname + const nodeModulesDir = path.join(rootDir, 'node_modules') + + // If the root node_modules directory doesn't contain vitest, link + // it to the vitest installed for this script. + fs.mkdirSync(nodeModulesDir, { recursive: true }) + try { + fs.symlinkSync( + path.relative( + nodeModulesDir, + path.join(scriptDir, 'node_modules/vitest'), + ), + path.join(nodeModulesDir, 'vitest'), + ) + } catch (e) { + console.warn(e) + } + const vitest = await createVitest('benchmark', { watch: false, pool: 'vmThreads', includeTaskLocation: true, - config: new URL('../../../vitest.config.ts', import.meta.url).pathname, + config: path.join(rootDir, 'vitest.config.ts'), benchmark: { reporters: [ reportToBenchmarkHandler(report => {