Skip to content

Commit

Permalink
chore: use ./scripts/bench-file/node_modules/vitest if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Nov 23, 2024
1 parent 843867a commit 8210168
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion scripts/bench-file/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,39 @@ 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()

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 => {
Expand Down

0 comments on commit 8210168

Please sign in to comment.