From 821016819296b96150a60eeeb6e80822d9b98105 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Sat, 23 Nov 2024 16:50:37 -0500 Subject: [PATCH] chore: use ./scripts/bench-file/node_modules/vitest if necessary --- scripts/bench-file/src/main.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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 => {