Skip to content

Commit

Permalink
feat(benchmark): move importTinybench to runner (vitest-dev#4376)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing authored and LorenzoBloedow committed Dec 19, 2023
1 parent eb0e95e commit 12162fc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
1 change: 0 additions & 1 deletion packages/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@
"birpc": "0.2.14",
"chai-subset": "^1.6.0",
"cli-truncate": "^3.1.0",
"event-target-polyfill": "^0.0.3",
"execa": "^7.1.1",
"expect-type": "^0.16.0",
"fast-glob": "^3.3.0",
Expand Down
16 changes: 7 additions & 9 deletions packages/vitest/src/runtime/runners/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ import type { BenchTask, Benchmark, BenchmarkResult } from '../../types/benchmar
import type { ResolvedConfig } from '../../types/config'
import type { VitestExecutor } from '../execute'

async function importTinybench() {
if (!globalThis.EventTarget)
await import('event-target-polyfill' as any)

return (await import('tinybench'))
}

function createBenchmarkResult(name: string): BenchmarkResult {
return {
name,
Expand All @@ -26,8 +19,9 @@ function createBenchmarkResult(name: string): BenchmarkResult {

const benchmarkTasks = new WeakMap<Benchmark, import('tinybench').Task>()

async function runBenchmarkSuite(suite: Suite, runner: VitestRunner) {
const { Task, Bench } = await importTinybench()
async function runBenchmarkSuite(suite: Suite, runner: NodeBenchmarkRunner) {
const { Task, Bench } = await runner.importTinybench()

const start = performance.now()

const benchmarkGroup: Benchmark[] = []
Expand Down Expand Up @@ -132,6 +126,10 @@ export class NodeBenchmarkRunner implements VitestRunner {

constructor(public config: ResolvedConfig) {}

async importTinybench() {
return await import('tinybench')
}

importFile(filepath: string, source: VitestRunnerImportSource): unknown {
if (source === 'setup')
getWorkerState().moduleCache.delete(filepath)
Expand Down
5 changes: 1 addition & 4 deletions packages/vitest/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,10 +736,7 @@ export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'f

api?: ApiConfig

benchmark?: Required<Omit<BenchmarkUserOptions, 'outputFile'>> & {
outputFile?: BenchmarkUserOptions['outputFile']
}

benchmark?: Required<Omit<BenchmarkUserOptions, 'outputFile'>> & Pick<BenchmarkUserOptions, 'outputFile'>
shard?: {
index: number
count: number
Expand Down
7 changes: 0 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 12162fc

Please sign in to comment.