Skip to content

Commit c36d2b9

Browse files
authored
feat(benchmark): move importTinybench to runner (#4376)
1 parent 5cdeb55 commit c36d2b9

File tree

4 files changed

+8
-21
lines changed

4 files changed

+8
-21
lines changed

packages/vitest/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@
172172
"birpc": "0.2.14",
173173
"chai-subset": "^1.6.0",
174174
"cli-truncate": "^3.1.0",
175-
"event-target-polyfill": "^0.0.3",
176175
"execa": "^7.1.1",
177176
"expect-type": "^0.16.0",
178177
"fast-glob": "^3.3.0",

packages/vitest/src/runtime/runners/benchmark.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ import type { BenchTask, Benchmark, BenchmarkResult } from '../../types/benchmar
88
import type { ResolvedConfig } from '../../types/config'
99
import type { VitestExecutor } from '../execute'
1010

11-
async function importTinybench() {
12-
if (!globalThis.EventTarget)
13-
await import('event-target-polyfill' as any)
14-
15-
return (await import('tinybench'))
16-
}
17-
1811
function createBenchmarkResult(name: string): BenchmarkResult {
1912
return {
2013
name,
@@ -26,8 +19,9 @@ function createBenchmarkResult(name: string): BenchmarkResult {
2619

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

29-
async function runBenchmarkSuite(suite: Suite, runner: VitestRunner) {
30-
const { Task, Bench } = await importTinybench()
22+
async function runBenchmarkSuite(suite: Suite, runner: NodeBenchmarkRunner) {
23+
const { Task, Bench } = await runner.importTinybench()
24+
3125
const start = performance.now()
3226

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

133127
constructor(public config: ResolvedConfig) {}
134128

129+
async importTinybench() {
130+
return await import('tinybench')
131+
}
132+
135133
importFile(filepath: string, source: VitestRunnerImportSource): unknown {
136134
if (source === 'setup')
137135
getWorkerState().moduleCache.delete(filepath)

packages/vitest/src/types/config.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,10 +736,7 @@ export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'f
736736

737737
api?: ApiConfig
738738

739-
benchmark?: Required<Omit<BenchmarkUserOptions, 'outputFile'>> & {
740-
outputFile?: BenchmarkUserOptions['outputFile']
741-
}
742-
739+
benchmark?: Required<Omit<BenchmarkUserOptions, 'outputFile'>> & Pick<BenchmarkUserOptions, 'outputFile'>
743740
shard?: {
744741
index: number
745742
count: number

pnpm-lock.yaml

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy